From: Uwe Ligges <ligges_at_statistik.tu-dortmund.de
<mailto:ligges_at_statistik.tu-dortmund.de?Subject=Re:%20[R]%20Help%20with%2
0gam> > 
Date: Wed, 11 May 2011 19:08:38 +0200

On 11.05.2011 17:22, Zsolt Macskasi wrote: 
> Hi, 
> 
 <http://tolstoy.newcastle.edu.au/R/e14/help/11/05/1036.html#1040qlink1> > I
am a brand new user of R and I am trying to use the gam procedure with the
package mgcv. I did a bit of my homework by consulting the R-manual, as well
as the mgcv manual written by Simon Wood. I admit it was just a few hours,
but what I am trying to do is really basic. Essentially, what I am trying to
do is to generate the fitted values after the execution of the gam procedure
and export them into Excel. 
> 
> Here is my program: 
> 
> ABC<- read.table("Incidence Data.csv", header=TRUE, sep=",") 

probably the next three lines can be omitted if you just say: 

fit <- gam(incidence~te(age,birthyear), data=ABC, family=poisson, fit=TRUE) 

 <http://tolstoy.newcastle.edu.au/R/e14/help/11/05/1036.html#1040qlink2> >
incidence<- ABC[,1] 
> age<- ABC[,2] 
> birthyear<- ABC[,3] 
> fit<-gam(incidence~te(age,birthyear), family=poisson, fit=TRUE) 

> 
 <http://tolstoy.newcastle.edu.au/R/e14/help/11/05/1036.html#1040qlink3> >
All this works. Now, how can I see the fitted values and copy them back to
Excel? 

As for most fitted models, you can get 

Fitted values: 

   predict(fit) 

Coefficients: 

  coef(fit) 

etc. 

Uwe Ligges 

 <http://tolstoy.newcastle.edu.au/R/e14/help/11/05/1036.html#1040qlink4> >
Thank you very much, 
> 
> Zsolt 
> 
> [[alternative HTML version deleted]] 
> 

Note that predict(fit) will give the additive fit.  If you are looking for
the fitted mean values, I would do the following:



ds <- data.frame(fit$fitted.values)

write.csv(ds, file = "test.csv") #to write the fitted mean values to a csv
file



Paula McGee




        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to