nls

nls2 treats vectored initial values as single elements, unlike nls

試著忘記壹切 提交于 2019-12-13 03:08:50
问题 I noticed that I can fit parameter vector, as below, using nls . This let's me decide the number of parameters I want to fit. As in the example below; where I am fitting y = k + a_1 x^2 + a_2 x^3 + a_3 x^3 . I can simply change the number of initial values, which change the number of co-efficients to estimate. But, this approach doesn't work with nls2 . It just treats fits the y = k + a_1 * x , three times! My questions is how to get nls2 to determine the number of parameters to fit based on

Exponential fitting with R

不羁岁月 提交于 2019-12-13 00:55:25
问题 I have a dataset like this df x y 7.3006667 -0.14383333 -0.8983333 0.02133333 2.7953333 -0.07466667 and I would like to fit an exponential function like y = a*(exp(bx)). This is what I tried and the error I get f <- function(x,a,b) {a * exp(b * x)} st <- coef(nls(log(y) ~ log(f(x, a, b)), df, start = c(a = 1, b = -1))) Error in qr.qty(QR, resid) : NA/NaN/Inf in foreign function call (arg 5) In addition: Warning messages: 1: In log(y) : NaNs produced 2: In log(y) : NaNs produced fit <- nls(y ~

NLS Function By Group

☆樱花仙子☆ 提交于 2019-12-12 23:30:18
问题 I have a dataset where I want to apply non linear least squares by group. This is a continuation to my previous question: NLS Function - Number of Iterations Exceeds max The dataset looks like this: df x y GRP 0 0 1 426 9.28 1 853 18.5 1 1279 27.8 1 1705 37.0 1 2131 46.2 1 0 0 2 450 7.28 2 800 16.5 2 1300 30.0 2 2000 40.0 2 2200 48.0 2 If I were to do this with one group it would be like this: df1<-filter(df, GRP==1) a.start <- max(df1$y) b.start <- 1e-06 control1 <- nls.control(maxiter=

Trouble when adding 3rd fitting parameter in nls

老子叫甜甜 提交于 2019-12-12 03:03:39
问题 I have some trouble with adding another fitting parameter to my formula. I'm using nlsLM for fitting functions and plyr package fitting in groups. You can see the code below. As well I understood from other questions there are many suggestions on when you obtain singular gradient matrix at initial parameter estimates you can vary the starting values or try to simplify your model by looking for redundant parameters which usually cause troubles. So, I understand that starting parameter is

nls function does not perform well

流过昼夜 提交于 2019-12-12 02:42:52
问题 I need to fit this formula y ~ 1/(pi*a*(1+((x-2.15646)/a)^2))+1/(pi*b*(1+((x-2.16355)/b)^2)) to the variables x and y x<- c(2.15011, 2.15035, 2.15060, 2.15084, 2.15109, 2.15133, 2.15157, 2.15182, 2.15206, 2.15231, 2.15255, 2.15280, 2.15304, 2.15329, 2.15353, 2.15377, 2.15402, 2.15426, 2.15451, 2.15475, 2.15500, 2.15524, 2.15549, 2.15573, 2.15597, 2.15622, 2.15646, 2.15671, 2.15695, 2.15720, 2.15744, 2.15769, 2.15793, 2.15817, 2.15842, 2.15866, 2.15891, 2.15915, 2.15940, 2.15964, 2.15989, 2

Error fitting a model in nls

隐身守侯 提交于 2019-12-12 02:36:08
问题 previous answers to similar questions have not help me to solve my problem. I am trying to fit a model y=a1*(1-exp(-a21*Age_WH40))^a3 , where a21=ln(1/a3)/a2 , and Age_WH40 goes from 1 to 40. I've plot the data and a line to get an idea of the starting values plot(MOE_WH40 ~ Age_WH40) lines(ts(8*(1-exp(log(1/3)/5*(1:40)))^3),col="red", lwd=2) fit.nlm_MOE4A.WH <- nls(MOE_WH40 ~ a*(1-exp(log(1/c)/b*Age_WH40))^b, start=list(a=10, b=6, c=2)) but even if I restrict the data to avoid dispersion I

NLS Regression in GGPlot2, Plotting y=Ax^b Trendline Error

冷暖自知 提交于 2019-12-11 16:18:47
问题 I'm attempting to fit a basic power trendline on a set of 3 data point, as you could do in Excel to mimic the y = Ax^b function. I have a very simple data set loaded into LCurve.data as follows: MDPT = {4, 10.9, 51.6} AUC = {287069.4, 272986.0, 172426.1} fm0 <- nls(log(LCurve.data$AUC) ~ log(a) + b * log(LCurve.data$MDPT), data = LCurve.data, start = list (a = 1, b =1)) ggplot(LCurve.data, aes(x=MDPT, y = AUC)) + geom_line() + geom_point() + stat_smooth(method = 'nls', formula = y ~ a * x ^ b

Use `nlsfit` within geom_smooth to add exponential line to plot

◇◆丶佛笑我妖孽 提交于 2019-12-11 08:26:26
问题 I would like to use the nlsfit from the easynls package with ggplot2 if at all possible. This is what I have done so far: Set up subset data: library('ggplot2') library('easynls') x <- seq(25,97) y <- c(0.014, 0.016, 0.015, 0.016, 0.018, 0.019, 0.023, 0.019, 0.021, 0.017, 0.018, 0.016, 0.016, 0.020, 0.018, 0.019, 0.022, 0.023, 0.027, 0.027, 0.028, 0.031, 0.029, 0.032, 0.030, 0.030, 0.030, 0.033, 0.039, 0.038, 0.039, 0.046, 0.042, 0.043, 0.050, 0.054, 0.059, 0.064, 0.062, 0.058, 0.063, 0.069,

NLS Function - Number of Iterations Exceeds max

浪子不回头ぞ 提交于 2019-12-11 07:57:49
问题 I have a dataset that looks like this: dput(testing1) structure(list(x = c(0, 426.263081392053, 852.526162784105, 1278.78924417616, 1705.05232556821, 2131.31540696026, 2557.57848835232, 2983.84156974437, 3410.10465113642, 3836.36773252847, 4262.63081392053, 4688.89389531258, 5115.15697670463, 5541.42005809668, 5967.68313948874, 6393.94622088079, 6820.20930227284, 7246.4723836649, 7672.73546505695, 8098.998546449, 8525.26162784105, 8951.52470923311, 9377.78779062516, 9804.05087201721, 10230

nls when the data is a convoluted spectra (variable number of variables)

爷,独闯天下 提交于 2019-12-11 02:56:02
问题 I have some spectrum data that looks like one of the multiplets when is plotted: http://journals.prous.com/journals/dof/19982303/html/df230301/images/keiferf3.gif How it is seen in the image, all the peaks are realy close among each other, so I would like to do some deconvolution using nls function, like it was posted before (R: Fitting Gaussian peaks to density plot data using nls), but using a Lorentzian function instead: y <- 1/(pi*a*(1+((x-x0)/a)^2)) In my case, x0 is the peak maximum