# pdf("F:\\sta4210\\CH13TA01.pdf") sev_inj <- read.table("http://www.stat.ufl.edu/~winner/sta4210/data/CH13TA01.txt", header=F, col.names=c("prognosis","days")) attach(sev_inj) ### 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])) (g1.lm <- si.mod0$coef[2]) 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) vcov(si.mod1) plot(days,prognosis,xlab="days",ylab="prognosis") days1 <- 0:70 lines(days1,predict(si.mod1,list(days=days1))) # dev.off()