0

I have a regression that looks like this:

fit <- nls (data$y ~ (data$v1 + data$v2 + data$v3 + data$v4) *(1 + exp(theta1 - theta2*data$v5 - theta3*data$v6)^-1),
       data = data,
       start = c (theta1 =0, theta2= 0, theta3= 0))

summary(fit)

In the first part the variables follow a linear relationship but they are weighted by a non-linear expression (second part). The model runs, but the summary only shows the information for the parameters on the non-linear part (theta1, theta2, and theta3). Does anybody know how to get the information about the intercept and the coefficient of the non-linear part? Or my formulation wrong and R is not estimating these coefficients?

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
  • 3
    You don't need the `data$` part in front of every variable. – Roman Luštrik Sep 04 '14 at 20:51
  • 3
    But you do need explicit variable coefficients for each of the values in your data. Unlike with `lm()`, `nls()` does not assume that you want to estimate a coefficient for each variable in your model. So you'd want it to look like `alpha1*v1 + alpha2*v2 + alpha3*v3 + alpha4*v4` or something like that. It also would have been nice to make this a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) by including sample data so it's clear what is contained in `data` and what is not. – MrFlick Sep 04 '14 at 20:53

1 Answers1

3

While lm will assume you want coefficients in front of every data column, nls makes no such assumption; you must tell it.

fit <- nls (y ~ (b0 + b1 * v1 + b2 * v2 + b3 * v3 + b4 * v4) *
                (1 + exp(theta1 - theta2 * v5 - theta3 * v6) ^ -1),
       data = data,
       start = c (b0 = 0, b1 = 1, b2 = 2, b3 = 3, b4 = 4,
                  theta1 =0, theta2= 0, theta3= 0))

You may want to initially fit the lm to the first part, and then use the estimated coefficients as the starting values in nls.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
  • 1
    although note that `nlme::gnls` has a `params` argument that allows you to specify linear sub-models for some of the parameters, e.g. `gnls( y ~ B * (1 + exp(T)^(-1)), params=list(B~v1+v2+v3+v4, T ~ v5+v6), ...)` – Ben Bolker Sep 04 '14 at 21:09