[18891] in s-news-athena
Re: [S] nested models
daemon@ATHENA.MIT.EDU (Jean Adams)
Mon Aug 9 10:21:29 1999
Mime-Version: 1.0
Date: Mon, 9 Aug 1999 10:19:20 -0600
Message-Id: <00114B2B.@usgs.gov>
From: Jean_Adams@usgs.gov (Jean Adams)
To: s-news@wubios.wustl.edu
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Description: cc:Mail note part
Never mind. I figured it out. There are no errors if I use aov()
instead of lm() to do the fitting.
JVA
______________________________ Reply Separator _________________________________
Subject: [S] nested models
Author: "Jean V Adams; STATISTICIAN (BIOLOGY); Ann Arbor; MI
"<jean_adams@brd.usgs.gov> (Jean Adams) at NBS-Internet-Gateway
Date: 8/9/99 9:40 AM
I am trying to fit a nested ANOVA model in S-PLUS. The nested
variable, f2, is numbered consecutively throughout the levels of the
parent factor, f1. When trying to fit the nested model, I get an
error message. If I recode f2 to have repeating levels within each
level of the parent factor (see f3 below), then I am able to fit the
model with no errors. Why is that? Is there some easier way around
this other than creating a new variable like f3?
I am using S-PLUS 4.5 Professional Release 2 on Windows NT.
Thanks.
JVA
-----
y <- rnorm(18)
f1 <- as.factor(rep(1:3, rep(6, 3)))
f2 <- as.factor(rep(1981:1986, rep(3, 6)))
f3 <- as.factor(rep(rep(1:2, c(3, 3)), 3))
data.frame(y, f1, f2, f3)
y f1 f2 f3
1 -0.29795485 1 1981 1
2 1.40823725 1 1981 1
3 -0.35602882 1 1981 1
4 0.08005759 1 1982 2
5 -0.03494272 1 1982 2
6 0.57604035 1 1982 2
7 0.87854266 2 1983 1
8 -0.47552007 2 1983 1
9 0.57099009 2 1983 1
10 -0.33071819 2 1984 2
11 0.49792956 2 1984 2
12 0.34697820 2 1984 2
13 0.52752611 3 1985 1
14 0.23840659 3 1985 1
15 1.88830004 3 1985 1
16 1.83807194 3 1986 2
17 -0.12104665 3 1986 2
18 0.16229776 3 1986 2
anova(lm(y ~ f1/f2))
Error in lm.fit.qr(x, y): computed fit is singular, rank 6
Dumped
anova(lm(y ~ f1/f3))
Analysis of Variance Table
Response: y
Terms added sequentially (first to last)
Df Sum of Sq Mean Sq F Value Pr(F)
f1 2 1.070044 0.5350220 0.8662107 0.4452508
f3 %in% f1 3 0.138273 0.0460910 0.0746221 0.9724834
Residuals 12 7.411897 0.6176581
Jean V. Adams USGS Biological Resources Division
e-mail: jean_adams@usgs.gov Great Lakes Science Center
phone: (734) 214-9307 1451 Green Road
FAX: 734-994-8780 Ann Arbor, MI 48105-2899 USA
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news