Hi I am trying to build a regression model. My data looks like this: A B C D E 1 1 1 2.57 5 2 0 0 1.64 3 0 5 1 4.8 1 1 3 0 3.56 168 1 1 1 2.13 1 0 3 1 5 168 2 0 0 7.75 28 4 0 2 2.85 168 3 0 1 1.89 6 1 1 1 2.33 3 3 2 2 1.77 168 1 0 0 1.38 0.04 0 6 1 4.57 168 2 2 2 2.86 1 3 1 1 4.11 168 3 0 2 3 84 1 1 1 2.5 56 where E is a response variable and A, B, C, D are predictor variables. Below are commands which I enter in R: str (mydata) mydata.lm = lm (E ~ 1, data = mydata) # to create a blank model add1(mydata.lm, mydata, test='F') # to add the best predictor variable to the blank model However at this point the message appears: Warning messages: 1: In model.matrix.default(Terms, m, contrasts.arg = object$contrasts) : the response appeared on the right-hand side and was dropped 2: In model.matrix.default(Terms, m, contrasts.arg = object$contrasts) : problem with term 4 in model.matrix: no columns are assigned What does it mean ? Could you please help ? -- View this message in context: http://r.789695.n4.nabble.com/building-a-regression-model-tp4654701.html Sent from the R help mailing list archive at Nabble.com.
Hi I am trying to build a regression model. My data looks like this: A B C ? ? ? ? D ? ? ? ? ? ? ? ? ? ?E 1 1 1 ? ? ? ?2.57 ? ? ? ? ? ?5 2 0 0 ? ? ? 1.64 ? ? ? ? ? ?3 0 5 1 ? ? ?4.8 ? ? ? ? ? ? ? ? ? ?1 1 3 0 ? ? ?3.56 ? ? ? ? ? ? ? ? ? 168 1 1 1 ? ? ?2.13 ? ? ? ? ? ? ? ? ? 1 0 3 1 ? ? ?5 ? ? ? ? ? ? ? ? ? 168 2 0 0 ? ? ?7.75 ? ? ? ? ? ? ? ? ? 28 4 0 2 ? ? 2.85 ? ? ? ? ? ? ? ? ?168 3 0 1 ? ? 1.89 ? ? ? ? ? ? ? ? ?6 1 1 1 ? ?2.33 ? ? ? ? ? ? ? ? ?3 3 2 2 ? ?1.77 ? ? ? ? ? ? ? ? 168 1 0 0 ? ?1.38 ? ? ? ? ? ? ? ? 0.04 0 6 1 ? ? 4. 11 ? ? ? ? ? ? ? ? ? ?168 2 2 2 ? ? ?2.86 ? ? ? ? ? ? ? ? 1 3 1 1 ? ? 4.11 ? ? ? ? ? ? ? ? 168 3 0 2 ? ? ?3 ? ? ? ? ? ? ? ? 84 1 1 1 ? ? ?2.5 ? ? ? ? ? ? ? ? ?56 where E is a response variable and A, B, C, D are predictor variables. Below are commands which I enter in R: str (mydata) mydata.lm = lm (E ~ 1, data = mydata) # to create a blank model add1(mydata.lm, mydata, test='F') # to add the best predictor variable to the blank model However at this point the message appears: Warning messages: 1: In model.matrix.default(Terms, m, contrasts.arg = object$contrasts) : ? the response appeared on the right-hand side and was dropped 2: In model.matrix.default(Terms, m, contrasts.arg = object$contrasts) : ? problem with term 4 in model.matrix: no columns are assigned What does it mean ? Could you please help ? This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham. This message has been checked for viruses but the contents of an attachment may still contain software viruses which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.
Hello, The "error" is just a warning, these are not the same thing. And the warning says that you're giving a wrong scope argument, one that includes the response. See ?add1. Argument 'scope' is "a formula giving the terms to be considered for adding or dropping." And you're passing the entire data.frame, not just the regressors. To get rid of the warning, try the following. add1(mydata.lm, ~ A + B + C + D, test='F') Hope this helps, Rui Barradas Em 04-01-2013 23:53, dada escreveu:> Hi > > I am trying to build a regression model. My data looks like this: > > A B C D E > 1 1 1 2.57 5 > 2 0 0 1.64 3 > 0 5 1 4.8 1 > 1 3 0 3.56 168 > 1 1 1 2.13 1 > 0 3 1 5 168 > 2 0 0 7.75 28 > 4 0 2 2.85 168 > 3 0 1 1.89 6 > 1 1 1 2.33 3 > 3 2 2 1.77 168 > 1 0 0 1.38 0.04 > 0 6 1 4.57 168 > 2 2 2 2.86 1 > 3 1 1 4.11 168 > 3 0 2 3 84 > 1 1 1 2.5 56 > > where E is a response variable and A, B, C, D are predictor variables. Below > are commands which I enter in R: > > str (mydata) > mydata.lm = lm (E ~ 1, data = mydata) # to create a blank model > add1(mydata.lm, mydata, test='F') # to add the best predictor variable to > the blank model > > However at this point the message appears: > > Warning messages: > 1: In model.matrix.default(Terms, m, contrasts.arg = object$contrasts) : > the response appeared on the right-hand side and was dropped > 2: In model.matrix.default(Terms, m, contrasts.arg = object$contrasts) : > problem with term 4 in model.matrix: no columns are assigned > > What does it mean ? Could you please help ? > > > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/building-a-regression-model-tp4654701.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.
You have to understand the ``scope'' argument to add1. As Rui Barradas points out, that argument expects a formula, but you pass it a data frame, YET you only get two warnings. You should practice having that feel strange to you, and having it make you investigate: 1- Why did you not have to give add1 a formula, even though Rui Barradas said you did? 2- Why did add1 warn you about the response, ``E'', appearing on ``the right-hand side''? 3- Why did add1 warn you about a ``problem with term 4 in model.matrix''? As a starter for your answering these questions, describe what you get from this: formula(mydata) Below are some questions to might answer as a follow-up to help yourself answer the above questions. 1- What might add1 have done when you gave it a data frame for its scope argument? 2- How does the location of the linear regression's response term explain the first warning? 3- What does ``model.matrix'' do anyway? 4- What is ``term 4'' in a model matrix, and how does it differ from column 4 of a matrix? 5- How does this last answer help explain the second warning? 6- How does the abscence of an ``A'' on right-hand side explain why the result of add1 did not have an ``A'' row? Best, Mario On Fri, Jan 4, 2013 at 6:53 PM, dada <paxkn@nottingham.ac.uk> wrote:> Hi > > I am trying to build a regression model. My data looks like this: > > A B C D E > 1 1 1 2.57 5 > 2 0 0 1.64 3 > 0 5 1 4.8 1 > 1 3 0 3.56 168 > 1 1 1 2.13 1 > 0 3 1 5 168 > 2 0 0 7.75 28 > 4 0 2 2.85 168 > 3 0 1 1.89 6 > 1 1 1 2.33 3 > 3 2 2 1.77 168 > 1 0 0 1.38 0.04 > 0 6 1 4.57 168 > 2 2 2 2.86 1 > 3 1 1 4.11 168 > 3 0 2 3 84 > 1 1 1 2.5 56 > > where E is a response variable and A, B, C, D are predictor variables. > Below > are commands which I enter in R: > > str (mydata) > mydata.lm = lm (E ~ 1, data = mydata) # to create a blank model > add1(mydata.lm, mydata, test='F') # to add the best predictor variable to > the blank model > > However at this point the message appears: > > Warning messages: > 1: In model.matrix.default(Terms, m, contrasts.arg = object$contrasts) : > the response appeared on the right-hand side and was dropped > 2: In model.matrix.default(Terms, m, contrasts.arg = object$contrasts) : > problem with term 4 in model.matrix: no columns are assigned > > What does it mean ? Could you please help ? > > > > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/building-a-regression-model-tp4654701.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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.[[alternative HTML version deleted]]