# Re: [R] curve fitting problem

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Mon, 24 Dec 2007 10:02:48 -0500

Your model is singular. Varying m and log(l) have the same effect: log(ir) = log(k) + m * log(l) * ox

Also with plinear you don't specify the linear coefficients but rather an X matrix whose coefficients represent them: If we use this model instead:

ir = k * exp(m * ox)

Then:

> mod0 <- lm(log(ir) ~ ox)
> mod0

Call:
lm(formula = log(ir) ~ ox)

Coefficients:

```(Intercept)           ox
2.199743     0.003835

```

> nls(ir ~ exp(m * ox), start = list(m = coef(mod0)), algorithm = "plinear")
Nonlinear regression model
model: ir ~ exp(m * ox)
data: parent.frame()

m .lin
0.003991 9.091758
residual sum-of-squares: 0.3551

Number of iterations to convergence: 3
Achieved convergence tolerance: 5.289e-07

On Dec 24, 2007 9:04 AM, <pieterprovoost_at_gmail.com> wrote:
> I'm trying to fit a function y=k*l^(m*x) to some data points, with reasonable starting value estimates (I think). I keep getting "singular matrix 'a' in solve".
>
> This is the code:
>
> ox <- c(-600,-300,-200,1,100,200)
> ir <- c(1,2.5,4,9,14,20)
> model <- nls(ir ~ k*l^(m*ox),start=list(k=10,l=3,m=0.004),algorithm="plinear")
> summary(model)
> plot(ox,ir)
> testox <- seq(-600,200,length=100)
> k <- 10
> l <- 3
> m <- 0.004
> testir <- k*l^(m*testox)
> lines(testox,testir)
>
> Any thoughts?
> Thanks!
>
> --
> This message was sent on behalf of pieterprovoost_at_gmail.com at openSubscriber.com
> http://www.opensubscriber.com/messages/r-help@stat.math.ethz.ch/topic.html
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help