[R] "mvr" function

Bjørn-Helge Mevik bhx2 at mevik.net
Fri Jun 3 10:04:31 CEST 2005


McGehee, Robert writes:

> dataSet <- data.frame(y = vol[, 12])
> dataSet$X <- data.matrix(vol[, 1:11])
>
> ans.pcr <- pcr(y ~ X, 6, data = dataSet, validation = "CV")
>
> If there's a more elegant way of doing this without using data frames of
> matrices, I'd be interested as well.

I actually find using data frames with matrices the most elegant
way. :-)  Especially if you have several matrices.

Alternatively, to regress one variable of a data frame on the rest of
the variables, one can use

 ans.pcr <- pcr(y ~ ., 6, data = vol, validation = "CV")

(assuming the response variable is called `y' in the data frame; see
names(vol).)

One does not _have_ to store the data in a data frame (although I
would recommend it, because it is then easier to specify test data
sets and alternative data sets).  One can simply store the variables
in the global environment, and skip the `data' argument of `pcr',

-- 
HTH,
Bjørn-Helge Mevik




More information about the R-help mailing list