# [R] Hep on using GAM() in R

From: zhijie zhang <epistat_at_gmail.com>
Date: Wed, 12 Dec 2007 20:38:18 +0800

Dear friends,
I met some problem on using GAM() function in R.

Any help or suggestions are greatly appreciated.

# My programs and problems are list below#

library(splines)

library(gam)

gam.opt<-gam(mark~lo(x,y,span=0.2)+lo(lstday2004,span=0.2)+lo(slope,span=0.2)+lo(ndvi2004,span= 0.2)+lo(elevation,span=0.2)+disbinary,
family=binomial(logit),data=point) #span is 0.2

#when you run the above codes, 30 warnings() appear

> warnings()

Warning message：

1. In lo.wam(x, z, wz, fit\$smooth, which, fit\$smooth.frame, ... :

lo.wam convergence not obtained in 30 iterations

2: In lo.wam(x, z, wz, fit\$smooth, which, fit\$smooth.frame, ... :

lo.wam convergence not obtained in 30 iterations

```.............................................

```

gam.opt2<-gam(mark~lo(x,y,span=0.05)+lo(lstday2004,span=0.05)+lo(slope,span= 0.05)+lo(ndvi2004,span=0.05)+lo(elevation,span=0.05 )+disbinary,family=binomial(logit),data=point) #span is 0.05

#22 warnings()

> warnings()

1. In lo.wam(x, z, wz, fit\$smooth, which, fit\$smooth.frame, ... :

k-d tree limited by memory; nvmax= 226

2: In lo.wam(x, z, wz, fit\$smooth, which, fit\$smooth.frame, ... :

pseudoinverse used at 14923

3: In lo.wam(x, z, wz, fit\$smooth, which, fit\$smooth.frame, ... :

4: In lo.wam(x, z, wz, fit\$smooth, which, fit\$smooth.frame, ... :

reciprocal condition number 0

```........................................................

```

Q1: Their warning messages were differernt, are there any problem with the codes that i used? What does these warnings mean?

Q2: As we know, the span is an important role for smoothing, so i try to choose the optimal span by the AIC criterion. But it seemed that i can't run it successfully,

My codes are listed below.

hmin<-0.05; hmax<-0.95; hstart<-hmin; nh<-100

hstep<-(hmax-hmin)/(nh-1)

aic.h<- matrix(NA,nrow=nh,ncol=2)

for (i in 1:nh)

{

htry<-hstart+(i-1)*hstep m.gam
<-gam(mark~lo(x,y,span=htry)+lo(lstday2004,span=htry)+lo(slope,span=htry)+lo(ndvi2004,span=htry)+lo(elevation,span=htry)+disbinary,family=binomial(logit),data=point)

aic.h[i,2]<-m.gam\$aic

aic.h[i,1]<-htry

}

aic.h #only the first line in aic.h has values, there must be errors in my codes

Where goes wrong? How should i do for determining the best span for different variables?
Any help or suggestions are greatly appreciated?  BTW, I'd like to send you my dataset off this mailing list if possible.

```--
With Kind Regards,

oooO:::::::::
(..):::::::::
:\.(:::Oooo::
::\_)::(..)::
:::::::)./:::
::::::(_/::::
:::::::::::::
[***********************************************************************]
Zhi Jie,Zhang ,PHD
Tel:+86-21-54237149
Dept. of Epidemiology,School of Public Health,Fudan University
Postcode:200032
Email:epistat_at_gmail.com
Website: www.statABC.com
[***********************************************************************]
oooO:::::::::
(..):::::::::
:\.(:::Oooo::
::\_)::(..)::
:::::::)./:::
::::::(_/::::
:::::::::::::

[[alternative HTML version deleted]]

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help