Hi
I'm performing a PLS
This is my data present in a file
Year Y X2 X3 X4 X5 X6
1960 27.8 397.5 42.2 50.7 78.3 65.8
1960 29.9 413.3 38.1 52 79.2 66.9
1961 29.8 439.2 40.3 54 79.2 67.8
1961 30.8 459.7 39.5 55.3 79.2 69.6
1962 31.2 492.9 37.3 54.7 77.4 68.7
My R-code
Data <- read.csv("C:/TestData.csv")
variable=names(Data)[4:8]
dataset=NULL
dataset$X=NULL
len=length(variable)
for( i in 1:len)
{
var=variable[i]
if(i==1)
{
dataset$X=as.matrix(Data[var])
}
if(i>1)
{
dataset$X=as.matrix(cbind(dataset$X,Data[var]))
}
}
depVar="Y"
dataset$Y=as.matrix(cbind(Data[depVar]))
pls1=mvr(Y~X,data=dataset,ncomp=4)
summary(pls1)
On execution the error is
Error in get(as.character(FUN), mode = "function", envir = envir) :
object 'X6' of mode 'function' was not found
Please help me on this
--
View this message in context: http://r.789695.n4.nabble.com/problem-in-exceuting-PLS-tp3914664p3914664.html
Sent from the R help mailing list archive at Nabble.com.
problem in exceuting PLS
2 messages · arunkumar1111, Uwe Ligges
On 18.10.2011 11:03, arunkumar1111 wrote:
Hi
I'm performing a PLS
This is my data present in a file
Year Y X2 X3 X4 X5 X6
1960 27.8 397.5 42.2 50.7 78.3 65.8
1960 29.9 413.3 38.1 52 79.2 66.9
1961 29.8 439.2 40.3 54 79.2 67.8
1961 30.8 459.7 39.5 55.3 79.2 69.6
1962 31.2 492.9 37.3 54.7 77.4 68.7
My R-code
Data<- read.csv("C:/TestData.csv")
variable=names(Data)[4:8]
There are only 7 columns in your data.
dataset=NULL dataset$X=NULL
Why NULL?
len=length(variable) for( i in 1:len)
Better: for(i in seq_along(variable))
{
var=variable[i]
if(i==1)
{
dataset$X=as.matrix(Data[var])
}
if(i>1)
{
dataset$X=as.matrix(cbind(dataset$X,Data[var]))
}
}
Or even better, forget about that loop! X <- as.matrix(Data[,4:8]) seems to be the fast way without any loop - but again, there is no 8th column in your data.
depVar="Y" dataset$Y=as.matrix(cbind(Data[depVar]))
What's wrong with dataset$Y <- Data[,depVar]
pls1=mvr(Y~X,data=dataset,ncomp=4)
Looks like you are talking about the pls package (unstated!)? Then, just forget everything from before and just read in the data and apply: fit1 <- mvr(Y ~ X2 + X3 + X4 + X5 + X6, data=Data, ncomp=4) you do not need all that preprocessing!
summary(pls1)
I get:
ummary(mvr(Y ~ X2 + X3 + X4 + X5 + X6, data=Data, ncomp=4))
Data: X dimension: 5 5
Y dimension: 5 1
Fit method: kernelpls
Number of components considered: 4
TRAINING: % variance explained
1 comps 2 comps 3 comps 4 comps
X 99.73 99.85 100.00 100
Y 78.51 99.81 99.98 100
Uwe Ligges
On execution the error is Error in get(as.character(FUN), mode = "function", envir = envir) : object 'X6' of mode 'function' was not found Please help me on this -- View this message in context: http://r.789695.n4.nabble.com/problem-in-exceuting-PLS-tp3914664p3914664.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ 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.