There are three ways of setting contrasts: via the name of the predictor, via a string that specifies the contrasts for all predictors and via setting the contrast value via the index of the predictor.
Creating a contrast
First, clear the contrasts if you'd like to start from scratch via doc.ClearContrasts(); and then add contrasts via doc.AddContrast("nameOfContrast");
function Create_new_contrast(){
// assume project (FMR, VMR) has been loaded
var doc = BrainVoyagerQX.ActiveDocument();
doc.LoadGLM(FileDialog.getOpenFileName("*.glm", "Please select a GLM file"));
doc.AddContrast("Objects_in_RVF > Objects_in_LVF");
}
Selecting a contrast for setting its values
When the contrast has been added via scripting or when a contrasts file (*.ctr) was loaded manually, an existing contrast can be selected via doc.SetCurrentContrast("nameOfContrast");
function Selecting_a_contrast_via_name() {
// assume project and GLM have been loaded
var doc = BrainVoyagerQX.ActiveDocument();
doc.AddContrast("Objects_in_RVF > Objects_in_LVF");
doc.SetCurrentContrast("Objects_in_RVF > Objects_in_LVF");
doc.SetContrastValue("Objects_in_RVF", 1);
doc.ShowGLM();
}
Alternatively, the current contrast can be selected via its number, e.g. doc.SetCurrentContrastIndex(1); when using this function, be sure to use ClearContrasts() first, otherwise the index number of the contrast being select is not correct:
function Selecting_a_contrast_via_index() {
// assume project and GLM have been loaded
var doc = BrainVoyagerQX.ActiveDocument();
doc.ClearContrasts();
doc.AddContrast("Objects_in_RVF > Objects_in_LVF");
doc.SetCurrentContrastIndex(1); // = Objects_in_LVF > Objects_in_RVF
doc.SetContrastValue("Objects_in_RVF", 1);
doc.ShowGLM();
}
Setting the contrast values
Say we'd like to set the value of the second predictor, objects in left visual field ("Objects_in_LVF"), to -1 (see figure below), then there are three ways to achieve this: via the name of the predictor, via the index number of the predictor and by setting all predictor values at the same time via a string. The methods are explained below in further detail.
1. Setting the contrast values via the predictor name
When setting the contrast via its name, the function doc.SetContrastValue("nameOfContrast", value); can be used.
When the name of the predictor is not correct, no results will be shown. So say we'd want to set the Objects in left visual field predictor to -1, we could use the following function:
function Changing_a_contrast_value_via_name() {
// assume project & GLM have been loaded
var doc = BrainVoyagerQX.ActiveDocument();
doc.SetCurrentContrast("Objects_in_RVF > Objects_in_LVF");
doc.SetContrastValue("Objects_in_LVF", -1);
}
2. Setting the contrast values via the predictor index
Via the function doc.SetContrastValueAtIndex("number", value); the contrast number one will be assigned the value specified as second parameter. The indexing starts from 1. So if there are 4 predictors, including the confound, predictor number two, in case of setting the Objects_in_LVF predictor (see figure above), the command will be doc.SetContrastValueAtIndex(2, -1);
function Changing_a_contrast_value_via_index() {
// assume project & GLM have been loaded
var doc = BrainVoyagerQX.ActiveDocument();
doc.SetCurrentContrast("Objects_in_RVF > Objects_in_LVF");
doc.SetContrastValueAtIndex(2, -1);
}
3. Setting all contrast values at once via a string
Via the function doc.SetContrastString("valuePred1 valuePred2 valuePred3 valueConfound"); all values for a contrast can be set at once. Please note that the confound is only shown in the "Overlay GLM" dialog when this is explicitly set via "Overlay GLM Options..." > Show confound predictors.
|
|
If the confound is not added in the contrast string, for example in doc.SetContrastString("1 -1 0");, it will automatically be added to the contrast file (*.ctr) by BrainVoyager QX:
|
|
Our function to change all contrast values for a contrast at once could look like this:
function Changing_all_contrast_values_via_string(){
// assume project & GLM have been loaded
var doc = BrainVoyagerQX.ActiveDocument();
doc.SetCurrentContrast("Objects_in_RVF > Objects_in_LVF");
doc.SetContrastString("1 -1 0 0");
}
For a comparison with creating and setting contrasts via the BrainVoyager user interface, see Contrasts step by step.
Methods
ClearContrasts()
AddContrast()
SetCurrentContrast()
SetCurrentContrastIndex()
SetContrastString()
SetContrastValue()
SetContrastValueAtIndex()