gam.sim {spgam} | R Documentation |
~~ A concise (1-5 lines) description of what the function does. ~~
gam.sim(form, gam.data, pts, region, start, ngrid = NULL, prev.sims = NULL)
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~~ |
~~ If necessary, more details than the description above ~~
~Describe the value returned If it is a LIST, use
comp1 |
Description of 'comp1' |
comp2 |
Description of 'comp2' |
...
....
~~further notes~~
~Make other sections like Warning with section{Warning }{....} ~
~~who you are~~
~put references to the literature/web site here ~
~~objects to See Also as help
, ~~~
##---- 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 }