Re: [R] non-linear regression and root finding

2023-11-07 Thread Ivan Krylov
On Mon, 6 Nov 2023 14:55:39 -0500 J C Nash wrote: > However, I'm wondering if this approach is worth writing up, at least > as a vignette or blog post. It does need a shorter example and some > explanation of the "why" and some testing perhaps. Do you mean using this problem as a basis to

Re: [R] non-linear regression and root finding

2023-11-06 Thread Berwin A Turlach
G'day Troels, On Tue, 7 Nov 2023 07:14:02 +0100 Troels Ring wrote: > Be as it may, I wonder if not your method might work if only we KNOW > that pK1 is either positive OR negative, in which case we have pK1 = > -exp(theta1)? If pK1 can be either negative or positive (or 0 :-) ), and it is just

Re: [R] non-linear regression and root finding

2023-11-06 Thread Troels Ring
Thanks a lot, Berwin. Unfortunately, pK1 may well be negative and as I understand the literature it may be poorly defined as such, and also seems to be at a boundary, since when lower is set to say rep(-4,3) pK1 is returned as -4 while pK2 and pK3 are undisturbed. Perhaps the point is that pK1

Re: [R] non-linear regression and root finding

2023-11-06 Thread Berwin A Turlach
G'day Troels, On Mon, 6 Nov 2023 20:43:10 +0100 Troels Ring wrote: > Thanks a lot! This was amazing. I'm not sure I see how the conditiion > pK1 < pK2 < pK3 is enforced? One way of enforcing such constraints (well, in finite computer arithemtic only "<=" can be enforced) is to rewrite the

Re: [R] non-linear regression and root finding

2023-11-06 Thread J C Nash
I won't send to list, but just to the two of you, as I don't have anything to add at this time. However, I'm wondering if this approach is worth writing up, at least as a vignette or blog post. It does need a shorter example and some explanation of the "why" and some testing perhaps. If there's

Re: [R] non-linear regression and root finding

2023-11-06 Thread Troels Ring
Thanks a lot! This was amazing. I'm not sure I see how the conditiion pK1 < pK2 < pK3 is enforced? - it comes from the derivation via generalized Henderson-Hasselbalch but perhaps it is not really necessary. Anyway, the use of Vectorize did the trick! Best wishes Troels Den 06-11-2023 kl.

Re: [R] non-linear regression and root finding

2023-11-06 Thread J C Nash
Your script is missing something (in particular kw). I presume you are trying to estimate the pK values. You may have more success with package nlsr than nls(). nlsr::nlxb() tries to get the Jacobian of the model specified by a formula and do so by applying symbolic or automatic differentiation.

Re: [R] non-linear regression and root finding

2023-11-06 Thread Ivan Krylov
В Mon, 6 Nov 2023 17:53:49 +0100 Troels Ring пишет: > Hence I wonder if I could somehow have non linear regression to find > the 3 pK values. Below is HEPESFUNC which delivers charge in the > fluid for known pKs, HEPTOT and SID. Is it possible to have > root-finding in the formula with nls?

[R] non-linear regression and root finding

2023-11-06 Thread Troels Ring
Dear friends - I have a function for the charge in a fluid (water) buffered with HEPES and otherwise only containing Na and Cl so that [Na] - [Cl] = SID (strong ion difference) goes from -1 mM to 1 mM. With known SID and total HEPES concentration I can calculate accurately the pH if I know 3

Re: [R] Non-Linear Regression Help

2017-05-10 Thread David Stevens
I have a fair bit of experience with both nls and rating curves. This is not a nls() problem, this is a model problem. The power law rating curve favored by hydrologists would not apply to your data as it's based on the idea that a log-log plot of discharge vs. stage, or state+a in your case

Re: [R] Non-Linear Regression Help

2017-05-05 Thread J C Nash
If you insist on using nls() for anything that you don't understand extremely well, you will end up with frustration. nls() uses the same method K F Gauss used (with good understanding of the details) over 200 years ago. The Gauss-Newton approach inside works very well and efficiently for

Re: [R] Non-Linear Regression Help

2017-05-05 Thread PIKAL Petr
nal Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Zachary > Shadomy > Sent: Friday, May 5, 2017 12:58 AM > To: r-help@r-project.org > Subject: [R] Non-Linear Regression Help > > I am having some errors come up in my first section of code. I hav

[R] Non-Linear Regression Help

2017-05-04 Thread Zachary Shadomy
I am having some errors come up in my first section of code. I have no issue in plotting the points. Is there an easier method for creating a non-linear regression using C*(x+a)^n. The .txt file is named stage_discharge with the two variables being stage and discharge. The data is a relatively

Re: [R] Non linear regression - Von Bertalanffy Growth Function - "singular gradient matrix at initial parameter estimates"

2015-09-08 Thread Xochitl CORMON
Thank you for the tip. Indeed, nlxb in nlmrt works and results are not crazy. I would like however to assess goodness-of-fit (gof) and ultimately to compare it with gof from linear regression (fitted with same variables). Before I used AICc to compare the nls() and lm() fit, however I get

Re: [R] Non linear regression - Von Bertalanffy Growth Function - singular gradient matrix at initial parameter estimates

2015-08-19 Thread ProfJCNash
Packages nlmrt or minpack.lm use a Marquardt method. minpack.lm won't proceed if the Jacobian singularity is at the starting point as far as I'm aware, but nlxb in nlmrt can sometimes get going. It has a policy that is aggressive in trying to improve the sum of squares, so will use more effort

[R] Non linear regression - Von Bertalanffy Growth Function - singular gradient matrix at initial parameter estimates

2015-08-18 Thread Xochitl CORMON
Dear all, I am trying to estimate VBGF parameters K and Linf using non linear regression and nls(). First I used a classic approach where I estimate both parameters together as below with alkdyr being a subset per year of my age-length-key database and running in a loop. vbgf.par -

Re: [R] Non linear regression - Von Bertalanffy Growth Function - singular gradient matrix at initial parameter estimates

2015-08-18 Thread Bert Gunter
These appear to be primarily statistics/nonlinear optimization issues that are off topic here, which is about R programming. Post on a statistics list like stats.stackexchange.com instead. Cheers, Bert Bert Gunter Data is not information. Information is not knowledge. And knowledge is

[R] Non-linear regression analysis in R‏

2012-12-19 Thread Yann Labou
Hey all, I'm trying to fit a non-linear model y ~ a * constant ^ b * x ^ c and estimates the paramaters a, b and c. Using the nls function, I'm getting following error message: Error in nlsModel(formula, mf, start, wts) : singular gradient matrix at initial parameter estimates If I

Re: [R] Non-linear regression analysis in R

2012-12-19 Thread Jeremy Miles
Could you provide the code that you're running, so we can see what you're trying to do? Even better would be a repeatable example. Jeremy On 19 December 2012 09:42, Yann Labou yann.la...@outlook.com wrote: Hey all, I'm trying to fit a non-linear model y ~ a * constant ^ b * x ^ c and

Re: [R] Non-linear regression analysis in R

2012-12-19 Thread Bert Gunter
Jeremy: Don't be silly. The model is overdetermined -- a and b tradeoff with each other. e.g. for any solution (a,b), (a/k^m,b+m) for any m is also a solution, where k = const (assuming I have correctly interpreted the model, of course). -- Bert On Wed, Dec 19, 2012 at 11:59 AM, Jeremy Miles

Re: [R] Non linear regression with complex equation

2012-02-28 Thread jeff_hawkes
Apologies for the phrasing of the question. I've sorted the problem (thanks Bert Gunter) by using the curly brackets {} as below (using a simplified version of my real model). I hope this helps someone else! Jeff --- data Alpha ip X 1 0.7106967

[R] Non linear regression with complex equation

2012-02-27 Thread jeff_hawkes
Hi all, Is it possible to model a function where the unknown parameter appears both in the fitted equation AND in the determination of other parameters? E.g. y = a^2 + b/2 + k where a = 2/k and b = k^2 and the model needs to determine k? I know this is a very simple equation (its just an

Re: [R] Non linear regression with complex equation

2012-02-27 Thread Rolf Turner
Your question is (completely) ill-posed. What is your actual model? What you have said makes no sense at all as it stands. (Minimal self-contained example .) cheers, Rolf Turner On 28/02/12 09:25, jeff_hawkes wrote: Hi all, Is it possible to model a function where the

Re: [R] Non-linear Regression best-fit line

2011-06-18 Thread Dennis Murphy
Hi: Perhaps the self-starting functions may be helpful. See ?selfStart. There are self-starting functions for both the logistic and Gompertz models (SSlogis and SSgompertz, respectively). Go through the examples to see how they work. HTH, Dennis On Fri, Jun 17, 2011 at 2:14 PM, Sean Bignami

Re: [R] Non-linear Regression best-fit line

2011-06-18 Thread peter dalgaard
On Jun 17, 2011, at 23:14 , Sean Bignami wrote: I am trying to fit a curve to a cumulative mortality curve (logistic) where y is the cumulative proportion of mortalities, and t is the time in hours (see below). Asym. at 0 and 1 y [1] 0. 0.04853859 0.08303777 0.15201970 0.40995074

[R] Non-linear Regression best-fit line

2011-06-17 Thread Sean Bignami
I am trying to fit a curve to a cumulative mortality curve (logistic) where y is the cumulative proportion of mortalities, and t is the time in hours (see below). Asym. at 0 and 1 y [1] 0. 0.04853859 0.08303777 0.15201970 0.40995074 0.46444992 0.62862069 0.95885057 1. [10]

Re: [R] Non linear Regression: singular gradient matrix at initial parameter estimates

2011-04-12 Thread Peter Ehlers
On 2011-04-11 13:29, Felix Nensa wrote: Hi, I am using nls to fit a non linear function to some data but R keeps giving me singular gradient matrix at initial parameter estimates errors. For testing purposes I am doing this: ### R code ### x- 0:140 y- 200 / (1 + exp(17 - x)/2) * exp(-0.02*x)

Re: [R] Non linear Regression: singular gradient matrix at initial parameter estimates

2011-04-12 Thread Felix Nensa
Hi Peter, thank you for your reply. Now I see, that P3 is indeed redundand. But with the simplified model... fit = nls(yeps ~ p1 / (1 + exp(p2 - x)) * exp(p4 * x)) ...nls still produces the same error. Any ideas? Felix 2011/4/12 Peter Ehlers ehl...@ucalgary.ca On 2011-04-11 13:29, Felix

Re: [R] Non linear Regression: singular gradient matrix at initial parameter estimates

2011-04-12 Thread Mario Valle
Use a more realistic starting point instead of the default one: fit - nls(yeps ~ p1 / (1 + exp(p2 - x)) * exp(p4 * x), start=list(p1=410,p2=18,p4=-.03)) This works for me: fit Nonlinear regression model model: yeps ~ p1/(1 + exp(p2 - x)) * exp(p4 * x) data: parent.frame() p1

Re: [R] Non linear Regression: singular gradient matrix at initial parameter estimates

2011-04-12 Thread Felix Nensa
Hi Mario, yes works great. Thanks! 2011/4/12 Mario Valle mva...@cscs.ch Use a more realistic starting point instead of the default one: fit - nls(yeps ~ p1 / (1 + exp(p2 - x)) * exp(p4 * x), start=list(p1=410,p2=18,p4=-.03)) This works for me: fit Nonlinear regression model model:

[R] Non linear Regression: singular gradient matrix at initial parameter estimates

2011-04-11 Thread Felix Nensa
Hi, I am using nls to fit a non linear function to some data but R keeps giving me singular gradient matrix at initial parameter estimates errors. For testing purposes I am doing this: ### R code ### x - 0:140 y - 200 / (1 + exp(17 - x)/2) * exp(-0.02*x) # creating 'perfect' samples with

Re: [R] non-linear regression for 3D data

2010-08-15 Thread szisziszilvi
Thanks a lot, this I(xx^2) ... worked. I guess, I should learn more abot the function poly itself. (so will I... :) ) Thanks again! -- View this message in context: http://r.789695.n4.nabble.com/non-linear-regression-for-3D-data-tp2320982p2325911.html Sent from the R help mailing list archive

