Hello, I made a function, which calculates the confidence interval and the prediction interval, but if I want to plot it, then it plots only the regressionline. Maybe somebody can help me:
conf.band <- function(x,y) { res.lsfit <- lsfit(x,y) xi <- seq(from=40, to=160, length=200) n <- length(x) MSE <- sqrt(sum(res.lsfit$residuals^2)/(n-2)) # confidence interval band <- sqrt(2*qf(0.95,2,n-2)) * MSE * sqrt(1/n+(xi-length(x))^2/(var(x)*(n-1))) uiv <- res.lsfit$coef[1] + res.lsfit$coef[2]*xi - band oiv <- res.lsfit$coef[1] + res.lsfit$coef[2]*xi + band # prediction interval band <- sqrt(2*qf(0.95,2,n-2)) * MSE * sqrt(1+1/n +(xi-mean(x))^2/(var(x)*(n-1))) uip <- res.lsfit$coef[1] + res.lsfit$coef[2]*xi - band oip <- res.lsfit$coef[1] + res.lsfit$coef[2]*xi + band # creating the graphik plot(x, y, xlab=colnames(x), ylab=colnames(y), pch=19) abline(res.lsfit, col=1) matlines(xi, cbind(uiv,oiv), col=3, lty=2, lwd=2) matlines(xi, cbind(uiv,oip), col=2, lty=3, lwd=2) } -- Mit freundlichen GrĂ¼ssen / Best Regards Soare Marcian-Alin [[alternative HTML version deleted]]
______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.