nls

Constraints for nls coefficients

孤人 提交于 2021-02-11 15:57:47
问题 I'm trying to fit data with nls() function where the nature of data gives me bounds for one coefficient and for sum of two coefficients. Let me introduce short example to see where is the problem. I want parameter b1 to be between 0 and 1 and I want sum of parameters b1 and b2 to be between 0 and 1 as well. set.seed(123) # example where everything is OK x <- 1:200 g <- rbinom(200, 1, 0.5) y <- 3 + (0.7 + 0.2 * g) * x yeps <- y + rnorm(length(y), sd = 0.1) # both parameter b1 and sum of

Constraints for nls coefficients

三世轮回 提交于 2021-02-11 15:56:19
问题 I'm trying to fit data with nls() function where the nature of data gives me bounds for one coefficient and for sum of two coefficients. Let me introduce short example to see where is the problem. I want parameter b1 to be between 0 and 1 and I want sum of parameters b1 and b2 to be between 0 and 1 as well. set.seed(123) # example where everything is OK x <- 1:200 g <- rbinom(200, 1, 0.5) y <- 3 + (0.7 + 0.2 * g) * x yeps <- y + rnorm(length(y), sd = 0.1) # both parameter b1 and sum of

Non-linear fitting with nls() is giving me singular gradient matrix at initial parameter estimates. Why?

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-08 17:07:59
问题 This is my first attempt at fitting a non-linear model in R, so please bear with me. Problem I am trying to understand why nls() is giving me this error: Error in nlsModel(formula, mf, start, wts): singular gradient matrix at initial parameter estimates Hypotheses From what I've read from other questions here at SO it could either be because: my model is discontinuous, or my model is over-determined, or bad choice of starting parameter values So I am calling for help on how to overcome this

Non-linear fitting with nls() is giving me singular gradient matrix at initial parameter estimates. Why?

那年仲夏 提交于 2021-02-08 17:04:38
问题 This is my first attempt at fitting a non-linear model in R, so please bear with me. Problem I am trying to understand why nls() is giving me this error: Error in nlsModel(formula, mf, start, wts): singular gradient matrix at initial parameter estimates Hypotheses From what I've read from other questions here at SO it could either be because: my model is discontinuous, or my model is over-determined, or bad choice of starting parameter values So I am calling for help on how to overcome this

Non-linear fitting with nls() is giving me singular gradient matrix at initial parameter estimates. Why?

ⅰ亾dé卋堺 提交于 2021-02-08 17:03:27
问题 This is my first attempt at fitting a non-linear model in R, so please bear with me. Problem I am trying to understand why nls() is giving me this error: Error in nlsModel(formula, mf, start, wts): singular gradient matrix at initial parameter estimates Hypotheses From what I've read from other questions here at SO it could either be because: my model is discontinuous, or my model is over-determined, or bad choice of starting parameter values So I am calling for help on how to overcome this

fitting first order equation with nlme and lsoda

試著忘記壹切 提交于 2021-02-08 14:27:08
问题 I a trying to fit a first order differential model using nlme and lsoda . Here is the basic idea: I first define the function allowing to generate the solution of the differential equation: library(deSolve) ODE1 <- function(time, x, parms) {with(as.list(c(parms, x)), { import <- excfunc(time) dS <- import*k/tau - (S-yo)/tau res <- c(dS) list(res)})} solution_ODE1 = function(tau1,k1,yo1,excitation,time){ excfunc <- approxfun(time, excitation, rule = 2) parms <- c(tau = tau1, k = k1, yo = yo1,

How to calculate 95% prediction interval from nls

蓝咒 提交于 2021-02-07 09:02:33
问题 Borrowing the example data from this question, if I have the following data and I fit the following non linear model to it, how can I calculate the 95% prediction interval for my curve? library(broom) library(tidyverse) x <- seq(0, 4, 0.1) y1 <- (x * 2 / (0.2 + x)) y <- y1 + rnorm(length(y1), 0, 0.2) d <- data.frame(x, y) mymodel <- nls(y ~ v * x / (k + x), start = list(v = 1.9, k = 0.19), data = d) mymodel_aug <- augment(mymodel) ggplot(mymodel_aug, aes(x, y)) + geom_point() + geom_line(aes

Error when running nlsLM but works for nls

一个人想着一个人 提交于 2021-02-05 07:42:34
问题 I am trying to use nlsLM to fit experimental data. But for this example, I am using analytical data from another program so that I know the correct values. I am trying to use nls2 to give me starting points that I can use when using nlsLM. I was able to do this successfully with a less complex function, but it is not working with the more complicated function. I get values for nls2, but when I use nlsLM I get the error: "evaluation of fn function returns non-sensible value". , which I cannot

How to fit a data set to an specific function by trial and error or a better specific alternative in R?

Deadly 提交于 2021-01-29 20:23:10
问题 I have a data set and I want to adjust to the following function and find the parameters a and b: I tried the nonlinear least squares approach, however, I'd like to try by trial and error, using a vector with values for a, and another for b, then plot all the alternatives mixing this values to choose a better fit. library(readxl) library(ggplot2) x <- c(52.67, 46.80, 41.74, 40.45) y <- c(1.73, 1.84, 1.79, 1.45) df <- data.frame(x,y) ggplot(data = df, aes(x, y))+ geom_point()+ stat_smooth

Fit multiple Gompertz curves and skip errors in R (nlsList and SSgompertz)

China☆狼群 提交于 2021-01-28 05:11:04
问题 I'm trying to fit hundreds of gompertz-shaped curves using SSgompertz. The dataset has three columns with "x" and "y" values and a coded column to separate the data into different samples: "GROUPING". Later, the parameters will be used to determine x from a fixed point on the y-axis for all samples (fit point methods) using predict(). I managed to fit multiple polynomials to the data before feeding the parameters into predict() using this code: Parameters<-lmList(x~poly(y,3,raw=TRUE)|GROUPING