You should work with lists.
Code:# (1)set parameters true.intercept<-0.2 true.slope<-0.03 true.err.var<-0.09 n.iter<-1000 s.sample<-100 estimates<-matrix(NA,nrow=n.iter,ncol=2) list<-list() s.sample<-100 x<-10*runif(s.sample) for(i in 1:n.iter) { y<-true.intercept+true.slope*x+rnorm(s.sample,mean=0, sd=true.err.var) list[[i]]<-lm(y~x) } #Store p-value of coefficient. sapply(1:length(list), function(X) { summary(list[[X]])$coef[2,4] }) #Store p-value of intercept. sapply(1:length(list), function(X) { summary(list[[X]])$coef[1,4] }) #Store R squares sapply(1:length(list), function(X) { summary(list[[X]])$r.squared })





Reply With Quote

