nls

R: Summarize inside an nlsLM() statement

无人久伴 提交于 2019-12-01 12:03:49
I'm using nlsLM() to make a model of a power function, but I need to summarize my data within the function call to find the appropriate coefficient and exponent. More specifically, here is what my model code looks like: Jmod = nlsLM(value~(a)*summarise(funs(mean), (MW)^b), start = list(a=100000, b = 1/3), data = mod_data, upper = c(Inf,1), lower = c(0,1/5)) where MW is the data I am trying to use to predict value . The data for MW is already grouped by month based off a variable called datetime , so I would like to take the monthly average of MW^b where b is found by the nlsLM() statement. I

R: Summarize inside an nlsLM() statement

戏子无情 提交于 2019-12-01 09:25:59
问题 I'm using nlsLM() to make a model of a power function, but I need to summarize my data within the function call to find the appropriate coefficient and exponent. More specifically, here is what my model code looks like: Jmod = nlsLM(value~(a)*summarise(funs(mean), (MW)^b), start = list(a=100000, b = 1/3), data = mod_data, upper = c(Inf,1), lower = c(0,1/5)) where MW is the data I am trying to use to predict value . The data for MW is already grouped by month based off a variable called

nls - convergence error

断了今生、忘了曾经 提交于 2019-12-01 06:16:40
问题 For this dataset: dat = structure(list(x = c(5L, 5L, 5L, 5L, 10L, 10L, 10L, 10L, 15L, 15L, 15L, 15L, 17L, 17L, 17L, 17L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 22L, 22L, 22L, 22L, 24L, 24L, 24L, 24L, 25L, 25L, 25L, 25L, 27L, 27L, 27L, 27L, 30L, 30L, 30L, 30L, 35L, 35L, 35L, 35L), y = c(2.2, 2.2, 1.95, 1.9, 4.1, 3.95, 3.75, 3.4, 5.15, 4.6, 4.75, 5.15, 3.7, 4.1, 3.9, 3.5, 7, 6.7, 6.7, 6.95, 4.95, 6, 6.45, 6.4, 7, 4.45, 6.15, 6.4, 7, 6.6, 6.7, 7, 4.5, 4.7, 5.75, 4.35, 5.4, 5.15, 5.7, 5.7, 0, 0,

nls troubles: Missing value or an infinity produced when evaluating the model

百般思念 提交于 2019-12-01 01:51:34
问题 I am an R newbie trying to fit plant photosynthetic light response curves (saturating, curvilinear) to a particular model accepted by experts. The goal is to get estimated coefficient values for Am, Rd, and LCP. Here is the error I keep getting: Error in numericDeriv(form[[3L]], names(ind), env) : Missing value or an infinity produced when evaluating the model I have switched around the starting values a number of times, but still no luck. Help? Thanks you in advance. Example dataset below.

Curve fitting in R using nls

青春壹個敷衍的年華 提交于 2019-11-30 20:14:38
I'm trying to fit a curve over (the tail of) the following data: [1] 1 1 1 1 1 1 2 1 2 2 3 2 1 1 4 3 2 11 6 2 16 7 17 36 [25] 27 39 41 33 42 66 92 138 189 249 665 224 309 247 641 777 671 532 749 506 315 292 281 130 [49] 137 91 40 27 34 19 1 I'm using the following function in R to accomplish this: nls(y~a x exp(-b*x^2),start=list(a=1,b=1),trace=TRUE) However, I'm getting the following error: 3650202 : 1 1 Error in numericDeriv(form[[3L]], names(ind), env) : Missing value or an infinity produced when evaluating the model When using the following, artificial values for x and y, everything works

NLS And Log-Periodic Power Law (LPPL) in R

自古美人都是妖i 提交于 2019-11-30 16:35:20
This is the most challenging thing I have done in R so far in that both nls and LPPL are fairly new to me. Below is a portion of script I have been working with. df is a data frame consisting of two columns, Date and Y, which are the closing prices for the S&P 500. I am not sure if it is relevant, but the dates start from 01-01-2003 through 12-31-2007. f <- function(pars, xx) {pars$a + pars$b*(pars$tc - xx)^pars$m * (1 + pars$c * cos(pars$omega*log(pars$tc - xx) + pars$phi))} # residual function resids <- function(p, observed, xx) {df$Y - f(p,xx)} # fit using Levenberg-Marquardt algorithm nls

R : catching errors in `nls`

主宰稳场 提交于 2019-11-30 09:59:12
I'm fitting some exponential data using nls . The code I'm using is: fit <- nls(y ~ expFit(times, A, tau, C), start = c(A=100, tau=-3, C=0)) expFit is defined as expFit <- function(t, A, tau, C) { expFit <- A*(exp(-t/tau))+C } This works well for most of my data, for which the starting parameters provided (100, -3 and 0) work well. Sometimes, though, I have data that doesn't go well with those parameters and I get errors from nls (e.g. "singular gradient" or things like that). How do I "catch" these errors? I tried to do something like fit <- NULL fit <- nls(...) if (is.null(fit)) { // Try nls

R nls singular gradient

淺唱寂寞╮ 提交于 2019-11-30 07:04:02
问题 I've tried searching the other threads on this topic but none of the fixes are working for me. I have the results of a natural experiment and I want to show the number of consecutive occurrences of an event fit an exponential distribution. My R shell is pasted below f <- function(x,a,b) {a * exp(b * x)} > x [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 [26] 26 27 > y [1] 1880 813 376 161 100 61 31 9 8 2 7 4 3 2 0 [16] 1 0 0 0 0 0 1 0 0 0 0 1 > dat2 x y 1 1 1880 2 2 813

NLS And Log-Periodic Power Law (LPPL) in R

我怕爱的太早我们不能终老 提交于 2019-11-29 23:49:08
问题 This is the most challenging thing I have done in R so far in that both nls and LPPL are fairly new to me. Below is a portion of script I have been working with. df is a data frame consisting of two columns, Date and Y, which are the closing prices for the S&P 500. I am not sure if it is relevant, but the dates start from 01-01-2003 through 12-31-2007. f <- function(pars, xx) {pars$a + pars$b*(pars$tc - xx)^pars$m * (1 + pars$c * cos(pars$omega*log(pars$tc - xx) + pars$phi))} # residual

Conditional nls

余生长醉 提交于 2019-11-29 17:28:33
I'm trying to fit the conditional nls with R 2.15.1. The same code was working fine with R 2.13 but now R 2.15.1 throws errors. x <- seq(from = 17, to = 47, by = 5) y <- c(26.2, 173.6, 233.9, 185.9, 115.4, 62.0, 21.7) Data <- data.frame(y, x) Fit <- nls(formula = y ~ ifelse(test = x <= Mu, yes = Mean <- c1*exp(-((x-Mu)/Sigma11)^2), no = Mean <- c1*exp(-((x-Mu)/Sigma12)^2)), data = Data, start = list(c1 = 240, Mu = 25, Sigma11 = 5, Sigma12 = 14), algorithm = "port", lower = list(Sigma11 = 0, Sigma12 = 0)) The error is Error in nls(formula = y ~ ifelse(test = x <= Mu, yes = Mean <- c1 * exp(-((x