I do not think anyone has answered this.> I'm trying to run a simple one-way ANCOVA with the lmer > function in R package lme4, but have encountered some > conceptual problem. The data file MyData.txt is like this: > > Group Subj Cov Resp > A 1 3.90 4.05 > A 2 4.05 4.25 > A 3 4.25 3.60 > A 4 3.60 4.20 > A 5 4.20 4.05 > A 6 4.05 3.85 > B 7 3.85 4.15 > B 8 4.15 4.60 > B 9 4.60 4.15 > B 10 4.15 4.40 > B 11 4.40 3.35 > B 12 3.35 3.80 > B 13 3.80 3.90 > > Since I would like to treat subject (Subj) as a random > factor, my one- way ANCOVA (with covariate, Cov) is:This is a conceptual problem, indeed. To be able to estimate a subject effect, you need to have repeated measurements (several lines) per observed subject ... Cheers, Lorenz
Thanks a lot for the response and explanation, Lorenz! It seems that I can run the analysis with 'lm' without treating subject as a random factor lm(Resp ~ Group*Cov, TestData) Thanks, Gang On Aug 2, 2007, at 5:09 AM, <lorenz.gygax at art.admin.ch> <lorenz.gygax at art.admin.ch> wrote:> I do not think anyone has answered this. > >> I'm trying to run a simple one-way ANCOVA with the lmer >> function in R package lme4, but have encountered some >> conceptual problem. The data file MyData.txt is like this: >> >> Group Subj Cov Resp >> A 1 3.90 4.05 >> A 2 4.05 4.25 >> A 3 4.25 3.60 >> A 4 3.60 4.20 >> A 5 4.20 4.05 >> A 6 4.05 3.85 >> B 7 3.85 4.15 >> B 8 4.15 4.60 >> B 9 4.60 4.15 >> B 10 4.15 4.40 >> B 11 4.40 3.35 >> B 12 3.35 3.80 >> B 13 3.80 3.90 >> >> Since I would like to treat subject (Subj) as a random >> factor, my one- way ANCOVA (with covariate, Cov) is: >> TestData=read.table("MyData.txt", header=T); >> m1 <- lmer(Resp ~ Group * Cov + (1 | Subj), TestData) > > This is a conceptual problem, indeed. To be able to estimate a > subject effect, you need to have repeated measurements (several > lines) per observed subject ... > > Cheers, Lorenz
Sorry about this basic question. After reading a table, Model=read.table("ModelMat.txt", header=T) I want to get access to each entry in the table Model. However, if I do > Model[1,1] I get the following, [1] A Levels: A B C My question is, how can I just get the entry "A" without the 2nd line ("Levels: A B C")? Thanks, Gang
I have a mixed balanced ANOVA design with a between-subject factor (Grp) and a within-subject factor (Rsp). When I tried the following two commands which I thought are equivalent, > fit.lme <- lme(Beta ~ Grp*Rsp, random = ~1|Subj, Model); > fit.aov <- aov(Beta ~ Rsp*Grp+Error(Subj/Rsp)+Grp, Model); I got totally different results. What did I do wrong? Thanks, Gang
Gang Chen wrote:> I have a mixed balanced ANOVA design with a between-subject factor > (Grp) and a within-subject factor (Rsp). When I tried the following > two commands which I thought are equivalent, > > > fit.lme <- lme(Beta ~ Grp*Rsp, random = ~1|Subj, Model); > > fit.aov <- aov(Beta ~ Rsp*Grp+Error(Subj/Rsp)+Grp, Model); > > I got totally different results. What did I do wrong? > >Except for not telling us what your data are and what you mean by "totally different"? One model has a random interaction between Subj and Rsp, the other does not. This may make a difference, unless the interaction term is aliased with the residual error. If your data are unbalanced, aov is not guaranteed to give meaningful results. -pd
Thanks for the response! It is indeed a balanced design. The results are different in the sense all the F tests for main effects are not the same. Do you mean that a random interaction is modeled in the aov command? If so, what would be an equivalent command of aov to the one with lme? Thanks, Gang On Aug 3, 2007, at 3:52 PM, Peter Dalgaard wrote:> Gang Chen wrote: >> I have a mixed balanced ANOVA design with a between-subject >> factor (Grp) and a within-subject factor (Rsp). When I tried the >> following two commands which I thought are equivalent, >> >> > fit.lme <- lme(Beta ~ Grp*Rsp, random = ~1|Subj, Model); >> > fit.aov <- aov(Beta ~ Rsp*Grp+Error(Subj/Rsp)+Grp, Model); >> >> I got totally different results. What did I do wrong? >> >> > Except for not telling us what your data are and what you mean by > "totally different"? > > One model has a random interaction between Subj and Rsp, the other > does not. This may make a difference, unless the interaction term > is aliased with the residual error. > > If your data are unbalanced, aov is not guaranteed to give > meaningful results. > > -pd
read.table will convert you character columns to factors. You are seeing a single value returned ("A"), but it is also reporting the levels for the factors. One way is to read the data in without conversion to factors: Model=read.table("ModelMat.txt", header=TRUE, as.is=TRUE) or you can convert the factor to character for output: as.character(Model[1,1]) On 8/2/07, Gang Chen <gangchen at mail.nih.gov> wrote:> Sorry about this basic question. After reading a table, > > Model=read.table("ModelMat.txt", header=T) > > I want to get access to each entry in the table Model. However, if I do > > > Model[1,1] > > I get the following, > > [1] A > Levels: A B C > > My question is, how can I just get the entry "A" without the 2nd line > ("Levels: A B C")? > > Thanks, > Gang > > ______________________________________________ > 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 > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?