[R] Covariates in NLS (Multiple nonlinear regression)
Dear R-users, I am trying to create a model using the NLS function, such that: Y = f(X) + q + e Where f is a nonlinear (Weibull: a*(1-exp(-b*X^c)) function of X and q is a covariate (continous variable) and e is an error term. I know that you can create multiple nonlinear regressions where x is polynomial for example, but is it possible to do this kind of thing when x is a function with unknown coefficients (a,b,c)? Ultimately, I am expecting the output to give individual regression models for each coefficient (a,b,c) with q as a covariate. I have tried the following code, and get the resultant error messages: weib.nls - nls(Y ~ (a*(1-exp(-b*X^c)))|q, + data=DATA, + start=c(a=75,b=0.05,c=0.7)) Error in nlsModel(formula, mf, start, wts) : singular gradient matrix at initial parameter estimates summary(weib.nls) weib.nls2 - nls(Y~ (a*(1-exp(-b*X^c)))+q, + data=DATA, + start=c(a=75,b=0.05,c=0.7)) Error in numericDeriv(form[[3L]], names(ind), env) : Missing value or an infinity produced when evaluating the model Many thanks in advance! Lindsay __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Covariates in NLS (Multiple nonlinear regression)
Thank you for your suggestion. Unfortunately, like most texts on the topic of nonlinear regression, examples tend to be either a) a simple regression with one predictor and one response or b) a continuous predictor and response with a categorical variable (i.e. differentiating for example two curves for two groups). I have not managed to find any examples that replicate my scenario - that I would expect the nature of the weibull curve to vary in association with a third (fourth, etc) continuous variable. I was rather hoping to find somebody that had done the same thing - is it possible? Thanks, Lindsay -Original Message- From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Sent: 25 August 2009 17:53 To: Lindsay Banin Cc: r-help@r-project.org Subject: Re: [R] Covariates in NLS (Multiple nonlinear regression) Try this: RSiteSearch(Weibull regression) On Tue, Aug 25, 2009 at 12:02 PM, Lindsay Baninl.bani...@leeds.ac.uk wrote: Dear R-users, I am trying to create a model using the NLS function, such that: Y = f(X) + q + e Where f is a nonlinear (Weibull: a*(1-exp(-b*X^c)) function of X and q is a covariate (continous variable) and e is an error term. I know that you can create multiple nonlinear regressions where x is polynomial for example, but is it possible to do this kind of thing when x is a function with unknown coefficients (a,b,c)? Ultimately, I am expecting the output to give individual regression models for each coefficient (a,b,c) with q as a covariate. I have tried the following code, and get the resultant error messages: weib.nls - nls(Y ~ (a*(1-exp(-b*X^c)))|q, + data=DATA, + start=c(a=75,b=0.05,c=0.7)) Error in nlsModel(formula, mf, start, wts) : singular gradient matrix at initial parameter estimates summary(weib.nls) weib.nls2 - nls(Y~ (a*(1-exp(-b*X^c)))+q, + data=DATA, + start=c(a=75,b=0.05,c=0.7)) Error in numericDeriv(form[[3L]], names(ind), env) : Missing value or an infinity produced when evaluating the model Many thanks in advance! Lindsay __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Comparing model fits for NLME when models are not nested
Hi all, Many thanks for your advice. Lindsay -Original Message- From: Peter Flom [mailto:peterflomconsult...@mindspring.com] Sent: 12 June 2009 11:18 To: Lindsay Banin; 'r-help@r-project.org' Subject: Re: [R] Comparing model fits for NLME when models are not nested Lindsay Banin l.bani...@leeds.ac.uk wrote Hi there, I am looking to compare nonlinear mixed effects models that have different nonlinear functions (different types of growth curve)embedded. Most of the literature I can find focuses on comparing nested models with likelihood ratios and AIC. Is there a way to compare model fits when models are not nested, i.e. when the nonlinear functions are not the same? What I like to do in these cases (and, in fact, for comparing model fits in general, even if nested) is graph the results of one vs the other, and of each vs. actual values. If the predicted values from the two models are very similar, then I can choose based on complexity or some other criterion; if they are not similar, then which is closer to the actual values? Is the difference large? Is it worth it? It's not a formal test, but I often find it illuminating. HTH Peter Peter L. Flom, PhD Statistical Consultant www DOT peterflomconsulting DOT com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Function for AIC or logLIK for nlsList object
Dear R users, Does anybody have a function to calculate logLik or AIC for nlsList objects? After receiving error messages, another user helped me ascertain that this function is not currently written into R. Many thanks Lindsay __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Comparing model fits for NLME when models are not nested
Hi there, I am looking to compare nonlinear mixed effects models that have different nonlinear functions (different types of growth curve)embedded. Most of the literature I can find focuses on comparing nested models with likelihood ratios and AIC. Is there a way to compare model fits when models are not nested, i.e. when the nonlinear functions are not the same? Many thanks in advance! Lindsay __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Error in 1:p : NA/NaN argument when running model comparisons
Hi there, I am trying to compare nonlinear least squares regression with AIC and anova. The simplest model is one nonlinear curve, and in the more complex model I have a categorical variable (producing parameter estimates for four curves). Both models run fine, but when I try to produce an AIC value for the second model I get the error: AIC(pow.nls1) [1] 114408.3 AIC(pow.nls2) Error in 1:p : NA/NaN argument And similarly, when I try to compare the models with ANOVA, I get: anova(pow.nls1, pow.nls2) Error in if (df[i] 0) { : missing value where TRUE/FALSE needed It seemed as if this could be a problem with the dataset, but I have checked thoroughly and there are no missing values etc. What do these error messages actually indicate? Many thanks in advance! Lindsay __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Error in NLME (nonlinear mixed effects model)
Hi there, I have been trying to fit an NLME to my data. My dataset has two category levels - one is a fixed effect (level1) and one is a random effect (level2), though so far I have only experimented with the highest level grouping (fixed, level1), with the following code: mod1 - nlme(H ~ a*(1-exp(-b*D^c)), data=sizes, fixed=a+b+c~factor(Loc), start=c(a=75,b=0.05,c=0.7)) This returns the error: Error in getGroups.data.frame(dataMix, eval(parse(text = paste(~1, deparse(groups[[2]]), : Invalid formula for groups Other points that it may be useful to note in diagnosing the problem are that: 1) I have tried both specifying Loc=as.factor and not specifying this. 2) I have tried other configurations of writing fixed=list(...) or fixed=c(...) and that always generates an error 3) I have not specified groupedData 4) My groups do not have equal sample sizes (unbalanced?) Look forward to hearing back! Thanks in advance, Lindsay __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] (no subject)
Subject: nls, step factor 0.000488281 reduced below 'minFactor' of 0.000976563 Hi there, I'm trying to conduct nls regression using roughly the below code: nls1 - nls(y ~ a*(1-exp(-b*x^c)), start=list(a=a1,b=b1,c=c1)) I checked my start values by plotting the relationship etc. but I kept getting an error message saying maximum iterations exceeded. I have tried changing these start values, and I heeded advice from other threads and ammended my code to include :, control = list(maxiter = 500), trace=TRUE)). Now I receive an error message saying step factor 0.000488281 reduced below 'minFactor' of 0.000976563. Any ideas? Many thanks in anticipation, LB ** Lindsay Banin School of Geography University of Leeds Leeds, LS2 9JT UK [EMAIL PROTECTED] ** __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.