[R] Re: bootstrap and nls

Patrick Giraudoux patrick.giraudoux at univ-fcomte.fr
Fri Jul 23 17:35:53 CEST 2004


Hi,

Just a recap on the trials done based on Spencer Grave, Bervin A Turlach and Christian Ritz's advise.

On their suggestion, the trouble mentioned has well been turned using the function try() (using the algorithm "plinear" unstead of
"default" was unsuccessful) in the following way:

library(boot)

dif.param<-function(data,i){
RaiesLossA.nls<-try(nls(SolA~a/(1+b*Tps)^c,start=c(a=31,b=0.5,c=0.6),data[i,]),silent=TRUE)
RaiesLossB.nls<-try(nls(Solb~a/(1+b*Tps)^c,start=c(a=33,b=1.4,c=0.5),data[i,]),silent=TRUE)

if ( (inherits(RaiesLossA.nls,"try-error")) |
(inherits(RaiesLossB.nls,"try-error"))) {return(NA)} else {
return(RaiesLossA.nls$m$getPars()-RaiesLossB.nls$m$getPars())}

}

myboot<-boot(Raies,dif.param,R=1000)


The boot objet "myboot" that one get cannot however be handled, eg with boot.ci(),  because "myboot$t" has NA values. This can be
corrected in this way:

myboot$t<-na.omit(myboot$t)
myboot$R<-length(myboot$t[,1])

boot.ci(myboot,index=1, type=c("norm","basic","perc", "bca"))

Studentized CI appear to be quite unstable here and were not used.

That's it!

The effect of omitting some bootstrap replicates (the less than 10% that could not lead to a propper fit)  is however questionable:
may this
biase the result in a way? I am not too much worried about it for my current purpose (crude comparison of parameters), but I
guess that it may be an issue for true statisticians...

Many thanks for the most helpful hints provided,

Patrick Giraudoux




>Hi,
>
>I am trying to bootstrap the difference between each parameters among two non linear regression (distributed loss model) as
>following:
>
># data.frame
>
>
>>Raies[1:10,]
>>
>>
>   Tps  SolA  Solb
>1    0 32.97 35.92
>2    0 32.01 31.35
>3    1 21.73 22.03
>4    1 23.73 18.53
>5    2 19.68 18.28
>6    2 18.56 16.79
>7    3 18.79 15.61
>8    3 17.60 13.43
>9    4 14.83 12.76
>10   4 17.33 14.91
>etc...
>
># non linear model (work well)
>
>RaiesLossA.nls<-nls(SolA~a/(1+b*Tps)^c,start=c(a=32,b=0.5,c=0.6))
>RaiesLossB.nls<-nls(Solb~a/(1+b*Tps)^c,start=c(a=33,b=1.5,c=0.5))
>
>
># bootstrap
>library(boot)
>
>dif.param<-function(data,i){
>RaiesLossA.nls<-nls(SolA[i]~a/(1+b*Tps[i])^c,start=c(a=31,b=0.5,c=0.6))
>RaiesLossB.nls<-nls(Solb[i]~a/(1+b*Tps[i])^c,start=c(a=33,b=1.4,c=0.5))
>RaiesLossA.nls$m$getPars()-RaiesLossB.nls$m$getPars()
>}
>
>
>
>> myboot<-boot(Raies,dif.param,R=1000)
>>
>>
>
>Error in numericDeriv(form[[3]], names(ind), env) :
>        Missing value or an Infinity produced when evaluating the model
>
>It seems that the init values (start=) may come not to be suitable while bootstraping. Data can be sent offline to whom wanted to
>try on the dataset.
>
>Any hint welcome!
>
>Best regards,
>
>Patrick Giraudoux




More information about the R-help mailing list