Question about predict function
Thomas L Jones wrote:
I am working with a non-parametic smoothing operation using a Generalized Additive Model. It is a bivariate data set. I know how to do the smooth, and out comes a nice smooth curve. Now I want to find the value of the smoothed curve for several values of x (the abscissa). This can be done (please correct me if I am wrong) by using the predict.gam function. You feed the predict.gam function a data frame, telling it what you want. Let's start with the predict.gam function. Are you supposed to be able to look up how to use it? E.g., what goes into the various columns of the data frame? I do have a working function call for predict. It says: pred_out <- predict (mod, data.frame (x = x), type = "response") (mod is the model) Now, if you tell me that x = x, I will believe you. But what is meant by "data.frame (x = x)", I know not. Or would it better to call the class, names, and str functions, using some well chosen objects?
Does this help?
library(gam)
data(kyphosis)
kyphosis.gam <- gam(Kyphosis ~ s(Age,4) + Number, family = binomial,
data=kyphosis)
predict(kyphosis.gam, data.frame(Age = c(10,100,200), Number = 3),
type="response")
1 2 3
0.019098701 0.248043366 0.005807921
The data frame should contain the predictor variables in the model and
the values for the variables should be those at which you want a prediction.
Tom Jones
______________________________________________ R-help at stat.math.ethz.ch 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.
Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894