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

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to