There is definitely a difference. The pcr program is Principal Component Regression, but document says
"The formula argument should be a symbolic formula of the form response ~ terms, where response is the name of the response vector or matrix (for multi-response models) and terms is the name of one or more predictor matrices, usually separated by +, e.g., water ~ FTIR or y ~ X + Z. See lm for a detailed description. The named variables should exist in the supplied data data frame or in the global environment. " Not sure what to do next ... > str(yarn) 'data.frame': 28 obs. of 3 variables: $ NIR : num [1:28, 1:268] 3.07 3.07 3.08 3.08 3.1 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : NULL .. ..$ : NULL $ density: num 100 80.2 79.5 60.8 60 ... $ train : logi TRUE TRUE TRUE TRUE TRUE TRUE ... > str(X) 'data.frame': 79 obs. of 100 variables: $ X.1 : num 2.36 2.36 2.15 2.22 2.3 ... $ X.2 : num 2.35 2.36 2.14 2.22 2.3 ... $ X.3 : num 2.35 2.35 2.14 2.21 2.29 ... $ X.4 : num 2.34 2.34 2.13 2.21 2.28 ... On Mon, May 10, 2010 at 9:19 PM, jim holtman <jholt...@gmail.com> wrote: > You need to provide an 'str(yarn)' so we can see what the structure is. I > don't know what the 'pcr' program is expecting, but it looks like from what > you have provided that 'yarn' might be a dataframe and "X" is a vector. > Look at the documentation for pcr and see what it expects. > > > On Mon, May 10, 2010 at 9:08 PM, Ravi Ramaswamy <raram...@gmail.com>wrote: > >> Jim - thanks. >> >> It worked, however pcr program is still not accepting it.... there is a >> sample yarn data loaded and I am comparing. My data looks like this >> >> >> X1 X2 X3 X4 X5 X6 X7 >> X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 >> 1Kalle 2.36038 2.35396 2.34772 2.34167 2.33587 2.33036 2.32517 2.32033 >> 2.31583 2.31168 2.30791 2.30450 2.30150 2.29891 2.29680 2.29523 2.29421 >> >> and yarn data looks like this >> >> NIR.1 NIR.2 NIR.3 NIR.4 NIR.5 NIR.6 NIR.7 NIR.8 >> NIR.9 NIR.10 NIR.11 NIR.12 NIR.13 NIR.14 NIR.15 NIR.16 NIR.17 >> NIR.18 >> 1 3.06630 3.08610 3.10790 3.09720 2.99790 2.82730 2.62330 2.40390 >> 2.19310 2.00580 1.83790 1.69070 1.57770 1.50330 1.43810 1.33730 1.22060 >> 1.14100 >> >> So, I thought I could convert X1 to X.1 and it would work. The names seem >> different. Not sure how to make the change >> >> > names(yarn) >> [1] "NIR" "density" "train" >> >> but >> >> > names(X) >> [1] "X.1" "X.2" "X.3" "X.4" "X.5" "X.6" "X.7" "X.8" >> "X.9" "X.10" "X.11" "X.12" "X.13" "X.14" "X.15" "X.16" "X.17" >> "X.18" >> >> >> On Mon, May 10, 2010 at 9:05 PM, jim holtman <jholt...@gmail.com> wrote: >> >>> Is this what you want: >>> >>> > x <- paste("X", 1:10, sep='') >>> >>> > x >>> [1] "X1" "X2" "X3" "X4" "X5" "X6" "X7" "X8" "X9" "X10" >>> > sub("X", "X.", x) >>> [1] "X.1" "X.2" "X.3" "X.4" "X.5" "X.6" "X.7" "X.8" "X.9" >>> "X.10" >>> > >>> >>> >>> On Mon, May 10, 2010 at 8:53 PM, Ravi Ramaswamy <raram...@gmail.com>wrote: >>> >>>> Hi - a newbie question, if someone can please help.... >>>> >>>> I want to change X1, X2,,.....to X.1 X.2 etc in the names below. I am >>>> using >>>> the Principal Component Regression function (pcr) and it seems to want >>>> it >>>> this way >>>> >>>> > datap3.pcr <- pcr(water ~ X, 10, data = datap3, Validation ="cv") >>>> Error in model.frame.default(formula = water ~ X, data = datap3) : >>>> invalid type (list) for variable 'X' >>>> >>>> ---------- >>>> >>>> > names(X) >>>> [1] "X1" "X2" "X3" "X4" "X5" "X6" "X7" "X8" "X9" >>>> "X10" >>>> "X11" "X12" "X13" "X14" "X15" "X16" "X17" "X18" "X19" "X20" >>>> [21] "X21" "X22" "X23" "X24" "X25" "X26" "X27" "X28" "X29" >>>> "X30" >>>> "X31" "X32" "X33" "X34" "X35" "X36" "X37" "X38" "X39" "X40" >>>> [41] "X41" "X42" "X43" "X44" "X45" "X46" "X47" "X48" "X49" >>>> "X50" >>>> "X51" "X52" "X53" "X54" "X55" "X56" "X57" "X58" "X59" "X60" >>>> [61] "X61" "X62" "X63" "X64" "X65" "X66" "X67" "X68" "X69" >>>> "X70" >>>> "X71" "X72" "X73" "X74" "X75" "X76" "X77" "X78" "X79" "X80" >>>> [81] "X81" "X82" "X83" "X84" "X85" "X86" "X87" "X88" "X89" >>>> "X90" >>>> "X91" "X92" "X93" "X94" "X95" "X96" "X97" "X98" "X99" "X100" >>>> > names(X)[1] >>>> [1] "X1" >>>> > for(i in 1:100){names(X)[i] <- "X.i"} >>>> > names(X) >>>> [1] "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" >>>> "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" >>>> "X.i" >>>> [25] "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" >>>> "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" >>>> "X.i" >>>> [49] "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" >>>> "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" >>>> "X.i" >>>> [73] "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" >>>> "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" >>>> "X.i" >>>> [97] "X.i" "X.i" "X.i" "X.i" >>>> > for(i in 1:100){names(X)[i] <- X.i} >>>> Error: object 'X.i' not found >>>> > for(i in 1:100){names(X)[i] <- "X."i} >>>> >>>> [[alternative HTML version deleted]] >>>> >>>> ______________________________________________ >>>> R-help@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<http://www.r-project.org/posting-guide.html> >>>> and provide commented, minimal, self-contained, reproducible code. >>>> >>> >>> >>> >>> -- >>> Jim Holtman >>> Cincinnati, OH >>> +1 513 646 9390 >>> >>> What is the problem that you are trying to solve? >>> >> >> > > > -- > Jim Holtman > Cincinnati, OH > +1 513 646 9390 > > What is the problem that you are trying to solve? > [[alternative HTML version deleted]] ______________________________________________ R-help@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.