Questions tagged [nls]

nls refers to nonlinear least-squares and is a function in R that allows to estimate the parameters of a nonlinear model.

nls should not be confused with nls-lang which is an environment variable for Oracle databases.

670 questions
0
votes
2 answers

R nlsModel singular gradient matrix at initial parameter estimates error initial parameter estimation problem

I need to do an nls fit for crop/year data (see Question on nls fit in R - why is this such a strange fit?). I am starting with this data and using the coefficients from a regular linear model fit as the initial parameter estimates. x <- c(1979L,…
user8229029
  • 883
  • 9
  • 21
0
votes
0 answers

Trouble with fitting a power curve in ggplot2

I have a dataset in r with the following columns: > names(dataset) [1] "Corp.Acct.Name" "Product-name" "Package.Type" "Total.Quantity" "ASP.Ex.Works" What I am trying to do is create a scatter plot with Total.Quantity on the x axis and…
proff
  • 1
  • 1
0
votes
0 answers

R nls(); Error in nlsModel: singular gradient matrix at initial parameter estimates

I receive an error from nls function in R. I search some similar questions, but do not solve this problem. For example, I try to use nlsLM from library 'minpack.lm', it also fails. So I have to ask for help here. Following is the code: tt = c(10,…
Lin
  • 195
  • 1
  • 12
0
votes
1 answer

How to calculate R-squared in nls package (non-linear model) in R?

I analyzed non-linear regression using nls package. power<- nls(formula= agw~a*area^b, data=calibration_6, start=list(a=1, b=1)) summary(power) I heard in non-linear model, R-squared is not valid and rather than R-squared, we usually show residual…
Jin.w.Kim
  • 599
  • 1
  • 4
  • 15
0
votes
1 answer

How to force intercept to zero using nls pacakge in R?

I used nls package to analyze non linear model (power curve, y= ax^b). cal<- nls(formula= agw~a*area^b, data=calibration_6, start=list(a=1, b=1)) summary(cal) What I want now is to force intercept (a) to zero to check something. In Excel, I can't…
Jin.w.Kim
  • 599
  • 1
  • 4
  • 15
0
votes
0 answers

Error in nlsModel(formula, mf, start, wts) : singular gradient matrix at initial parameter estimates

nls((mortalityof2018)~(i+g*h^age),start = list(g=1,h=1,i=1)) Error in nlsModel(formula, mf, start, wts) : singular gradient matrix at initial parameter estimates Everytime i enter the above code i get an error saying singular gradient matrix at…
AEx12
  • 1
0
votes
1 answer

Write a loop in R that achieves the same result as combn (x,m,sum)

I have the function below: Proposed <- function(N_b,Lanes,m,A,x.sqr,e_1,e_2,e_3,e_4,e_5) { e <- data.frame(e_1,e_2,e_3,e_4,e_5) CSi <- m * ((Lanes/N_b) + (max(A * combn(e,Lanes,sum)) / x.sqr)) return(CSi) } I want to write a similar function…
Maral Dorri
  • 468
  • 5
  • 17
0
votes
2 answers

Use combn within a function for nonlinear regression with nlsLM

Given is a few rows of a dataframe DATA: > dput(DATA[c(1,7,20,25,26,53,89),]) structure(list(Lanes = c(3, 3, 3, 3, 3, 3, 3), N_b = c(5, 5, 5, 5, 5, 5, 5), A = c(-12, -12, -15, -9, -9, -15, -9), x.sqr = c(1440, 1440, 2250, 810, 810, 2250, 810), e_1…
Maral Dorri
  • 468
  • 5
  • 17
0
votes
0 answers

Exponential models using nls() in R

I have a dataset which resembles the following: time <- c(0, 10, 20, 30, 40, 50, 60, 70 , 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190) temp <- c(30, 28, 24, 20, 17, 13, 10, 9, 8, 7.5, 7, 6.5, 6, 5.8, 5.5, 5.3, 5.1, 5, 5, 5) Ts = 5 #…
user12556893
0
votes
1 answer

How to work out the time of when the asymptote occurs in a logistic model in R?

I have fitted logistic growth models in R using nls function. pop.ss <- nls(MRDRSLT ~ SSlogis(TIME, phi1, phi2, phi3), data = testing, na.action = na.omit) Formula: MRDRSLT ~ SSlogis(TIME, phi1, phi2, phi3) Parameters: Estimate Std. Error t…
Bobby
  • 13
  • 3
0
votes
1 answer

Sum of residuals in NLS regression are not close to zero

I am running a NLS model in R. The residuals are normally distributed, but the mean of the residuals are not zero. How is this possible? x <- data.frame( height= c(185, 194,166, 187, 181,177), weight=c(77,67,79,87,65,64), …
0
votes
1 answer

Sigmoidal curve in R

I am novice at R studio. I'm trying to fit a sigmoidal curve for this data x <- c(0, 0.19, 0.3, 0.4, 0.52, 0.65, 0.78, 0.9, 1, 1.5, 2, 3) y <- c(0, 0.001131392946767, 0.001429213070191, 0.001695405556196, 0.008619063174144, 0.00970100252551,…
matgirl
  • 3
  • 3
0
votes
0 answers

How to perform statistical analysis for a nls function in R?

fm0 <- nls(exp(y) ~ exp(a*log(x)), moisture, start = c(a = 1, b = 1)) This is my code to obtain the starting conditions for my locarithmic model. How can I check the residuals on the reliability of this model for my dataset? Or what am I missing? I…
Cyril
  • 5
  • 3
0
votes
1 answer

R - NLS Error 'Missing value or an infinity produced when evaluating the model'

I found the following piece of code by a user called Taylor White on a Medium blog which calculates the R0 number. I tried to run the code but get hit with the following error: Error in numericDeriv(form[[3L]], names(ind), env) : Missing value or an…
Ciaran O Brien
  • 374
  • 3
  • 13
0
votes
1 answer

tryCatch crashes while nls fit

I am trying to fit a non-linear model using nls function. The model has a conditioning and works by groups therefore I try to implement a loop which covers over 300 combinations of starting values. I am using tryCatch but to my surprise the loop…
Loub
  • 101
  • 1