Hello all, I have problem with setting up random effects. I have a model: y=x1+x2+x1*x2+z1+z1*x2 where x1, x2, x1*x2 are fixed effects and z1, z1*x2 are random effects (crossed effects) I use library(nlme) 'lme' function. My question is: how I should set up random effects? I did lme(y~x1+x2+x1:x2, data=DATA, random=~z1+z1:x2, na.action='na.omit') but it did not work. Sincerely, Natalia.
NATALIA F TCHETCHERINA wrote:> Hello all, > I have problem with setting up random effects. > I have a model: > y=x1+x2+x1*x2+z1+z1*x2 > where x1, x2, x1*x2 are fixed effects > and z1, z1*x2 are random effects (crossed effects) > I use library(nlme) 'lme' function. > My question is: how I should set up random effects? > I did > lme(y~x1+x2+x1:x2, data=DATA, random=~z1+z1:x2, na.action='na.omit') > but it did not work. > > Sincerely, Natalia. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.htmlThe answer will depend on the types of x1, x2 and z1 (i.e. whether each of them is numeric or a factor). Because you use x1:x2 I will assume that x1, x2 and z1 are all factors. In that case the formula term x1*x2 is equivalent to x1 + x2 + x1:x2 and you could write the call to lme as lme(y ~ x1*x2, data = DATA, random = ~1|z1/x1) For lmer from the lme4 package it would be lmer(y ~ x1*x2 + (1|z1) + (1|z1:x1), data = DATA)
I may not follow entirely here, but your random effects structure isn't correct for lme. Also, nlme cannot handle (at least well) models with crossed random effects. A better option would be to use the lmer function. Setting up the structure for the random effects in nlme would look something like: lme(y~ fixed, data, random~= z1 + z2 |ID) Where ID is a variable that contains the grouping structure of your data. In lmer, which is more appropriate for models with crossed random effects, you lmer call might be something along the lines of: lmer(y ~ fixed + (z1|ID) + (z2|ID), data) See the most recent version of R news for more info on this topic. -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of NATALIA F TCHETCHERINA Sent: Wednesday, May 25, 2005 11:50 AM To: r-help at stat.math.ethz.ch Subject: [R] mixed model Hello all, I have problem with setting up random effects. I have a model: y=x1+x2+x1*x2+z1+z1*x2 where x1, x2, x1*x2 are fixed effects and z1, z1*x2 are random effects (crossed effects) I use library(nlme) 'lme' function. My question is: how I should set up random effects? I did lme(y~x1+x2+x1:x2, data=DATA, random=~z1+z1:x2, na.action='na.omit') but it did not work. Sincerely, Natalia. ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Dear Fellow R users,
I am fairly new to R and am currently conducting a mixed model.
I have 7 repeated measures on a simulated clinical trial
If I understand the model correctly, the outcome is the measure (as a
factor) the predictors are clinical group and trial (1-7). The fixed
factors are the measure and group. The random factors are the intercept
and id and group.
Based on this
Dataset <- read.table("C:/Program
Files/R/rw2010/data/miss/model1.dat",
header=TRUE, sep="\t", na.strings="NA", dec=".",
strip.white=TRUE)
require (nlme)
model.mix <- lme (trans1 ~ Index1 + grp,
random = ~ constant | id / grp ,
data = Dataset,
na.action = "na.exclude")
# where trans1 is the factor of the repeated measures of the scale.
# Index is the trial number, grp the group, and id the subject number.
I would like to split the results, just like SPSS splitfile by a
variable in the Dataset called runnb
I have tried using:
by (Dataset, runnb,
function (x) (lme (trans1 ~ Index1 + grp,
random = ~ constant | id / grp ,
data = Dataset,
na.action = "na.exclude") )
)
but to no avail . as my computer hangs and I set my GUI to --mdi
--max-mem-size=1200M.
Any ideas as to how to splitfile the results SPSS style would be most
appreciated?
Also, does lme do pairwise deletion?
By the way
> version
platform i386-pc-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 2
minor 1.0
year 2005
month 04
day 18
language R
Windows XP Pro.
Many thanks
Stephen
Ps as its my first time on this group - neat program!
???? ?"? ???? ????
http://mail.nana.co.il
[[alternative HTML version deleted]]
Hi Doug and Spencer, Many thanks - Excellent! All worked out nicely .... Regards Stephen ________________________________ From: Spencer Graves [mailto:spencer.graves@pdf.com] Sent: Mon 20/06/2005 17:54 To: Stephen Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Mixed model (comments in line) Stephen wrote:> Dear Fellow R users, > > > > I am fairly new to R and am currently conducting a mixed model. > > > > I have 7 repeated measures on a simulated clinical trial > > > > If I understand the model correctly, the outcome is the measure (as a > factor) the predictors are clinical group and trial (1-7). The fixed > factors are the measure and group. The random factors are theintercept> and id and group. > > > > Based on this > > Dataset <- read.table("C:/ProgramFiles/R/rw2010/data/miss/model1.dat",> header=TRUE, sep="\t", na.strings="NA", dec=".", strip.white=TRUE) > > require (nlme) > > model.mix <- lme (trans1 ~ Index1 + grp, > random = ~ constant | id / grp , > data = Dataset, > na.action = "na.exclude")I'm not familiar with this syntax. I would replace your "random" formula with "~1|id/grp". Did you get sensible results from your attempt to compute "model.mix"? How do the results compare with the results from replacing your "random" with "~1|id/grp"? Also, I'd try the same thing with lmer; please see "Fitting Linear Mixed Models in R" by Doug Bates in the latest R News, downloadable from "www.r-project.org" -> Newsletter.> > > > # where trans1 is the factor of the repeated measures of the scale. > > # Index is the trial number, grp the group, and id the subject number. > > > > I would like to split the results, just like SPSS splitfile by a > variable in the Dataset called runnb > > I have tried using: > > > > by (Dataset, runnb, > > function (x) (lme (trans1 ~ Index1 + grp, > > random = ~ constant | id / grp , > > data = Dataset, > > na.action = "na.exclude") ) > > ) >I haven't used "by" enough to comment on this. If I had problems with something like this, I might do something like the following: with(Dataset, table(runnb, id, grp)) Do you have enough observations in all cells to be able to estimate all these individual models? If yes, I might proceed as follows: b.lvls <- table(Dataset$runnb) nb <- length(b.lvls) fit <- vector(mode="list", nb) for(i in 1:nb) fit[[i]] <- lme(...) If I still had problems with this, I might manually step through this until I found the "i" that created the problem, etc.> > > but to no avail . as my computer hangs and I set my GUI to --mdi > --max-mem-size=1200M. > > > > Any ideas as to how to splitfile the results SPSS style would be most > appreciated? > > > > Also, does lme do pairwise deletion? > > > > By the way > > >>version > > > platform i386-pc-mingw32 > > arch i386 > > os mingw32 > > system i386, mingw32 > > status > > major 2 > > minor 1.0 > > year 2005 > > month 04 > > day 18 > > language R > > Windows XP Pro. > > > > Many thanks > > Stephen > > Ps as its my first time on this group - neat program! > > > ???? ?"? ???? ???? > http://mail.nana.co.il > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide!http://www.R-project.org/posting-guide.html ???? ?"? ???? ???? http://mail.nana.co.il [[alternative HTML version deleted]]