Re: [R] non-linear regression for 3D data

2010-08-12 Thread szisziszilvi
I've tried lm, but something is wrong. I've made a test dataset of 599 data points, my original equation is zz = 1 +0.5*xx -3.2*xx*xx -1*yy +4.2*yy*yy but the R gives this result: --- mp - read.csv(file=sample.csv,sep=;,header=TRUE) lm(zz ~

Re: [R] non-linear regression for 3D data

2010-08-12 Thread szisziszilvi
right. How does it come that if I devide the result vector with 10*interception, I get a much better result? zz2 - 25.86 -2239.86*mp$xx -595.01*mp$xx*mp$xx + 2875.54*mp$yy + 776.84*mp$yy*mp$yy mp$zz2 - zz2 library(lattice) cloud(zz2/258.6 + zz ~ xx * yy, data=mp) looks quite pretty.

Re: [R] non-linear regression for 3D data

2010-08-12 Thread Duncan Murdoch
On 12/08/2010 10:35 AM, szisziszilvi wrote: I've tried lm, but something is wrong. I've made a test dataset of 599 data points, my original equation is zz = 1 +0.5*xx -3.2*xx*xx -1*yy +4.2*yy*yy but the R gives this result: --- mp -

[R] non-linear regression for 3D data

2010-08-11 Thread szisziszilvi
Hello! Is there a simplier way in R to get a nonlinear regression (like nls) for a surface? I have 3D data, and it is definitely not a linear surface with which it would fit the best. Rather sg like z = a + f(x) + g(y) where probably both f and g are polinomes (hopefully quadratic). Szilvia --

Re: [R] non-linear regression for 3D data

2010-08-11 Thread Duncan Murdoch
On 11/08/2010 6:15 AM, szisziszilvi wrote: Hello! Is there a simplier way in R to get a nonlinear regression (like nls) for a surface? I have 3D data, and it is definitely not a linear surface with which it would fit the best. Rather sg like z = a + f(x) + g(y) where probably both f and g are

Re: [R] non-linear regression for 3D data

2010-08-11 Thread szisziszilvi
oh, god, please don't tell anybody... -- View this message in context: http://r.789695.n4.nabble.com/non-linear-regression-for-3D-data-tp2320982p2321082.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing

Re: [R] Non-linear regression

2010-02-07 Thread David Winsemius
It appears my suspicions about this being homework were unfounded. Given the additional problems with excess zeroes, you may want to examine the extremely informative material on analysis of such problems written by Zeileis, Kleiber and Jackman: (easily found in case you have misplaced it,

[R] Non-linear regression

2010-02-06 Thread kupz
So I have a data set I would like to model using a non-linear method. I know it should be an exponential decay. However I know what the first derivative of the equation should be at two points, x=0 and x=100. Is there anyway to establish this when inputing the model or how would one go about this

Re: [R] Non-linear regression

2010-02-06 Thread David Winsemius
On Feb 6, 2010, at 10:33 PM, kupz wrote: So I have a data set I would like to model using a non-linear method. I know it should be an exponential decay. However I know what the first derivative of the equation should be at two points, x=0 and x=100. Is there anyway to establish this

Re: [R] Non-linear regression

2010-02-06 Thread kupz
Agreed, it would be simple to propose the relationship, however the regression is necessary to model the data properly. Unfortunately a simple decay based on those two points does not have the proper shape necessary. This is due to an extreme amount of zero inflation with this fisheries data.

Re: [R] non-linear regression

2009-12-11 Thread Alane
-project.org Sent: Thursday, December 10, 2009 9:55 PM Subject: Re: [R] non-linear regression You did not provide the data or a way of generating it. I would guess that Excel finds the same solution (the same residual sum-of squares) as nls but that it uses a weak convergence criterion and/or does

Re: [R] non-linear regression

2009-12-11 Thread Katharine Mullen
=list(A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,K=0)) HP matplot(cbind(log(fitted(HP)), log(tx.br)),type=l) - Original Message - From: Katharine Mullen k...@few.vu.nl To: AneSR citb...@terra.com.br Cc: r-help@r-project.org Sent: Thursday, December 10, 2009 9:55 PM Subject: Re: [R] non-linear

[R] non-linear regression

2009-12-10 Thread AneSR
I have a non-linear regression with 8 parameters to solve however it does not converge ... easily solves the excel ... including the initial estimates used in the R were found in the excel ... Another question is how to establish the increments of R by the parameters in the search ..

Re: [R] non-linear regression

2009-12-10 Thread Katharine Mullen
You did not provide the data or a way of generating it. I would guess that Excel finds the same solution (the same residual sum-of squares) as nls but that it uses a weak convergence criterion and/or does not give you information regarding why it terminates. Regarding the step size: you can set

Re: [R] Non-Linear Regression with two Predictors

2009-07-27 Thread Berlinerfee
is always 0 and so the gradient is singular. Why do you need delta at all? --- On Mon, 27/7/09, Berlinerfee berliner...@yahoo.de wrote: From: Berlinerfee berliner...@yahoo.de Subject: [R] Non-Linear Regression with two Predictors To: r-h...@stat.math.ethz.ch Received: Monday, 27 July, 2009

[R] Non-Linear Regression with two Predictors

2009-07-26 Thread Berlinerfee
Hello there, I am using nls the first time for a non-linear regression with a logistic growth function: startparam - c(alpha=3e+07,beta=4000,gamma=2) fit - nls(dataset$V2~(( alpha / ( 1 + exp( beta - gamma * dataset$V1 ) ) ) ),data=dataset,start=startparam) Everything works fine and i get

[R] Non-linear regression/Quantile regression

2009-06-09 Thread despaired
Hi, I'm relatively new to R and need to do a quantile regression. Linear quantile regression works, but for my data I need some quadratic function. So I guess, I have to use a nonlinear quantile regression. I tried the example on the help page for nlrq with my data and it worked. But the example

Re: [R] Non-linear regression/Quantile regression

2009-06-09 Thread Gabor Grothendieck
Those are linear in the coefficients so try these: library(quantreg) rq1 - rq(demand ~ Time + I(Time^2), data = BOD, tau= 1:3/4); rq1 # or rq2 - rq(demand ~ poly(Time, 2), data = BOD, tau = 1:3/4); rq2 On Tue, Jun 9, 2009 at 10:55 AM, despairedmeyfa...@uni-potsdam.de wrote: Hi, I'm

Re: [R] Non-linear regression/Quantile regression

2009-06-09 Thread despaired
Hi, thanks, it works :-) But where is the difference between demand ~ Time + I(Time^2) and demand ~ poly(Time, 2) ? Or: How do I have to interpret the results? (I get different results for the two methods) Thank you again! Gabor Grothendieck wrote: Those are linear in the coefficients so

