# completely randomized design (CRD) y=c(1,3,4,7,15,5,57,40); x=c(1,2,4,7,10,20,40,70) group=c(rep(1,each=4),rep(2,each=4)); data=data.frame(group,x,y) plot(x,y); title('Y by X') library(car) # plot by group scatterplot(y~x|group,reg.line=F,smoother=F); title('Y by X and Group') scatterplot(y~x|group,smoother=F); title('Y by X and Group with \n regression lines') cov(data[,-1]); cor(data[-1]) by(data[-1],group,cov,use='pairwise'); by(data[-1],group,cor,use='pairwise') cor.test(x,y,data=data) cor.test(x[group==1],y[group==1],data=data);cor.test(x[group==2],y[group==2],data=data)