0
votes

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?

1
You don't need the data$ part in front of every variable.Roman Luštrik
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 by including sample data so it's clear what is contained in data and what is not.MrFlick

1 Answers

3
votes

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.