> ### Fit the transformed linear model for starting values: > ### Y = g0*exp(g1*X) => Y' = ln(Y) =ln(g0) + (g1*X) =g0' + (g1'*X') > ### where g0 = exp(g0') g1=g1' X=X' > > si.mod0 <- lm(log(prognosis) ~ days) # R uses log(*) for ln(*) > > (g0.lm <- exp(si.mod0$coef[1])) (Intercept) 56.66512 > (g1.lm <- si.mod0$coef[2]) days -0.03797418 > > g0.lm <- g0.lm[[1]] # [[1]] takes coefficent, not label (Intercept) > g1.lm <- g1.lm[[1]] # [[1]] takes coefficient, not label (days) > > ### Use regression coefficients (transformed back) as inputs to NLS > > si.mod1 <- nls(prognosis ~ g0 * exp(g1*days), start=c(g0=g0.lm, g1=g1.lm)) > > summary(si.mod1) Formula: prognosis ~ g0 * exp(g1 * days) Parameters: Estimate Std. Error t value Pr(>|t|) g0 58.606531 1.472159 39.81 5.70e-15 *** g1 -0.039586 0.001711 -23.13 6.01e-12 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 1.951 on 13 degrees of freedom Number of iterations to convergence: 3 Achieved convergence tolerance: 8.973e-06 > vcov(si.mod1) g0 g1 g0 2.167253342 -1.781512e-03 g1 -0.001781512 2.928520e-06 > > plot(days,prognosis,xlab="days",ylab="prognosis") > > days1 <- 0:70 > > lines(days1,predict(si.mod1,list(days=days1))) >