[R] Predicting Smooths of Vectors in MGCV

Nick Jacobson njacobson at psu.edu
Wed Jan 21 17:42:42 CET 2015


Hi everyone,

I am trying to obtain predictions from a smooth of vectors. I have
successfully modeled the smooth vectors, using the following:

test=gam(outcome~s(matb,by=mat,k=4))
summary(test)
plot(test)

Both matb and mat are matrices, each containing 7 columns.

I am unsure of how to set up the prediction data frame given there are two
matrices:

I have tried creating two separate matrices (matpdat and matpdat2)
containing the names of original columns in mat and matb and linking them
with c():

matpdat=matrix(0,nrow=1,ncol=7)
matpdat=data.frame(matpdat)
names(matpdat)=c("lag.1.1","lag.2.1","lag.3.1","lag.4.1","lag.5.1","lag.6.1","lag.7.1")
matpdat[1,1]=1

matpdat2=matrix(0,nrow=1,ncol=7)
matpdat2=data.frame(matpdat2)
names(matpdat2)=c("V53","V54","V55","V56","V57","V58","V59")

predictions=predict.gam(test,c(matpdat,matpdat2),type="link",se.fit=TRUE)

However, I receive the following error:
Error in model.frame.default(ff, data = newdata, na.action = na.act) :
  invalid type (list) for variable 'matb'

I have also tried combining the two matrices into a data frame, but I
receive the same error using the following code:
predictions=predict.gam(test,data.frame(c(matpdat,matpdat2)),type="link",se.fit=TRUE)

I know that predictions are possible, given that if I do not specify the
prediction values, the GAM. I'm not sure how the data matrix is supposed to
be set up. I searched the MGCV documentation and I also searched the forums
and google, but I was unable to find an example of someone making
predictions from smooths of vectors.

I would appreciate any help!

Thanks!
Nick

-- 
Nicholas C. Jacobson
Doctoral Student in Clinical Psychology
378 Moore Building
The Pennsylvania State University
University Park, PA  16802-3103
Phone: 814-863-0115
Email: njacobson at psu.edu
Website: nicholasjacobson.com

	[[alternative HTML version deleted]]



More information about the R-help mailing list