Re: [R] Help in using PCR

From: Gavin Simpson <gavin.simpson_at_ucl.ac.uk>
Date: Wed, 02 Jul 2008 10:51:29 +0100

On Wed, 2008-07-02 at 10:32 +0200, Bjørn-Helge Mevik wrote:
> Gavin Simpson <gavin.simpson@ucl.ac.uk> writes:
>
> > Ok, lets sort this out. [Not tested as I don't have your data]
> >
> > df <- data.frame(resp = cancerv1[, 408],
> > VARS = as.matrix(cancerv1[, 2:407])
>
> Actually, you _do_ need an I() here:
>
> df <- data.frame(resp = cancerv1[, 408],
> VARS = I(as.matrix(cancerv1[, 2:407])))
>
> otherwise data.frame() will split the matrix into single coloumn variables.

Doh! Thanks for pointing that out! I knew I'd get something seriously wrong there when I added the immortal words "Not tested...". That'll teach me to take shortcuts and not use dummy or inbuilt data as an example.

This raises another issue:

> dat <- data.frame(matrix(rnorm(101 * 20), ncol = 101, nrow = 20))
> df <- data.frame(resp = dat[,1], VARS = I(as.matrix(dat[, 2:101])))
> str(df)

'data.frame': 20 obs. of 2 variables:  $ resp: num 0.149 -0.715 0.069 0.560 -0.321 ...  $ VARS: AsIs [1:20, 1:100] 0.602859.... 0.517785.... -1.02003....

-2.70378.... -0.95322.... ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr  "X2" "X3" "X4" "X5" ...

> class(df$VARS)

[1] "AsIs"

The class is AsIs for $VARS. But if I look at your yarn data set for example, the NIR component is of class "matrix":

> str(yarn)

'data.frame': 28 obs. of 3 variables:  $ NIR : num [1:28, 1:268] 3.07 3.07 3.08 3.08 3.10 ...

  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : NULL

 $ density: num 100.0 80.2 79.5 60.8 60.0 ...  $ train : logi TRUE TRUE TRUE TRUE TRUE TRUE ...
> class(yarn$NIR)
[1] "matrix"

How did you achieve this?

Cheers

G

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

______________________________________________
R-help_at_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.
Received on Wed 02 Jul 2008 - 09:59:35 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 02 Jul 2008 - 12:31:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive