Re: [R] "mvr" function

From: Bjørn-Helge Mevik <>
Date: Fri 03 Jun 2005 - 18:04:31 EST

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',

Bjørn-Helge Mevik

______________________________________________ mailing list
PLEASE do read the posting guide!
Received on Fri Jun 03 18:08:39 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:22 EST