Re: [R] Non-linear regression/Quantile regression

2009-06-09 Thread Ravi Varadhan
: Tuesday, June 09, 2009 11:59 AM To: r-help@r-project.org Subject: Re: [R] Non-linear regression/Quantile regression Hi, thanks, it works :-) But where is the difference between demand ~ Time + I(Time^2) and demand ~ poly(Time, 2) ? Or: How do I have to interpret the results? (I get different

Re: [R] Non-linear regression/Quantile regression

2009-06-09 Thread Greg Snow
-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of despaired Sent: Tuesday, June 09, 2009 9:59 AM To: r-help@r-project.org Subject: Re: [R] Non-linear regression/Quantile regression Hi, thanks, it works :-) But where is the difference between demand ~ Time + I(Time^2) and demand

Re: [R] Non-linear regression/Quantile regression

2009-06-09 Thread Gabor Grothendieck
. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of despaired Sent: Tuesday, June 09, 2009 9:59 AM To: r-help@r-project.org Subject: Re: [R] Non-linear

Re: [R] Non-linear regression with latent variable

2009-05-21 Thread spencerg
If you have the RSiteSearch package installed, you can do the following: library(RSiteSearch) nrow(nll - RSiteSearch.function(nonlinear regression with latent)) HTML(nll) This just produced 8 hits for me. If this doesn't solve your problem, you might try other search terms. If

[R] Non-linear regression with latent variable

