words_of_wisdom - 1 year ago 70

R Question

I'm new to R and started using it to implement a gam model. I've been following this tutorial examples and R keeps throwing an error when I try to use by. I really have no idea what's wrong and would appreciate it if anybody can suggest something.

Thanks a lot in advance.

`>require(mgcv)`

>set.seed(10)

## simulate date from y = f(x2)*x1 + error

>dat <- gamSim(3,n=400)

Continuous `by' variable example

>b<-gam(y ~ s(x2,by=x1),data=dat)

Error in s(x2, by = x1) : unused argument (by = x1)

Additional information: R version = 3.3.1 (2013-06-21)

OS = Windows 10

Answer Source

*Code*

```
require(mgcv)
set.seed(10)
## simulate date from y = f(x2)*x1 + error
dat <- gamSim(3,n=400)
b <- gam(y ~ s(x2,by=x1),data=dat)
b
```

*Result*

Continuous `by' variable example

Family: gaussian Link function: identity

Formula: y ~ s(x2, by = x1)

Estimated degrees of freedom: 9.2 total = 10.2

GCV score: 4.518245

Please start a fresh R session and see if you get the same error. Also, please check your version of `mgcv`

and make sure it's up to date.