lmconf<-function(formula, data, ...){ mformula<-as.formula(formula) #create variables predictor and response assign( "predictor", data[[as.character(mformula[[3]])]] ) assign( "response", data[[as.character(mformula[[2]])]] ) lm.can<-lm(response~predictor) #lm.can<-lm(data[[as.character(mformula[[2]])]]~data[[as.character(mformula[[3]])]]) print(anova(lm.can)) print(summary(lm.can)) new.range<-data.frame("predictor"=seq(min(predictor), max(predictor), length=100)) fit<-predict(lm.can, newdata=new.range, se.fit=T) #plotting xmin<-min(predictor, new.range$predictor) ymin<-min(response, fit$fit-2*fit$se.fit) xmax<-max(predictor, new.range$predictor) ymax<-max(response, fit$fit+2*fit$se.fit) plot(response~predictor, xlab=as.character(mformula[[3]]), ylab=as.character(mformula[[2]]), xlim=c(xmin,xmax), ylim=c(ymin,ymax)) lines(new.range$predictor, fit$fit) lines(new.range$predictor, fit$fit-2*fit$se.fit, lty=2) lines(new.range$predictor, fit$fit+2*fit$se.fit, lty=2) return(lm.can) }