[R] exponential model with decreasing

Ben Bolker bbolker at gmail.com
Tue Aug 16 17:57:53 CEST 2011


Komine <momadou <at> yahoo.fr> writes:

> I try to do an exponential model with decreasing. In my data, there is no
> data missing but there negative values. I adapted this following code whose
> the origin code comes from in this forum:
> Regress<-read.table("C:\\Users\\Regression.csv",sep=";",dec=",",header=TRUE) 
> Regress
> f <- function(x,a,b) {a * exp(b * x)} 
> x<-Regress$EWT
> y<-Regress$MSI7
> plot(y ~ x) 
> fm <- nls(y ~ f(x,a,b), data =Regress, start = c(a=1, b=1)) 
> co <- coef(fm) 
> curve(f(x, a=co[1], b=co[2]), add = TRUE)
> But in the line 7, it blocks with the following message:
> #Error in numericDeriv(form[[3L]], names(ind), env) : 
> # Missing value or an infinity produced when evaluating the model
> 1: In min (x) found no arguments to min; Inf is returned       #it is my
> translation
> 2: In max (x): no arguments to max;-Inf is returned
> -	Please where is the problem?
> -	What I can do to obtain R^2?
> - The way to verify Homoscedasticity and normality is the same for linear
> model?

  Please read the posting guide, and <http://tinyurl.com/3jgynql>
(stackoverflow reproducible example advice).  
  You may do better by using the starting values from a log-linear
regression (ignoring negative values):

m1 <- lm(log(MSI7)~EWT,data=regress,subset=MSI7>0)
fm <- nls(MSI7 ~ f(EWT,a,b), data=Regress, 
     start=c(a=coef(m1)[1],b=coef(m1)[2])

For R^2, see e.g. 
<https://stat.ethz.ch/pipermail/r-help/2002-July/023461.html>
(I googled "nls R^2" ...)



More information about the R-help mailing list