[R] Format of a data frame
jim holtman
jholtman at gmail.com
Mon Oct 22 05:12:07 CEST 2007
If you look at the example for predict.gam, it should be clear that
the data frame has a column(s) for the value(s) you want to predict
for:
> newd <- data.frame(x0=(0:30)/30,x1=(0:30)/30,x2=(0:30)/30,x3=(0:30)/30)
> pred <- predict.gam(b,newd)
> head(newd)
x0 x1 x2 x3
1 0.00000000 0.00000000 0.00000000 0.00000000
2 0.03333333 0.03333333 0.03333333 0.03333333
3 0.06666667 0.06666667 0.06666667 0.06666667
4 0.10000000 0.10000000 0.10000000 0.10000000
5 0.13333333 0.13333333 0.13333333 0.13333333
6 0.16666667 0.16666667 0.16666667 0.16666667
On 10/21/07, Thomas L Jones, PhD <jones3745 at verizon.net> wrote:
> The goal is to smooth a scatterplot using the LOESS locally weighted
> regression program and a gam. There are 156 points. Thus x can have the
> value 1, or 2, etc., up to a maximum of x = 156. The y values are random,
> with a Poisson distribution, or the next thing to it.
>
> After reading in the data, I was able to generate a model, named mod, as
> follows:
>
> mod <- gam(y~lo(x), family=poisson, x = TRUE)
>
> Next, I want to look at some values of the fitted curve: Specifically x =1,
> x = 2, and x = 3. Upon looking up predict.gam, I see the following:
>
> Usage
>
> predict.gam (object, newdata, type, dispension, se.fit = FALSE, na.action,
> terms ...)
>
> One of the arguments of the function is named newdata. I see:
>
> newdata A data frame containing the values at which predictions are
> requested. [snip] Only those predictors, referred to in the
> right side of the formula, need be present by name in newdata.
>
> I am having difficulty figuring out the format of the data frame. For
> example, how many columns should it have? Should it have a column for the
> three values of x? Probably there is a rather standard format for data
> frames, but I am having trouble looking it up. Perhaps some one would point
> me to the place in the documentation where this is discussed.
>
> Tom Jones
>
> ______________________________________________
> 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?
More information about the R-help
mailing list