• Zach Shipstead

Transitioning to R (Part 1): You might need to factor your independent variables

Updated: Feb 9

Have you ever attempted to check ANOVA results from R against results from SPSS, JASP, SAS, or some other package? Did you find that they were off?

The likely reason is that R thinks your independent variables are continuous, when they are supposed to be discrete. Unfortunately, many R-related resources don’t warn you about this.

Traditional software packages place within-subjects variables in separate columns, and require the grouping variables within columns to be numeric.

R, conversely, wants all variables in the same column, and freely accepts character-based labels.

The problem sets in when you use the traditional labelling system for your groups (0, 1, 2, etc.). R believes that these numbers are continuous until told otherwise. As such, the results of your ANOVA may wind up more like a messed-up regression or an ANCOVA.

To deal with this, get in the habit of always explicitly setting your IVs to be factors. It’s actually a good idea to do this with your subject number as well. R connects within-subjects data by using the subject number to look down the column of data (as opposed to looking across columns, like most software). Factoring your subject number let’s R know that each person is distinct, instead of continuous.

For details on how to do this, see my ANOVA page https://zshipstead.wixsite.com/mysite/anova

6 views0 comments

Recent Posts

See All