Interaction between two continuous variables
From PsychWiki - A Collaborative Psychology Wiki
Jchristie (Talk | contribs) (→R commands) |
|||
(45 intermediate revisions not shown) | |||
Line 1: | Line 1: | ||
- | Statistical programs, like SPSS, do not always have "point-and-click" commands for every possible statistical test. This page is a description of how to test the interaction between two continuous variables. | + | Statistical programs, like SPSS, do not always have "point-and-click" commands for every possible statistical test. This page is a description of how to test the interaction between two continuous variables. Three approaches are described below:<br> |
+ | (1) '''[[#Three Steps Using SPSS | three steps to conduct the interaction using commands within SPSS]]''', and<br> | ||
+ | (2) '''[[#Interaction! software | Interaction! software]]''' by Daniel S. Soper that performs statistical analysis and graphics for interactions between dichotomous, categorical, and continuous variables.<br> | ||
+ | (3) '''[[#R commands | R commands]]''' for executing the analysis. | ||
- | + | <nowiki>*</nowiki>For a description of what is an interaction and main effects, please see the accompanying page about [[What is an Interaction?]]. | |
- | * | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | ==Three Steps== | + | __TOC__ |
+ | |||
+ | |||
+ | ==Three Steps using SPSS== | ||
There are three steps involved to calculate the interaction between two continuous variables. | There are three steps involved to calculate the interaction between two continuous variables. | ||
- | + | ===► '''Center''' the two continuous variables=== | |
- | + | *Why center the variables? | |
- | + | *#To increase interpretability of interactions numerous researchers (e.g. [[Aiken and West, 1991]]; [[Judd and McClelland, 1989]]) have recommended centering the predictor variables (X1 and X2). | |
- | + | *#If the variables are not centered there are possible problems with multicolinearity, which means that if the IVs are not centered their product (used in computing the interaction) is highly correlated with the original IV. | |
- | + | *How to center the variables? | |
- | + | *#You center the continuous variables by subtracting the mean score from each data-point. In other words, use SPSS, or another statistical program, to find the mean value of the variable. Then, use the "Compute" command in SPSS to create a new variable that is the original values minus the mean. | |
+ | *#Then, repeat the procedure for the second variable. | ||
+ | *As a concrete example, | ||
+ | *#Suppose you have 200 subjects (N=200) for which you have their IQ score and the length of time they studied for an exam. Thus, there are two continuous variables (X1=IQ, X2=time spent studying), and your dependent variable is the test score (Y=test score). | ||
+ | *#Imagine that the average IQ score is 100. To center the IQ variable, 100 needs to be subtracted from every every subject's IQ score. So if a subject has an IQ of 115, their centered IQ score is 15. If a subject has an IQ of 90, their centered IQ score is -10. For easy reference, lets called the newly centered IQ score as "IQ_c". | ||
+ | *#To check your transformation has been performed correctly you should compute the mean of your IQ_c variable. If the centering process has worked the mean score for IQ_c should be 0. It is important that the mean score you subtract is as accurate as possible. Typically this means your mean score should be entered to say at least 4 decimal places (though the number of decimal places needed will depend on your data). If you have rounded your mean score your centered variable may not have a mean of zero. | ||
+ | *There is a macro available that will center the variables | ||
+ | *#Macros are useful when you need to perform the same statistical procedure for lots of variables or imagine in the future you will be performing the same analysis over and over again. In other words macros may take some initial time to learn but in the long run will save you time. | ||
+ | *#See [http://www2.jura.uni-hamburg.de/instkrim/kriminologie/Mitarbeiter/Enzmann/Software/Enzmann_Software.html this website] and download the file. | ||
+ | *#Open and select run all from the pull-down menu. | ||
+ | *#At the bottom of the downloaded file is the following text | ||
+ | *#:/* --------------------------------------------------------- */.<br> | ||
+ | *#:/* The macro is called by: <br> | ||
+ | *#:/* Center IDVar = variable containing casenumbers <br> | ||
+ | *#:/* /VARS = variables <br> | ||
+ | *#:/* /DVARS = new variables. <br> | ||
+ | *#:/* --------------------------------------------------------- */.<br> | ||
+ | *#You should re-write that text to reflect your current study. For example, remove the "/*" because that is telling SPSS to ignore the enclosed text. Then, insert your variable names into the text, such as | ||
+ | *#:CenterIDVar = subjects | ||
+ | *#:/VARS = IQ, study | ||
+ | *#:/DVARS = IQ_c, study_c | ||
+ | *#In the above example, ‘IQ’ and ‘study’ are the variable names in SPSS given to the IQ and time spent studying by the subjects. ‘Subjects’ indicates the variable containing the case numbers, in this case 1-200 as there were 200 subjects in the study. | ||
+ | *#Highlight the text, and click run selection. A new SPSS data editor window should be created at the end of which should be 2 new SPSS variables IQ_c and study_c. You should now save this spss file with a new name. | ||
+ | ===► '''Create the interaction term'''=== | ||
+ | *How to create the interaction term? | ||
+ | *#Simply multiply together the two new centered variables. | ||
+ | *#In our example, multiple IQ_c x study_c | ||
+ | *#In SPSS this is accomplished using the "compute" command and typing "IQ_c * study_c" in the open box. | ||
+ | ===► '''Conduct Regression'''=== | ||
+ | *How to conduct the regression analysis? | ||
+ | *#In SPSS, click on "linear regression" and enter the test score variable as the DV. | ||
+ | *#Enter the newly centered variables as the IVs in the regression analysis. | ||
+ | *#Click "next" and enter both centered variables AND the new interaction variable as the IVs. | ||
+ | *#Run the analysis. | ||
+ | *#In the output, look at the second model in the "Coefficients" box. An interaction is depicted as a significant value for the interaction variable. A significant value for the centered variables can be conceptualized as a "main effect". | ||
+ | *#If your interaction term is then significant it is recommended you produce plots to assist the interpretation of your interaction. | ||
+ | |||
+ | ==Interaction! software== | ||
+ | *Given the tedious nature of using the [[#Three Steps using SPSS | three steps described above]] every time you need to test interactions between continuous variables, I was happy to find Windows-based software which analyzes statistical interactions between dichotomous, categorical, or continuous variables, AND plots the interaction graphs. | ||
+ | *The software is called [http://www.danielsoper.com/Interaction/default.aspx Interaction!] from a graduate student in the Information Systems department at Arizona State University. I found it very easy to use. There is also a good [http://www.danielsoper.com/Interaction/help.aspx Help section] on the website. | ||
+ | *There is an SPSS macro for conducting cross-product regressions [http://www.ilstu.edu/~wjschne/tests.html here]. | ||
+ | ==R commands== | ||
+ | *Assuming you have your data in a comma delimited text file called 'myGreatData.csv' and the first line (header) labels the three columns 'y, x1, x2', the following command will generate your regression. Note that these commands are the minimum and assume the same things are true as are true in the SPSS example above (centering, assumptions of the regression are met, etc.). | ||
+ | *#setwd( 'dataDir' ) #Set the working director to the path to your data file. You could skip this step and just enter the full path into the next step. | ||
+ | *#dat <- read.csv( 'myGreatData.csv', header = TRUE ) #load your data file into the variable 'dat' | ||
+ | *#m <- lm( y ~ x1 * x2, data = 'dat') #do the regression | ||
+ | *#summary(m) #view the results | ||
- | + | ---- | |
+ | ◄ Back to [[Analyzing Data]] page |
Latest revision as of 16:49, 5 August 2011
Statistical programs, like SPSS, do not always have "point-and-click" commands for every possible statistical test. This page is a description of how to test the interaction between two continuous variables. Three approaches are described below:
(1) three steps to conduct the interaction using commands within SPSS, and
(2) Interaction! software by Daniel S. Soper that performs statistical analysis and graphics for interactions between dichotomous, categorical, and continuous variables.
(3) R commands for executing the analysis.
*For a description of what is an interaction and main effects, please see the accompanying page about What is an Interaction?.
Contents |
Three Steps using SPSS
There are three steps involved to calculate the interaction between two continuous variables.
► Center the two continuous variables
- Why center the variables?
- To increase interpretability of interactions numerous researchers (e.g. (Aiken and West, 1991); (Judd and McClelland, 1989)) have recommended centering the predictor variables (X1 and X2).
- If the variables are not centered there are possible problems with multicolinearity, which means that if the IVs are not centered their product (used in computing the interaction) is highly correlated with the original IV.
- How to center the variables?
- You center the continuous variables by subtracting the mean score from each data-point. In other words, use SPSS, or another statistical program, to find the mean value of the variable. Then, use the "Compute" command in SPSS to create a new variable that is the original values minus the mean.
- Then, repeat the procedure for the second variable.
- As a concrete example,
- Suppose you have 200 subjects (N=200) for which you have their IQ score and the length of time they studied for an exam. Thus, there are two continuous variables (X1=IQ, X2=time spent studying), and your dependent variable is the test score (Y=test score).
- Imagine that the average IQ score is 100. To center the IQ variable, 100 needs to be subtracted from every every subject's IQ score. So if a subject has an IQ of 115, their centered IQ score is 15. If a subject has an IQ of 90, their centered IQ score is -10. For easy reference, lets called the newly centered IQ score as "IQ_c".
- To check your transformation has been performed correctly you should compute the mean of your IQ_c variable. If the centering process has worked the mean score for IQ_c should be 0. It is important that the mean score you subtract is as accurate as possible. Typically this means your mean score should be entered to say at least 4 decimal places (though the number of decimal places needed will depend on your data). If you have rounded your mean score your centered variable may not have a mean of zero.
- There is a macro available that will center the variables
- Macros are useful when you need to perform the same statistical procedure for lots of variables or imagine in the future you will be performing the same analysis over and over again. In other words macros may take some initial time to learn but in the long run will save you time.
- See this website and download the file.
- Open and select run all from the pull-down menu.
- At the bottom of the downloaded file is the following text
- /* --------------------------------------------------------- */.
- /* The macro is called by:
- /* Center IDVar = variable containing casenumbers
- /* /VARS = variables
- /* /DVARS = new variables.
- /* --------------------------------------------------------- */.
- /* --------------------------------------------------------- */.
- You should re-write that text to reflect your current study. For example, remove the "/*" because that is telling SPSS to ignore the enclosed text. Then, insert your variable names into the text, such as
- CenterIDVar = subjects
- /VARS = IQ, study
- /DVARS = IQ_c, study_c
- In the above example, ‘IQ’ and ‘study’ are the variable names in SPSS given to the IQ and time spent studying by the subjects. ‘Subjects’ indicates the variable containing the case numbers, in this case 1-200 as there were 200 subjects in the study.
- Highlight the text, and click run selection. A new SPSS data editor window should be created at the end of which should be 2 new SPSS variables IQ_c and study_c. You should now save this spss file with a new name.
► Create the interaction term
- How to create the interaction term?
- Simply multiply together the two new centered variables.
- In our example, multiple IQ_c x study_c
- In SPSS this is accomplished using the "compute" command and typing "IQ_c * study_c" in the open box.
► Conduct Regression
- How to conduct the regression analysis?
- In SPSS, click on "linear regression" and enter the test score variable as the DV.
- Enter the newly centered variables as the IVs in the regression analysis.
- Click "next" and enter both centered variables AND the new interaction variable as the IVs.
- Run the analysis.
- In the output, look at the second model in the "Coefficients" box. An interaction is depicted as a significant value for the interaction variable. A significant value for the centered variables can be conceptualized as a "main effect".
- If your interaction term is then significant it is recommended you produce plots to assist the interpretation of your interaction.
Interaction! software
- Given the tedious nature of using the three steps described above every time you need to test interactions between continuous variables, I was happy to find Windows-based software which analyzes statistical interactions between dichotomous, categorical, or continuous variables, AND plots the interaction graphs.
- The software is called Interaction! from a graduate student in the Information Systems department at Arizona State University. I found it very easy to use. There is also a good Help section on the website.
- There is an SPSS macro for conducting cross-product regressions here.
R commands
- Assuming you have your data in a comma delimited text file called 'myGreatData.csv' and the first line (header) labels the three columns 'y, x1, x2', the following command will generate your regression. Note that these commands are the minimum and assume the same things are true as are true in the SPSS example above (centering, assumptions of the regression are met, etc.).
- setwd( 'dataDir' ) #Set the working director to the path to your data file. You could skip this step and just enter the full path into the next step.
- dat <- read.csv( 'myGreatData.csv', header = TRUE ) #load your data file into the variable 'dat'
- m <- lm( y ~ x1 * x2, data = 'dat') #do the regression
- summary(m) #view the results
◄ Back to Analyzing Data page