# R CMD BATCH mc_asy.R mc_asy.out postscript(file="xyplot_asy.eps",append=F,print.it=F) make.data <- function( b, N, sseed=NULL) { if (!is.null(sseed)) set.seed(sseed) x <- rnorm(N) e <- rnorm(N,0,5) xb <- b[1] + b[2]* x y <- xb + e dta <- as.data.frame(cbind( y=y, x=x, e=e)) return(dta) } ## set some parameters b <- c(1,3) ## number of cases in simulated data; choose values to put in here Nvec <- c(n1, n2, n3, n4, n5, n6) ## set mfrow paramater to produce multiple plots on same page for ## purposes of comparison par(mfrow=c(3,2)) for(i in 1:nrow(as.matrix(Nvec))){ dta <- make.data( b, Nvec[i]) Y <- dta$y X <- dta$x xyreg<-lm(Y~X) ## plot the data points with limits on X and Y axes plot(X,Y,xlim=c(-5,5),ylim=c(-12,12)) ## add the true regression line to the plot abline(b,lty=2) ## add the estimated regression line to the plot abline(xyreg) }