[R] Within factor & random factor
Juliet Hannah
juliet.hannah at gmail.com
Sat Aug 29 19:53:03 CEST 2009
Let's say that location defined a group, and observations may
be more similar in a group. You could account for this similarity
with the following model.
model1 <-lme(X~CorP,random=~1|location,data=mydata,method="ML")
This fits a random intercept model grouped by location. This would
assume that the slope of the regression of X on CorP is the same by
group, but the group means differ.
"CorP" defines the fixed part of the model.
random= ~1 defines the random part (in this case just an intercept).
The last part specifies the estimation method.
I would recommend reading through Pinheiro and Bates. Brady West's
Linear Mixed Models also has nice examples. It is difficult (for me)
to assess your analysis. For example, I can see how location and
subject would be random if you had repeated measures on subjects
within location. These concepts take some time to understand. I would
recommend working on this problem with someone experienced in this. In
your studying, if you come across specific questions about nlme or
lme4, there is a mixed model mailing list that is very helpful. One
more note, your response takes values between 0 and 1, so you would
have to make sure the residuals are behaving ok (read up on
diagnostics).
Best,
Juliet
2009/8/26 細田弘吉 <khosoda at med.kobe-u.ac.jp>:
> Hi,
> I am quite new to R and trying to analyze the following data. I have 28
> controls and 25 patients. I measured X values of 4 different locations
> (A,B,C,D) in the brain image of each subject. And X ranges from 0 to 1.
> I think "control or patient" is a between subject factor and location is
> a within subject factor. So,
>
> controls: 28
> patients: 25 (unbalanced data set)
> respone measure: X values (ranging 0 to 1)
> fixed factor: control vs. patient (between subject factor)
> random factor: location (level: A,B,C,D ;no order) (within subject factor)
> random factor: subjectID 1-53
>
> My data looks like this;
>
> CorP X location subjectID
> control 0.708 A 1
> control 0.648 A 2
> patient 0.638 C 3
> control 0.547 D 4
> patient 0.632 B 5
> control 0.723 C 6
> ...........
>
> I want to know
> (a) if there is a significant difference between controls and patients
> in X values.
> (b) where (A,B,C,D?) the difference is between controls and patients in
> X values. (There may be an interaction)
>
> I constructed linear mixed model with lme as followings;
>
> (1) model1 <- lme(X ~ CorP*location, random= ~ 1| subjectID, mydata)
>
> (2) model2 <- lme(X ~ CorP*location, random= ~ location| subjectID, mydata)
>
> I am not familiar with lme syntax. I'm just wondering which formula
> [(1) or (2)] is appropriate for my model to know answers of (a) and (b)
> questions. Or may be both of the formulas are wrong.
>
> I would appreciate it very much if somebody could help me.
>
> Sincerely,
>
> Kohkichi Hosoda
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list