Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8895719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:51:27+00:00 2026-06-14T23:51:27+00:00

I would like to do bootstrap of residuals for nls fits in a loop.

  • 0

I would like to do bootstrap of residuals for nls fits in a loop. I use nlsBoot and in order to decrease computation time I would like to do that in parallel (on a Windows 7 system at the moment). Here is some code, which reproduces my problem:

#function for fitting
Falge2000 <- function(GP2000,alpha,PAR) {
  (GP2000*alpha*PAR)/(GP2000+alpha*PAR-GP2000/2000*PAR)
}

#some data
PAR <- 10:1600
GPP <- Falge2000(-450,-0.73,PAR) + rnorm(length(PAR),sd=0.0001)
df1 <- data.frame(PAR,GPP)

#nls fit
mod <- nls(GPP~Falge2000(GP2000,alpha,PAR),start=list(GP2000=-450,alpha=-0.73),data=df1, upper=c(0,0),algorithm="port")

#bootstrap of residuals
library(nlstools)
summary(nlsBoot(mod,niter=5))
#works

#now do it several times
#and in parallel
library(foreach)
library(doParallel)

cl <- makeCluster(1)
registerDoParallel(cl)

ttt <- foreach(1:5, .packages='nlstools',.export="df1") %dopar% {
  res <- nlsBoot(mod,niter=5)
  summary(res)

}
#Error in { : 
#task 1 failed - "Procedure aborted: the fit only converged in 1 % during bootstrapping"

stopCluster(cl)

I suspect this an issue with environments and after looking at the code of nlsBoot the problem seems to arise from the use of an anonymous function in a lapply call:

l1 <- lapply(1:niter, function(i) {
    data2[, var1] <- fitted1 + sample(scale(resid1, scale = FALSE), 
        replace = TRUE)
    nls2 <- try(update(nls, start = as.list(coef(nls)), data = data2), 
        silent = TRUE)
    if (inherits(nls2, "nls")) 
        return(list(coef = coef(nls2), rse = summary(nls2)$sigma))
})
if (sum(sapply(l1, is.null)) > niter/2) 
    stop(paste("Procedure aborted: the fit only converged in", 
        round(sum(sapply(l1, is.null))/niter), "% during bootstrapping"))

Is there a way to use nlsBoot in a parallel loop? Or do I need to modify the function? (I could try to use a for loop instead of lapply.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:51:28+00:00Added an answer on June 14, 2026 at 11:51 pm

    By moving the creation of the mod object into the %dopar% loop, it looks like everything works OK. Also, this automatically exports the df1 object, so you can remove the .export argument.

    ttt <- foreach(1:5, .packages='nlstools') %dopar% {
      mod <- nls(GPP~Falge2000(GP2000,alpha,PAR),start=list(GP2000=-450,alpha=-0.73),data=df1, upper=c(0,0),algorithm="port")
      res <- nlsBoot(mod,niter=5)
      capture.output(summary(res))
    
    }
    

    However, you might need to work out what you want returned. Using capture.output was just to see if things were working, since summary(res) seemed to only return NULL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use twitter bootstrap to create Facebook like tooltip layout. I would
Would like a for loop in jquery so that: For every hover_link: show hidden
I would like to use the new Bootstrap library from Twitter for an external
I'm using bootstrap for my new site. I would like to use the button
I would like to use the bootstrap-fileupload.js ( http://jasny.github.com/bootstrap/javascript.html#fileupload ) but I am confused
I am using twitter bootstrap and I would like to create a grid that
I am using bootstrap's grid, and I would like to have a div that
In my rails 3.0.10 I would like to use Bootstrap from Twitter but I
I would like to use bootstrap's built in tabs in my site, but I
I use Bootstrap for my CSS style. I would like to fake a link

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.