mgcv:gam predicted class?
On Thu, 2013-07-18 at 16:13 +0200, Per Bergstr?m wrote:
How to get prediction of classes in gam? I have a problem with getting predicted classes from a gam-model using the gam function in the "mgcv"-package. I have a dataset where I have classified the response variable into 5 classes (i. e. 1, 2, 3, 4, 5) and I want to use a gam-model generated on a training dataset (traindata) to predict the class beloning of data from a test-dataset (testdata) but I can't get it to work. I generated the gam-model using: model<-gam(growthclass~Vol+Expo+distance+......+temperature,family=binomial, type="classification",data=traindata)
The binomial would presume two classes (0,1) and there is no `type` argument in `mgcv::gam()`, so the model you are fitting seems ill-fitted (sorry) to the problem. What you describe could be a multinomial model, but I don't know how that can be fitted with splines. It seems *you* has discretised the response. Why not fit the model on on the non-discrete response and then apply the classification to those values rather than the other way round which is what you have done. HTH G
When I then try to predict the class beloning of the test-dataset using:
pred<-predict(model,newdata=testdata)
I get results like this:
2 4 6 7 9
-1.93680872 2.28422570 0.99747563 0.03627236 0.74235160
But I really want the results to look like this:
2 4 6 7 9
1 3 2 1 2
i.e. the predicted classes for the new samples.
Obviously I am doing something wrong and it is probably very simple to solve but I've got stuck on it for a while and would appreciate some help solving it.
Thanks
Per
[[alternative HTML version deleted]]
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Gavin Simpson, PhD [t] +1 306 337 8863 Adjunct Professor, Department of Biology [f] +1 306 337 2410 Institute of Environmental Change & Society [e] gavin.simpson at uregina.ca 523 Research and Innovation Centre [tw] @ucfagls University of Regina Regina, SK S4S 0A2, Canada