gam.sim {spgam}R Documentation

~~function to do ... ~~

Description

~~ A concise (1-5 lines) description of what the function does. ~~

Usage

gam.sim(form, gam.data, pts, region, start, ngrid = NULL, prev.sims = NULL)

Arguments

form ~~Describe form here~~
gam.data ~~Describe gam.data here~~
pts ~~Describe pts here~~
region ~~Describe region here~~
start ~~Describe start here~~
ngrid ~~Describe ngrid here~~
prev.sims ~~Describe prev.sims here~~

Details

~~ If necessary, more details than the description above ~~

Value

~Describe the value returned If it is a LIST, use

comp1 Description of 'comp1'
comp2 Description of 'comp2'

...

Warning

....

Note

~~further notes~~

~Make other sections like Warning with section{Warning }{....} ~

Author(s)

~~who you are~~

References

~put references to the literature/web site here ~

See Also

~~objects to See Also as help, ~~~

Examples

##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--    or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function(form,gam.data,pts,region,start,ngrid=NULL,prev.sims=NULL){
        if(is.null(prev.sims)){
                prev.sims <- list(m=0,tval=NULL,tvalobs=start$tvalobs,pval=NULL,
                sigmat=matrix(0,nrow=length(start$surf.est[,1]),
                                ncol=length(start$surf.est[1,])),
                                x=start$x,y=start$y)
        }
        null.prob=start$prob
        surface.est=start$surf.est
        h=start$h 
        formul=formula(form)
        termos<-terms(formul)
        at<-as.character(attr(termos,"variables"))[-1]
        data<-as.data.frame(as.matrix(gam.data[,at]))
        why<-data[,at[1]]
        simcase=sample(1:length(why),size=sum(why),replace=F,prob=null.prob)
        simwhy=rep(0,length(why)); simwhy[simcase]=1
        data[,at[1]]<-simwhy
        sim=gamfit(form,data,pts=pts,region=region,h=h,ngrid=ngrid)
        tval=mean(sim$g2^2)
        below=as.numeric(sim$g2est$z<surface.est)
        prev.sims$m=prev.sims$m+1
        prev.sims$tval=c(prev.sims$tval,tval)
prev.sims$sigmat=prev.sims$sigmat+below
        prev.sims$pval=(sum(prev.sims$tval>=start$tvalobs)+1)/(prev.sims$m+1)
        cat('\n\n ********* DONE',prev.sims$m,'GAM FITS *********\n\n')
prev.sims
  }

[Package spgam version 1.0 Index]