[R] repeated measure with quantitative independent variable
Cristiano Alessandro
cri.alessandro at gmail.com
Mon Dec 14 14:43:29 CET 2015
Hi all,
I am new to R, and I am trying to set up a repeated measure analysis
with a quantitative (as opposed to factorized/categorical)
within-subjects variable. For a variety of reasons I am not using
linear-mixed models, rather I am trying to fit a General Linear Model (I
am aware of assumptions and limitations) to assess whether the value of
the within-subjects variable affects statistically significantly the
response variable. I have two questions. To make myself clear I propose
the following exemplary dataset (where myfactor_nc is the quantitative
within-subjects variable; i.e. each subject performs the experiment
three times -- nc_factor=1,2,3 -- and produces the response in variable dv).
dv <- c(1,3,4,2,2,3,2,5,6,3,4,4,3,5,6);
subject <-
factor(c("s1","s1","s1","s2","s2","s2","s3","s3","s3","s4","s4","s4","s5","s5","s5"));
myfactor_nc <- c(1,2,3,1,2,3,1,2,3,1,2,3,1,2,3)
mydata_nc <- data.frame(dv, subject, myfactor_nc)
*Question 1 (using function aov)*
Easily done...
am1_nc <- aov(dv ~ myfactor_nc + Error(subject/myfactor_nc), data=mydata_nc)
summary(am1_nc)
Unlike the case when myfactor_nc is categorical, this produces three
error strata: Error: subject, Error: subject:myfactor_nc, Error: Within.
I cannot understand the meaning of the latter. How is that computed?
*Question 2 (using function lm)*
Now I would like to do the same with the functions lm() and Anova()
(from the car package). What I have done so far (please correct me if I
am mistaking) is the following:
# Unstack the dataset
dvm <- with(mydata_nc, cbind(dv[myfactor_nc==1],dv[myfactor_nc==2],
dv[myfactor_nc==3]))
#Fit the linear model
mlm1 <- lm(dvm ~ 1)
(is that model above correct for my design?)
Now I should use the Anova function, but it seems that it only accepts
factors, and not quantitative within-subject variable.
Any help is highly appreciated!
Thanks
Cristiano
More information about the R-help
mailing list