Re: [R] mgcv

From: Gavin Simpson <gavin.simpson_at_ucl.ac.uk>
Date: Thu, 10 Jun 2010 12:29:23 +0100

On Mon, 2010-06-07 at 10:25 -0700, Dipa Hari wrote:
>
> Hello Sir,
> I am using mgcv package for my data.
> My model isy~x1+f(x2),I want to find out the function f(x2).
> Following is the code.
>
> sm1=gam(y~x1+s(x2),family=binomial, f)
> summary(sm1)
> plot(sm1,residuals=TRUE, xlab="AGE",pch=20)
>
> In this plot I am getting S(x2,1.93) on y axixs
> How should I get the function for x2 from this plot.or Is there
> anyother procedureinR to get this function or value for that
> particular function.for example f(x2)= log(x2) so from that plot how
> can I get this kind of formula for x2 variable?

## evaluate smooth at 200 equally spaced points across range of x2 n <- 200
ndat <- with(f, data.frame("x2" = seq(min(x2), max(x2), length = n)) pred <- predict(sm1, newdata = ndat, type = "terms", terms = "s(x2)")

## or for the observed data
pred <- predict(sm1, type = "terms", terms = "s(x2)")

> How can I find variance covariance matrix for that model

That can be done with the standard vcov() extractor method for "gam" objects:

vcov(sm1)

> and confidence interval for that model ?

Model or smooth s(x2)? If the latter, add se.fit = TRUE to the predict calls above. If the former;

pred <- predict(sm1, se.fit = TRUE)

or for predictions on scale of your response:

pred <- predict(sm1, type = "response", se.fit = TRUE)

And you can add newdata = ndat to either call if you want predictions for the newdata points we generated earlier.

> I tried delta method but I am not getting result.
> Hope you understand my question?
> Thanks

HTH G

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

______________________________________________
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.
Received on Thu 10 Jun 2010 - 11:29:04 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 Thu 10 Jun 2010 - 11:30:28 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.

list of date sections of archive