regplot.confbands.fun_function(x,y,confidencelevel,CImean,PI,CIregline){ #### For a simple linear regression line, this function #### will plot the line, CI for mean response, prediction intervals, #### and a CI for the regression line. lm1_lm(y~x) plot(x,y,ylim=c(min(y),(max(y)+.2*max(y)))) abline(lm1$coefficients) #### calculation of components of intervals #### n_length(y) sx2_(var(x)) shat_summary(lm1)$sigma s2hat_shat^2 SEmuhat_shat*sqrt(1/n+ ((x-mean(x))^2)/((n-1)*sx2)) SEpred_sqrt(s2hat+SEmuhat^2) t.quantile_qt(confidencelevel,lm1$df.residual) #### if (CImean==T){ mean.up_lm1$fitted+t.quantile*SEmuhat mean.down_lm1$fitted-t.quantile*SEmuhat lines(x,mean.up,lty=2) lines(x,mean.down,lty=2) } if (PI==T){ PI.up_lm1$fitted+t.quantile*SEpred PI.down_lm1$fitted-t.quantile*SEpred lines(x,PI.up,lty=3) lines(x,PI.down,lty=3) } if (CIregline==T){ HW_sqrt(2*qf(confidencelevel,n-lm1$df.residual,lm1$df.residual))*SEmuhat CIreg.up_lm1$fitted+HW CIreg.down_lm1$fitted-HW lines(x,CIreg.up,lty=4) lines(x,CIreg.down,lty=4) } choices_c(CImean,PI,CIregline) line.type_c(2,3,4) names.line_c("CI for mean resp.","Prediction Int.","CI for reg. line") legend(max(x)-.2*max(x),max(y)+.2*max(y),legend=names.line[choices],lty=line.type[choices]) }