Re: [R] Error using mgcv package

From: Jari Oksanen <jari.oksanen_at_oulu.fi>
Date: Tue, 12 Jun 2007 08:08:34 +0000 (UTC)

spime <sabya23 <at> gmail.com> writes:

>
>
> Hi all,
>
> I need some solution in the following problem. The following error appears
> when i use "mgcv" package for implementing GAM. But the same formula works
> fine in "gam" package.
>
> > model.gam <- gam(formula = RES ~
> > CAT01+s(NUM01,5)+CAT02+CAT03+s(NUM02,5)+CAT04+
> + CAT05+s(NUM03,5)+CAT06+CAT07+s(NUM04,5)+CAT08+s(NUM05,5)+CAT09+
> + CAT10+s(NUM06,5)+CAT11+NUM07+CAT12+CAT13,
> + family = binomial(link = logit), data = train.data,na.action = na.exclude,
> + control = list(epsilon = 0.001,bf.epsilon = 0.001, maxit = 50,
> + bf.maxit = 10, trace = F))
>
> Error in terms.formula(reformulate(term[i])) :
> invalid model formula in ExtractVars
>
It seems that nobody answered this (in public).

It seems that function s() in mgcv is defined as:

s(..., k = -1, fx = FALSE, bs = "tp", m = 0, by = NA)

(Like you see reading its help ?s). The function definition starts with "...", and after three dots you cannot use positional arguments, but you must give the full argument name. Try replacing s(NUM01, 5) with s(NUM01, k=5). See also help in mgcv (?s pointing to ?choose.k) for interpreting argument 'k' which is not directly degrees of freedom.

There may be other problems, but this probably fixes tha one you reported above.

cheers, jari oksanen

> And after deleting df's
>
> model.gam <- gam(formula = RES ~ CAT01+s(NUM01)+CAT02+CAT03+s(NUM02)+CAT04+
> + CAT05+s(NUM03)+CAT06+CAT07+s(NUM04)+CAT08+s(NUM05)+CAT09+
> + CAT10+s(NUM06)+CAT11+NUM07+CAT12+CAT13,
> + family = binomial(link = logit), data = train.data)
>
> Error in smooth.construct.tp.smooth.spec(object, data, knots) :
> A term has fewer unique covariate combinations than specified
> maximum degrees of freedom
>
> Can anybody show me some light in this case!!!
>
> Thanks in advance.



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. Received on Tue 12 Jun 2007 - 08:20:05 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 12 Jun 2007 - 10:31:48 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.