r - Problems with Gamma Regression Model after doing PCA decomposition -


i unfamiliar pca's , implementing them in r. have data , want apply pca decomposition way deal co-linearity. after applying pca analysis, want use gamma regression model, not sure how fix error keep getting. post code , results below:

   library(cosmophotoz)     totaldata<-merge(phat0test, phat0train, all=true)    summary(totaldata)     #gamma regression without pca done on phat0train, included in cosmophotoz    gamma1<-glm(redshift~., family=gamma(link="log"), data=phat0train)    summary(gamma1) #works fine     #new subset of data     set.seed(0508)    sample<-sample(1:nrow(totaldata), 0.90*nrow(totaldata))    test<-totaldata[sample,]    train<-totaldata[-sample,]    #pca on subsets    mytest<-subset(test, select=-c(redshift))   pcatest <- princomp(mytest,cor=t)   summary(pcatest, loadings=t)   mytrain<-subset(train, select=-c(redshift))  pcatrain <- princomp(mytrain,cor=t)  summary(pcatrain, loadings=t)   #formula based on pca loadings keep @ least 99.6% variance  form<-redshift~(poly(comp.1, 2))^2 + poly(comp.2, 2)*comp.3*comp.4*comp.5*comp.6    #gamma regression post pca    gammafit<-glm(form, family=gamma(link="log"), data=pcatrain) 

the error message posted below. of right now, have better understanding on why getting error. reading, has pca's being list , not data fram. still don't know how fix , know if correct way use pca , regression.

      error in as.data.frame.default(data) :       cannot coerce class ""princomp"" data.frame 


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -