Reputation: 71
I'm trying to run a smoothing spline regression using gam for y as a function of a and b, variables in the dataset. But when I run the following code, I get the following error.
> autogam_axb <- gam(data$y~s(data$a,data$b))
Error in eval(expr, envir, enclos) : object 'a' not found
Any idea what I am doing wrong?
Upvotes: 0
Views: 204
Reputation: 174798
You need to separate the model specification from the locations of the data. The former is specified via the formula, whilst the data
argument is used to tell gam
about the latter:
autogam_axb <- gam(y ~ s(a, b), data = data)
This serves two purposes:
data$
, which makes it easier to see what it being fitted, andUpvotes: 2