[R] S.O.S "try" doesnot work in boot?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Sep 9 10:15:38 CEST 2008
Returning NA (of the correct length, not length 1) will not help you, as
all the derived statistics from the bootstrap runs will be NA.
But here you never looked at the result of try.
On Tue, 9 Sep 2008, ctu at bigred.unl.edu wrote:
> First thanks for Jinsong's suggestions
> I would like to do a bootstrap in a nonlinear model. But it fails to converge
> in most of time. (it did converge if I just use nls without boot). Thus, I
> use "try" function to resolve my problem. This following code is from
> Jinsong's suggestion.
>
> h1a.nls<-nls(density~nmf(time, alpha, delta, psi, tau, gamma),data=h1a,
> start=c(alpha=0.3, delta=0.08869, psi=1.26523, tau=3.93919,
> gamma=-1.41927))
>
> h1a.data<-data.frame(h1a,res=resid(h1a.nls),fitted=fitted(h1a.nls))
> h1a.fun<-function(data,i){
> d<-data
> d$density<-d$fitted+d$res[i]
> try(update(h1a.nls,data=d),silent=T)
> if(!inherits(h1a.nls,"try-error")) h1a.coef<-coef(h1a.nls)
h1a.nls is the original fit, not the result of try().
> else h1a.coef<-NA
> h1a.coef
> }
> h1a.boot<-boot(h1a.data, statistic = h1a.fun, R=1000)
>> h1a.boot
>
> ORDINARY NONPARAMETRIC BOOTSTRAP
> Call:
> boot(data = h1a.data, statistic = h1a.fun, R = 1000)
> Bootstrap Statistics :
> original bias std. error
> t1* 0.27892590 0 0
> t2* 0.08869433 0 0
> t3* 1.26523275 0 0
> t4* 3.93919567 0 0
> t5* -1.41926966 0 0
> all of the values of each column in h1a.boot$t are the same.
> Is anyone know to how I can solve this problem?
> Appreciate in advance
>
> Chunhao
>
> ______________________________________________
> R-help at 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.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list