Dear R-users: I am a new R-user and I have a question about lm function. Here is my data. a<-c(1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14) b<-c(1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2) c<-c(2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2) d<-c(2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1) e<-c(1739,1633,1481,1837,1780,2073,1374,1629,1555,1385,1756,1522,1566,1643,1939,1615,1475,1759,1388,1483,1127,1682,1542,1247,1235,1605,1598,1718 ) Data<-data.frame(subject=as.factor(a), drug=as.factor(b), period=as.factor(c), sequence=as.factor(d), Max=e) lm3<- lm(Max ~subject*sequence + sequence + period + drug, data=Data) print(lm3) anova(lm3) When I use lm to fit the data, there are some problems in ?subject*sequence?. I have use GLM in SPSS to fit the same data, and it seems there is no problem. I don?t know where my problem is. How can I get the same result with SPSS? How can I do? Best regards, Hsin-Ya Lee ______________________________________________________________________________________________________ [[elided Yahoo spam]] Content-Type: application/msword; name="Result_SPSS.doc" Content-Transfer-Encoding: base64 Content-Description: 3367377201-Result_SPSS.doc Content-Disposition: attachment; filename="Result_SPSS.doc" AAAAAAAAAAAA
Dear Hsin-Ya Lee, The problem seems to be that every subject always only received one sequence: sequence subject 1 2 1 0 2 2 2 0 3 0 2 4 2 0 5 0 2 6 2 0 7 0 2 8 2 0 9 0 2 10 2 0 11 0 2 12 2 0 13 0 2 14 2 0 You should try to use a design where each subject receives each of the two sequences. Otherwise obviously the interactions will be not available. Best wishes Christoph leeznar schrieb:> Dear R-users: > > I am a new R-user and I have a question about lm > function. Here is my data. > a<-c(1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14) > b<-c(1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2) > c<-c(2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2) > d<-c(2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1) > e<-c(1739,1633,1481,1837,1780,2073,1374,1629,1555,1385,1756,1522,1566,1643,1939,1615,1475,1759,1388,1483,1127,1682,1542,1247,1235,1605,1598,1718 > ) > Data<-data.frame(subject=as.factor(a), > drug=as.factor(b), period=as.factor(c), > sequence=as.factor(d), Max=e) > > lm3<- lm(Max ~subject*sequence + sequence + period + > drug, data=Data) > print(lm3) > anova(lm3) > > When I use lm to fit the data, there are some problems > in "subject*sequence". I have use GLM in SPSS to > fit the same data, and it seems there is no problem. > > I don't know where my problem is. How can I get the > same result with SPSS? How can I do? > > Best regards, > Hsin-Ya Lee > > > > > ______________________________________________________________________________________________________ > [[elided Yahoo spam]] > Content-Type: application/msword; name="Result_SPSS.doc" > Content-Transfer-Encoding: base64 > Content-Description: 3367377201-Result_SPSS.doc > Content-Disposition: attachment; filename="Result_SPSS.doc" > > AAAAAAAAAAAA > > > > ------------------------------------------------------------------------ > > ______________________________________________ > 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.
In your data, subject is nested within sequence. Was that your intention?> a<-c(1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14) > b<-c(1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2) > c<-c(2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2) > d<-c(2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1) > e<-c(1739,1633,1481,1837,1780,2073,1374,1629,1555,1385,1756,1522,1566,1643,+ 1939,1615,1475,1759,1388,1483,1127,1682,1542,1247,1235,1605,1598,1718 + )> Data<-data.frame(subject=as.factor(a),+ drug=as.factor(b), period=as.factor(c), + sequence=as.factor(d), Max=e)> Datasubject drug period sequence Max 1 1 1 2 2 1739 2 1 2 1 2 1633 3 2 1 1 1 1481 4 2 2 2 1 1837 5 3 1 2 2 1780 6 3 2 1 2 2073 7 4 1 1 1 1374 8 4 2 2 1 1629 9 5 1 2 2 1555 10 5 2 1 2 1385 11 6 1 1 1 1756 12 6 2 2 1 1522 13 7 1 2 2 1566 14 7 2 1 2 1643 15 8 1 1 1 1939 16 8 2 2 1 1615 17 9 1 2 2 1475 18 9 2 1 2 1759 19 10 1 1 1 1388 20 10 2 2 1 1483 21 11 1 2 2 1127 22 11 2 1 2 1682 23 12 1 1 1 1542 24 12 2 2 1 1247 25 13 1 2 2 1235 26 13 2 1 2 1605 27 14 1 1 1 1598 28 14 2 2 1 1718 Andrew On Thu, Jun 19, 2008 at 04:29:16PM +0800, leeznar wrote:> Dear R-users: > > I am a new R-user and I have a question about lm > function. Here is my data. > a<-c(1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14) > b<-c(1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2) > c<-c(2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2) > d<-c(2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1) > e<-c(1739,1633,1481,1837,1780,2073,1374,1629,1555,1385,1756,1522,1566,1643,1939,1615,1475,1759,1388,1483,1127,1682,1542,1247,1235,1605,1598,1718 > ) > Data<-data.frame(subject=as.factor(a), > drug=as.factor(b), period=as.factor(c), > sequence=as.factor(d), Max=e) > > lm3<- lm(Max ~subject*sequence + sequence + period + > drug, data=Data) > print(lm3) > anova(lm3) > > When I use lm to fit the data, there are some problems > in ??subject*sequence??. I have use GLM in SPSS to > fit the same data, and it seems there is no problem. > > I don??t know where my problem is. How can I get the > same result with SPSS? How can I do? > > Best regards, > Hsin-Ya Lee > > > > > ______________________________________________________________________________________________________ > [[elided Yahoo spam]] > Content-Type: application/msword; name="Result_SPSS.doc" > Content-Transfer-Encoding: base64 > Content-Description: 3367377201-Result_SPSS.doc > Content-Disposition: attachment; filename="Result_SPSS.doc" > > AAAAAAAAAAAA >> ______________________________________________ > 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.-- Andrew Robinson Department of Mathematics and Statistics Tel: +61-3-8344-6410 University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599 http://www.ms.unimelb.edu.au/~andrewpr http://blogs.mbs.edu/fishing-in-the-bay/
Dear all, I am trying to fit a multiple linear regression model to a table of data. My data.frame is like this ... fit.data <- data.frame(y, x1, x2, x3, x4, x5, x6), then I use the linea regression command ... lm(formula = y ~ x1 + x2 + x3 + x4 + x5 + x6, data = fit.data) however, for some tables the data in column x1 is equal to -x2, so I get NA values for both coefficients of x1 and x2. I need to have real fitted coefficients for all the parameters or the physical meaning of the parameters is lost. Is there any way of forcing R to fit all the parameters? I have seen the contrast option but I don't really understand it (I am not a statistician) so I would be greatful if anyone could explain that. Kind Regards Chibisi [[alternative HTML version deleted]]
Dear Hsin-Ya, The problem here is that subject is a factor with 14 levels, and sequence again is a factor with 2 levels; so the subject:sequence interaction already uses up another (13*1)=13 d.f.; given that there are only 28 replicates, it is not surprising that there are no residual degrees of freedom left! What do you intend to test with your model? Maybe I can be of help to solve the problem Best wishes Christoph leeznar at yahoo.com.tw schrieb:> Dear Dr. Christoph: > > Thanks for your reply. I am sure that I use the same data to run GLM with SPSS, but SPSS seems work!! > I also try your suggestion. I change the sequence data. > a<-c(1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14) > b<-c(1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2) > c<-c(2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2) > d<-c(2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1) > d<-c(1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1) > e<-c(1739,1633,1481,1837,1780,2073,1374,1629,1555,1385,1756,1522,1566,1643,1939, > 1615,1475,1759,1388,1483,1127,1682,1542,1247,1235,1605,1598,1718 ) > KK<-data.frame(subject=as.factor(a), drug=as.factor(b), period=as.factor(c), sequence=as.factor(d), Max=e) > lm3<- lm(Max ~ subject*sequence + period + drug+sequence , data=KK) > print(lm3) > anova(lm3) > > However, it can not work!! > So, where is the problems? Do I misunderstand what you mean? > > > Best regards, > Hsin-Ya > > > Dr. Christoph Scherber wrote: >> Dear Hsin-Ya Lee, >> >> The problem seems to be that every subject always only received one >> sequence: >> >> sequence >> subject 1 2 >> 1 0 2 >> 2 2 0 >> 3 0 2 >> 4 2 0 >> 5 0 2 >> 6 2 0 >> 7 0 2 >> 8 2 0 >> 9 0 2 >> 10 2 0 >> 11 0 2 >> 12 2 0 >> 13 0 2 >> 14 2 0 >> >> >> You should try to use a design where each subject receives each of the two >> sequences. Otherwise >> obviously the interactions will be not available. >> >> Best wishes >> Christoph >> >> >> >> >> leeznar schrieb: >>> Dear R-users: >>> >>> I am a new R-user and I have a question about lm >>> function. Here is my data. >>> a<-c(1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14) >>> b<-c(1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2) >>> c<-c(2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2) >>> d<-c(2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1) >>> e<-c(1739,1633,1481,1837,1780,2073,1374,1629,1555,1385,1756,1522,1566,1643,1939,1615,1475,1759,1388,1483,1127,1682,1542,1247,1235,1605,1598,1718 >>> ) >>> Data<-data.frame(subject=as.factor(a), >>> drug=as.factor(b), period=as.factor(c), >>> sequence=as.factor(d), Max=e) >>> >>> lm3<- lm(Max ~subject*sequence + sequence + period + >>> drug, data=Data) >>> print(lm3) >>> anova(lm3) >>> >>> When I use lm to fit the data, there are some problems >>> in "subject*sequence". I have use GLM in SPSS to >>> fit the same data, and it seems there is no problem. >>> >>> I don't know where my problem is. How can I get the >>> same result with SPSS? How can I do? >>> >>> Best regards, >>> Hsin-Ya Lee >>> >>> >>> >>> >>> >>> ______________________________________________________________________________________________________ >>> [[elided Yahoo spam]] >>> Content-Type: application/msword; name="Result_SPSS.doc" >>> Content-Transfer-Encoding: base64 >>> Content-Description: 3367377201-Result_SPSS.doc >>> Content-Disposition: attachment; filename="Result_SPSS.doc" >>> >>> AAAAAAAAAAAA >>> >>> >>> >>> ------------------------------------------------------------------------ >>> >>> ______________________________________________ >>> 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. >> ______________________________________________ >> 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. >> >> > Quoted from: > http://www.nabble.com/Problems-with-lm%28%29-tp17999900p18000246.html > > > . >
Reasonably Related Threads
- Type I SS and Type III SS problem
- The variables combined in a table from other table and combination questions
- how to find and use specific column after spliting dataframe
- Regression line does not show on scatterplot
- poly() in lm() leads to wrong coefficients (but correct residuals)