Travis Tae Oh
  • Home
  • CV
  • Research
  • Contact
  • Home
  • CV
  • Research
  • Contact
Search
What is interX?

interX is a R package to help users analyze and visualize interactions between variables in an ordinary least squares regression model.
It currently consists of the spotlight() function, which tests whether the means of two experimental groups are statistically different at specific values of a continuous variable. The spotlight function executes a similar analysis as model 1 of the PROCESS macro in SAS or SPSS.

To download, please install the "devtools" package, and then use the install_github() function for the interX package.
The interX package also imports/depends on the tidyverse package.

library(devtools)
install_github("travioh/interx")

library(interX)


How it came about

As R became my go to program for data crunching, I found myself switching back and forth to SPSS occasionally to conduct various moderation and mediation analyses on PROCESS by Hayes. While I still use the macro for more complicated moderated mediation analyses, I wrote a simple R function to conduct spotlight analysis (here is a good piece on spotlight analysis by Aradhna Krishna).

My personal interest to learn more about R coding plus some positive nudging from my colleagues led me to turn this fledgling function into a R package. It's still a long way to get interX rolling like the PROCESS macro but I'm hopeful to receive critical feedback and suggestions from more advanced R users, as I make this package public. 


 
The Basics

The default setting of the spotlight() function is: (x, y, w, v, model = 1, spot = 1, center = TRUE, plot = FALSE), where

  • x = the experimental group variable (must be numeric, with dummy coding recommended)
  • y = the dependent variable
  • w = the moderator variable (should be continuous)
  • v = a covariate (only allows one covariate, can be left unidentified)
  • model = type of model (for now, "1" only for spotlight analysis)
  • spot = the # of standard deviation from the mean of "w" to conduct the spotlight analysis
  • center = centers the w variable when TRUE
  • plot = provides a ggplot of y ~ x*w when plot = TRUE

The current version (0.1.0) can only handle variables without any missing values.
The w (continuous moderator) should almost always be mean-centered to retrieve meaningful results.

The output of the function includes the regression analysis, the spotlight analysis (effect of x at specific points of w), and the values to plot an optional ggplot graph.


Here is an example output of the spotlight function:


#example
group <- sample(0:1, 200, replace = TRUE)
dv <- sample(1:5, 200, replace = TRUE)
cont <- sample(1:5, 200, replace = TRUE)
cova <- sample(1:5, 200, replace = TRUE)
dataset <- data.frame(group, dv, cont, cova)

​
#without covariate
spotlight(x = group, y = dv, w = cont, data = dataset, center = TRUE, plot = TRUE)

[[1]]

Call:
lm(formula = y ~ x * w, data = data)

Residuals:
     Min       1Q   Median       3Q      Max 
-2.29226 -1.14110 -0.06552  1.01005  2.40060 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  3.13506    0.12825  24.445   <2e-16 ***
x           -0.33673    0.19682  -1.711   0.0887 .  
w            0.07558    0.08575   0.881   0.3792    
x:w         -0.25977    0.14152  -1.836   0.0679 .  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.374 on 196 degrees of freedom
Multiple R-squared:  0.03079, Adjusted R-squared:  0.01595 
F-statistic: 2.075 on 3 and 196 DF,  p-value: 0.1048

[[2]]
    moderator_w    effect_x std.error      tstat     pvalue
1 -1.429622e+00  0.03464784 0.2795768  0.1239296 0.90149801
2  7.100799e-17 -0.33672646 0.1968195 -1.7108389 0.08869300
3  1.429622e+00 -0.70810076 0.2849281 -2.4851907 0.01378549

[[3]]
     ploty      cond           mod
1 3.061657 Treatment -1.429622e+00
2 2.798329 Treatment  7.100799e-17
3 2.535002 Treatment  1.429622e+00
4 3.027009   Control -1.429622e+00
5 3.135056   Control  7.100799e-17
6 3.243102   Control  1.429622e+00

[[4]]​
Picture
ⓒTravis Tae Oh. All Rights Reserved.
  • Home
  • CV
  • Research
  • Contact