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 <pa...@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]]

______________________________________________
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.

Reply via email to