I read about using the log as an alternative for creating a linear equation so that I can extract starting values for an nls fit from the linear equation, in R; Accordingly,
For equation: Y=q/(1+bDX)^(1/b) where Y and X are my data; q,b,D are my parameters to be estimated. I created the linear model:
X<-1:45
Y <- c(35326L, 30339L, 23379L, 21877L, 18629L, 17627L, 15691L, 15435L,
14205L, 11732L, 10560L, 10592L, 9939L, 7491L, 4928L, 3427L, 8123L,
9027L, 8733L, 9599L, 8737L, 9135L, 8548L, 7279L, 8940L, 8459L,
8460L, 7700L, 6817L, 7167L, 7089L, 7091L, 7538L, 9206L, 9680L,
5876L, 7799L, 8384L, 10586L, 8623L, 7848L, 5534L, 6610L, 6539L,
6650L)
lmodel <- coef(lm(log(Y)~X+I(X^2)))
q0 <- exp(lmodel[1])
D0 <- -lmodel[2]
b0 <- lmodel[3]*2/D0^2
Start1=list(q=q0,b=b0,D=D0)
theta_hat2 <- nls(y~q*(1+b*D*x)^(-1/b),start=Start1)
This provides me the required results everytime. However, I want to fit nls to some other equations mentioned below which are rather difficult for me. If someone can help me make a linear model to fit these, I would greatly appreciate.
Equation 2:
Y=q*(-D+(b/n)*X^n here q,b,D,n are to be estimated.
Equation 3:
Y=q*exp(-(X/D)^b here q,b,D are to be estimated.
Equation 4:
Y=q*X^((-b) )*exp(D/((1-b) )*(X^(1-b)-1) here q,b,D are to be estimated.
I am attaching example dataset for this problem here:
The main problem is that equations (2) and (4) are overparameterized so regardless of optimization algorithm used there will be problems. In the case of (3) there is a syntax error and we need better starting values. Test input should be contained within the question and we have provided it in the Note at the end.
Equation (1)
x
andy
should beX
andY
. We can use theplinear
algorithm to avoid having to specify starting values for the linear parameterq
in which case starting values of 1 for the other parameters seems sufficient.Equation (2)
Equation (2) is overparameterized because if you multiply q by an arbitrary number a and at the same time divide D and b by a the right hand side is unchanged. Removing q we note that D and b enter linearly and only n is actually nonlinear so we can use the plinear algorithm to avoid initial values for the linear parameters:
Equation (3)
There is a missing right parenthesis in the formula given in the question. If we fix that then the problme is that we need better starting valus. First try it with b fixed at 1 and then use the result as starting values for the full equation. Again use
plinear
to avoid having to supply starting values for the linear parameter.Equation (4)
Equation (4) is also overparameterized so set D to 1-b in which case exp(D/(1-b)) is the constant exp(1) so:
Compare
We can plot the various solutions:
Note
Test data should be self contained in the question and since it was not provided in that form we will provide it here this time: