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
4
votes
1 answer

R: Trouble fitting a 4-parameter hockeystick curve with nls

My dataset: mydata<-structure(list(t = c(0.208333333, 0.208333333, 0.208333333, 0.208333333, 1, 1, 1, 1, 2, 2, 2, 2, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 0.208333333, 0.208333333, 0.208333333, 0.208333333, 1, 1, 1, 1, 2, 2, 2, 2),…
Pinemangoes
  • 1,158
  • 3
  • 11
  • 13
4
votes
2 answers

PROC NLIN from SAS to R

I have been currently assigned a work where I need to translate a SAS code to R. I have been able to successfully do 80% of it and now I am stuck at the part where PROC NLIN is used. From what I read, PROC NLIN is used to fit Non-Linear Models andI…
RHelp
  • 815
  • 2
  • 8
  • 23
4
votes
1 answer

changepoint detection in R

Anybody an idea how to solve this R issue? It is to find a changepoint in a relation, like x=5 in data below. fitDat <- data.frame(x=1:10, y=c(rnorm(5, sd=0.2),(1:5)+rnorm(5, sd=0.2))) plot(fitDat$x, fitDat$y) SAS works beautifully…
4
votes
3 answers

Using "predict" in nls

I have data from the USGS Nation Water Data website. I am currently trying to plot and fit curves to the data to use in prediction for different measurements taken within the dataset (dissolved oxygen, pH, gage height and temp) all in relation to…
Jarrod
  • 43
  • 1
  • 7
4
votes
1 answer

Nonlinear least squares in Stata, how to model summation over variables/sets?

I would like to estimate the following function by nonlinear least squares using Stata: I am testing the results of another papper and would like to use Stata since it is the same software/solver as they used in the paper I am replicating and…
Jens
  • 43
  • 1
  • 4
4
votes
1 answer

R: How to add constraints for a model to be estimated via lm or nls?

I estimate a model in R and I would like to add constraint that would force one of the coefficients to be smaller than the other one. How can I do that?
infoholic_anonymous
  • 969
  • 3
  • 12
  • 34
3
votes
2 answers

OCI JDBC Driver and NLS Settings

We have created a "after logon" trigger to alter the session in order to set the two NLS settings - NLS_SORT and NLS_COMP. NLS_SORT needs to be set to BINARY_CI and NLS_COMP needs to be set to LINGUISTIC. By querying the V$NLS_PARAMETERS view after…
Andy Dufresne
  • 6,022
  • 7
  • 63
  • 113
3
votes
1 answer

Dealing with 0 error in nls - R script

Is there any way to allow my nls to have 0 residual error when it makes a non linear fit? I have cases in my data where the fit made should have 0 error, but nls always fails and spits out an error. Can anyone show me: How do I test if this is the…
StanLe
  • 5,037
  • 9
  • 38
  • 41
3
votes
2 answers

R script - NLS not working

I have 5 (x,y) data points and I'm trying to find a best fit solution consisting of two lines which intersect at a point (x0,y0), and which follow these equations: y1 = (m1)(x1 - x0) + y0 y2 = (m2)(x2 - x0) + y0 Specifically, I require that the…
CodeGuy
  • 28,427
  • 76
  • 200
  • 317
3
votes
1 answer

Next Steps with nls()?

Working in R, I am trying to use nls() to fit some data to the following model: y ~ c - a * exp(-b * x) My data: x <- c(8, 8, 10, 10, 10, 10, 12, 12, 12, 12, 14, 14, 14, 16, 16, 16, 18, 18, 20, 20, 20, 22, 22, 22, 24, 24, 24, 26, 26, 26, 28, 28,…
Scoops
  • 61
  • 4
3
votes
3 answers

How can I get the coefficients from nlsList into a dataframe?

Is there a way to extract just the estimates from nlsList()? Sample data: library(nlme) dat<-read.table(text="time gluc starch solka 1 6.32 7.51 1.95 2 20.11 25.49 6.43 3 36.03 47.53 10.39 6 107.52 166.31 27.01 12 259.28 305.19 113.72 24 283.40…
3
votes
1 answer

Reproducing PROC NLIN output with nls

I'd like to implement the following SAS code in R. $$N_e = N_o{1-exp[\frac{(d+bN_o)(T_h N_e - T)}{(1+c N_o)}]}$$ where $b>0$, $c\geq 0$, $T_h>0$, and $T=72$. The SAS code is DATA NOTONECT; INPUT N0 REP FATE NE N02 N03 PROPEAT; …
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
3
votes
1 answer

nonlinear curve fitting in R

I am working on nonlinear curve fitting in R and I cannot figure out how to constrain the data using the variables... Here is an example: dat<-read.table(text="time y 1 4.62 2 13.55 3 30.82 6 93.97 12 145.93 24 179.93", header =…
3
votes
1 answer

Plotting derivative of nls model in R

I have used nls function to fit the following equation y ~ (C + (A1*exp(-x/h1)) + (A2*exp(-x/h2))) My code looks as follows f <- as.formula(y ~ (C + (A1*exp(-x/h1)) + (A2*exp(-x/h2)))) nls_b <- nls(f, data = df, start = list(C = 0.140, A1 = 0.051,…
UseR10085
  • 7,120
  • 3
  • 24
  • 54
3
votes
0 answers

Perform nonlinear regression with nlsLM within a function in r

I want to add a modification factor to an existing equation to fit data. The original equation is defined through a function because the variable N_l is a vector of numbers and the function is selecting the largest outcome of the equation by going…
Maral Dorri
  • 468
  • 5
  • 17