cv.lm syntax error

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

cv.lm syntax error

agent dunham
Dear all,

I've tried a multiple regression, and now I want to try a cross-validation.

I obtain this error (it must be sth related to df) that I don't understand, any help would be appreciated.

cv.lm(df= dat, lm2.52f, m=3)

Error en `[.data.frame`(df, , ynam) : undefined columns selected

lm2.52f is my lm object, dat is a dataframe where the variables involved in .lm are

I tried CVlm also but the same error

Thanks, [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: cv.lm syntax error

Uwe Ligges-3


On 04.03.2011 10:11, agent dunham wrote:

> Dear all,
>
> I've tried a multiple regression, and now I want to try a cross-validation.
>
> I obtain this error (it must be sth related to df) that I don't understand,
> any help would be appreciated.
>
> cv.lm(df= dat, lm2.52f, m=3)
>
> Error en `[.data.frame`(df, , ynam) : undefined columns selected
>
> lm2.52f is my lm object,

If this is the cv.lm from the DAAG package (unstated), then please read
its help page and find that you need to specify a formula as the second
argument rather than an already fitted lm object.

Uwe Ligges



 > dat is a dataframe where the variables involved in

> .lm are
>
> I tried CVlm also but the same error
>
> Thanks, [hidden email]
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/cv-lm-syntax-error-tp3334889p3334889.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: cv.lm syntax error

agent dunham
Thanks for your answer, but I type the following:

> dfmod.1 <- data.frame(dat$v1,dat$v2,dat$v3,dat$v4, dat$v5,factor)

> CVlm(df= dfmod.1, form.lm = formula(dat$v1 ~ dat$v2+dat$v3+ dat$v4+ dat$v5+ factor), m=3, seed=29, plotit=TRUE, printit =TRUE)

Error en `[.data.frame`(df, , ynam) : undefined columns selected

What does it mean?

[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: cv.lm syntax error

Don McKenzie-2
Your message subject says it all.  The function is "cv.lm()".   Also  
check the syntax for data.frame()

On 8-Mar-11, at 8:47 AM, agent dunham wrote:

> Thanks for your answer, but I type the following:
>
>> dfmod.1 <- data.frame(dat$v1,dat$v2,dat$v3,dat$v4, dat$v5,factor)
>
>> CVlm(df= dfmod.1, form.lm = formula(dat$v1 ~ dat$v2+dat$v3+ dat$v4+
>> dat$v5+ factor), m=3, seed=29, plotit=TRUE, printit =TRUE)
>
> Error en `[.data.frame`(df, , ynam) : undefined columns selected
>
> What does it mean?
>
> [hidden email]
>
> --
> View this message in context: http://r.789695.n4.nabble.com/cv-lm- 
> syntax-error-tp3334889p3341767.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.

Why does the universe go to all the bother of existing?
-- Stephen Hawking

#define QUESTION ((bb) || !(bb))
-- William Shakespeare



Don McKenzie, Research Ecologist
Pacific WIldland Fire Sciences Lab
US Forest Service

Affiliate Professor
School of Forest Resources, College of the Environment
CSES Climate Impacts Group
University of Washington

desk: 206-732-7824
cell: 206-321-5966
[hidden email]
[hidden email]

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: cv.lm syntax error

agent dunham
But I read in the forum that  cv.lm is not for multiple regression, that's why i change it ti CVlm, however i fell to the same error ....[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: cv.lm syntax error

John Maindonald
In reply to this post by agent dunham
It means that dat$v1, dat$v2, . . . are not columns in the data frame df

Specify the formula as v1 ~ v2+v2+v3+v4+v5+factor
Then (assuming that factor is a column object of the right length)
you should be fine.

John Maindonald             email: [hidden email]
phone : +61 2 (6125)3473    fax  : +61 2(6125)5549
Centre for Mathematics & Its Applications, Room 1194,
John Dedman Mathematical Sciences Building (Building 27)
Australian National University, Canberra ACT 0200.
http://www.maths.anu.edu.au/~johnm

> From: agent dunham <[hidden email]>
> Date: 9 March 2011 3:47:10 AM AEDT
> To: [hidden email]
> Subject: Re: [R] cv.lm syntax error
>
>
> Thanks for your answer, but I type the following:
>
>> dfmod.1 <- data.frame(dat$v1,dat$v2,dat$v3,dat$v4, dat$v5,factor)
>
>> CVlm(df= dfmod.1, form.lm = formula(dat$v1 ~ dat$v2+dat$v3+ dat$v4+
>> dat$v5+ factor), m=3, seed=29, plotit=TRUE, printit =TRUE)
>
> Error en `[.data.frame`(df, , ynam) : undefined columns selected
>
> What does it mean?
>
> [hidden email]
>
> --
> View this message in context: http://r.789695.n4.nabble.com/cv-lm-syntax-error-tp3334889p3341767.html
> Sent from the R help mailing list archive at Nabble.com.


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: cv.lm syntax error

agent dunham
I rewrite my previous comand, CVlm works now. It was related to having the same names in the df than in the formula included at CVlm .

Now I'd like to know:

Q1: if the seed is of any special importance, or I can type just seed=29 like in the example?

Q2: I typed:

CVlm(df = mydf, form.lm = formula(response~v1+v2+factor), m=3, dots = TRUE, seed=29, plotit=TRUE, printit=TRUE)

In case is important factor has three levels, this way: table(factor):  levels: 2  3  4
                                                                                             freq:   2 21 34

And when the 3rd Fold it says:

fold 3
Observations in test set: 2 5 6 8 11 13 15 16 17 22 29 33 35 37 41 46 51 52 55
Error en model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) :
  factor 'factor' has new level(s) 2

What does it mean?

Thanks in advance,[hidden email]