Se <- scan() 6.23 140.16 6.79 133.32 7.92 135.34 8.02 127.82 9.34 108.67 10.00 146.22 10.57 131.18 11.04 145.51 12.36 163.24 14.53 136.55 15.28 112.63 18.68 245.07 22.08 140.48 27.55 177.93 32.83 160.73 36.04 227.60 37.74 177.69 40.00 174.23 41.23 206.30 45.47 141.31 #I figure this is an efficient way to read in two variables LiverSe <- Se[seq(1,length(Se),by=2)] ToothSe <- Se[seq(2,length(Se),by=2)] #Here's a better way shared by Zichen Ma Se <- scan(what=list(liver=0,tooth=0)) #data follows... LiverSe=Se$liver ToothSe=Se$tooth log.LiverSe <- log(LiverSe) log.ToothSe <- log(ToothSe) WhaleSe <- data.frame(cbind(LiverSe,ToothSe,log.LiverSe,log.ToothSe)) #Regression, Loess and penalized splines plot(LiverSe,ToothSe,data=WhaleSe,xlab="Tooth Se (ng/g)",ylab="Liver Se (mcg/g)") #Two lines of code may be better than one for the loess curve lines(WhaleSe$LiverSe,predict(loess(ToothSe ~ LiverSe,data=WhaleSe)),col="red",lwd=2) abline(lm(ToothSe ~ LiverSe),col="green",lwd=2) #Load mgcv package first lines(WhaleSe$LiverSe,predict(gam(ToothSe ~ s(LiverSe,bs="ps"),data=WhaleSe)),col="blue",lwd=2) legend(10,220,c("Penalized B Spline","Regression","Loess"),lwd=c(3,3,3),col=c("blue","green","red"),cex=.8) #Log both sides plot(log.LiverSe,log.ToothSe,data=WhaleSe,xlab="Tooth log(Se)",ylab="Liver log(Se)") lines(WhaleSe$log.LiverSe,predict(loess(log.ToothSe ~ log.LiverSe,data=WhaleSe)),col="red",lwd=2) abline(lm(log.ToothSe ~ log.LiverSe),col="green",lwd=2) #Load mgcv package first lines(WhaleSe$log.LiverSe,predict(gam(log.ToothSe ~ s(LiverSe,bs="ps"),data=WhaleSe)),col="blue",lwd=2) legend(2.0,5.3,c("Penalized B Spline","Regression","Loess"),lwd=c(3,3,3),col=c("blue","green","red"),cex=.8) WhaleSe.lm <- lm(LiverSe ~ ToothSe, data=WhaleSe) summary(WhaleSe.lm)