Found the answer...There is a line in the nlsLM function: for (i in names(start)) assign(i, start[[i]], envir = startEnv) The problem was the start provided in my formula did not have a name, b. I thought by using the list command that would resolve the issue. I have corrected it...

You should take @Roland's comment on your use of with seriously. There are much better ways of doing this, but building on your code, I would have done something like this. library(ggplot2) library(reshape2) df$fitted <- fitted(fit) df$upper <- df$fitted + 1 #I didn't bother to produce actual confidence band df$lower...

rnorm will give you noise from a normal distribution. For example: ComputeDi.Bi(hi, d, h, b1, b2, b3, b4, b5, b6, b7) + rnorm(length(hi), mean = 0, sd = 0.1) runif, rpois, rbinom and many more are also available. I'm not sure that's what you want to do here though... I'm...

r,ggplot2,curve-fitting,data-fitting,nls

For nls you have to specify the parameters more carefully. Also, you probably don't want to use log(y), because that will plot the logarithm instead of y. My guess is that you want to use something like y ~ exp(a + b * x). See below for an example. ggplot(df,...

Answer to Q1: your grouping structure is correct. You can validate it by running nls on a subset of your data: rec.hyp.test <- nls(flux ~ Re - ((Amax*par)/(k+par)), data=subset(nee.example,julian==159 & plotID==3), start=c(Re=3, k=300, Amax=5), na.action=na.omit) coef(rec.hyp.test) # Re k Amax # 0.7208943 792.4412287 0.8972519 coef(rec.hyp)[3,] # Re k Amax #...

r,regression,curve-fitting,data-fitting,nls

Here's one way to do it. (On edit: this works fine, a typo in my original code made it seem like it wasn't working, thanks to @MrFlick and @Gregor for pointing this out). First replicate your code with a fixed random seed: set.seed(1) x<-seq(0,120, by=5) y<-100/50*exp(-0.02*x)*rnorm(25, mean=1, sd=0.05) y2<-(1*100/50)*(0.1/(0.1-0.02))*(exp(-0.02*x)-exp(-0.1*x))*rnorm(25, mean=1,...

After searching the Rhelp archives for that error and finding that a similar situation was solved by Duncan Murdoch by converting the matrices to "long"-form using as.vector() and reviewing the material on nls and nlsList in Pinheiro and Bates, I'm posting the results of some experiments that may be congruent...

The main problem is the model specification. For fixed b any combination of a and n for which n* b/(a^b) is the same yield the same model giving rise to the singularity. Fix either a or n. In the following we fix a to be 1. The other problem with...

r,for-loop,error-handling,try-catch,nls

To understand the problem you need to understand how try() works. Specifically, try will run the code provided it's first argument until the code completes on it's own or until it encounters an error. The special thing that try() does is that if there is an error in your code...

To avoid more complicated subsetting, try simplifying your summary function to: ldply(NLmodels, function(x) c(coef(x),confint(x),p=summary(x)$coef[1,4])) ...

r,nonlinear-functions,nls,non-linear-regression

I am not aware of such packages and personally I don't think that you need one as the problem can be solved using a base R. nls is sensitive to the starting parameters, so you should begin with a good starting guess. You can easily evaluate Q because it corresponds...

The first line reads the data into R The second line restructures the data into a data frame (a table structure that is used commonly in R, it will be passed as the data to nls in line 3). This looks like older code, most modern coders would replace lines...

nls(...) uses the Gauss Newton method by default; that error message, which is quite common actually, means that the Jacobian matrix cannot be inverted. I think your problem has to do with the fact the your composite function (the RHS of your formula) is not continuous at t=tswitch for arbitrary...