Andry
Andry

Reputation: 16845

How to plot the fitting curves in a GAM regression in R?

I am trying to fit a GAM model as follows:

model <- gam(`output` ~ s(`var 1`) + s(`var 2`), data = mydata)

Where mydata is a data.frame containing the data I need with columns: output, var 1 and var 2.

When I run the command I get this warning:

Warning message:
In model.matrix.default(mt, mf, contrasts) :
  non-list contrasts argument ignored

Which I have no idea what it means. However I can see that the model is fit as summary(model) returns stuff.

Now I would like to plot the fitting curves for:

How?


Attempt I

I have tried to:

plot(model)

But I get this error:

Error in parse(text = evars) : <text>:1:8: unexpected symbol
1: var 1

Upvotes: 0

Views: 243

Answers (1)

Andry
Andry

Reputation: 16845

The problem was in the names. lm accepts the syntax of names enclosed in backticks. gam does not. In the end, I changed the data frame to allow this:

model <- gam(y ~ s(x) + s(w), data = mydata)

And then the plotting worked.

Upvotes: 1

Related Questions