2009-05-20 Thread Samiul Hasan
Hi Can anyone please suggest me a package where I can estimate a non-linear regression model? One of the independent variables is latent or unobserved. I have an indicator variable for this unobserved variable; however the relationship is known to be non-linear also. In terms of equations my

Re: [R] non linear regression with nls

2009-02-06 Thread lauramorg...@bluewin.ch
Thank you! It worked perfectly, also for the other variables! Messaggio originale Da: r...@life.ku.dk Data: 06.02.2009 13.29 A: lauramorg...@bluewin.ch Oggetto: Re: [R] non linear regression with nls Hi Laura, I think you have to make a list formulas: formList - list(NT.N ~ fz1

Re: [R] non linear regression with nls

2009-02-05 Thread lauramorg...@bluewin.ch
A: lauramorg...@bluewin.ch Oggetto: Re: [R] non linear regression with nls Hi Laura, I've the following suggestion for you using several lists and a for loop: fz1-function(Portata, a, b){a+b/Portata} fz2-function(Portata, a, b){a*exp(b*Portata)} fz3-function(Portata, a, b, d, e){a+b/Portata+d*(Portata^e

Re: [R] non linear regression with nls

2009-02-05 Thread lauramorg...@bluewin.ch
can someone specify the groups/subset? Thanks a lot! Laura Messaggio originale Da: kfr...@wisc.edu Data: 03.02.2009 15.36 A: lauramorg...@bluewin.ch Oggetto: Re: [R] non linear regression with nls Hi, Laura- You might have a look at ?nlsList(). Ken - Original Message - From

[R] non linear regression with nls

2009-02-03 Thread lauramorg...@bluewin.ch
Hello, I'm a beginner with R and it's the first time I'm using the R-help list... I hope I'm in the right place, if not: Sorry!! I need to do non linear regressions on a data set which columns are: river.namePortata PTG.P PO4.P NT.NNH4.N NO3.N BOD5SiO2 I need to predict

[R] non-linear regression problem

2008-08-14 Thread Sascha Benz
I need to do a non-linear regression in the form of Y = a0 + a1 * arctan(a2 * x) + error. A data sample (X,Y) is available, but I can't remember how to run this sort of regression through R so that I get a value for a0, a1 and a2. Can someone please give me a hint? Thank you in advance.

[R] Non linear regression with 2 explanatory variables

2008-01-16 Thread Janice Kielbassa
Hello! I want to do a non-linear regression with 2 explanatory variables (something like : length ~ a * time * exp( b* temperature)), having a data set (length, time, temperature). Which function could I use (I tried nls but I think it doesn't work) Thanks a lot! Janice

Re: [R] Non linear regression with 2 explanatory variables

2008-01-16 Thread Gavin Simpson
hits=-2.6 tests=BAYES_00 X-USF-Spam-Flag: NO On Wed, 2008-01-16 at 11:02 +0100, Janice Kielbassa wrote: Hello! I want to do a non-linear regression with 2 explanatory variables (something like : length ~ a * time * exp( b* temperature)), having a data set (length, time, temperature).

Re: [R] Non linear regression with 2 explanatory variables

2008-01-16 Thread Roland Rau
Gavin Simpson wrote: hits=-2.6 tests=BAYES_00 X-USF-Spam-Flag: NO On Wed, 2008-01-16 at 11:02 +0100, Janice Kielbassa wrote: Hello! I want to do a non-linear regression with 2 explanatory variables (something like : length ~ a * time * exp( b* temperature)), having a data set (length,

Re: [R] Non linear regression with 2 explanatory variables

2008-01-16 Thread Rolf Turner
I have never had much success in using nls(). If you scan the archives you will find one or two postings from me on this topic. I have received no useful responses to these postings. I have found that anything that I tried (and failed) to do using nls() could be done quite easily using

Re: [R] Non linear regression with 2 explanatory variables

2008-01-16 Thread Katharine Mullen
Dear Rolf, One thing that sometimes makes nls easier to apply is using the 'formula' argument like you would use the 'fn' argument of optim. That is, if you have a residual function that has arguments x, y, a, b and you need to optimize a and b, you would make a call like