Datum: Mon, 15 Aug 2011 08:33:52 -0300
Von: Alexandre Camargo Martensen <acmartensen at gmail.com>
An: Johannes Radinger <JRadinger at gmx.at>
Betreff: Re: [R-sig-eco] Extracting information from lm results
Hi Johannes,
try this
results.df<-data.frame(results)
#results.df
p<-t(results.df[4,])
r<-t(results.df[5,])
mean(p)
mean(r)
HTH,
Alexandre
On Mon, Aug 15, 2011 at 8:07 AM, Johannes Radinger <JRadinger at gmx.at>
wrote:
Hello Peter,
I just found a mail list correspondence from you in R-sig-eco and
found your information and code snipped about extracting information
lm results very useful. I do have a similar challenge to perform several
lm-regression and in the end I'd like to get e.g a mean value for
or p or any other of the regression coefficients.
So far I managed to write following code example:
#Defining variables
Y=c(15,14,23,18,19,9,19,13)
X1=c(0.2,0.6,0.45,0.27,0.6,0.14,0.1,0.52)
X2a=c(17,22,21,18,19,25,8,19)
X2b=c(22,22,29,34,19,26,17,22)
X2 <- function()runif(length(X2a), X2a, X2b)
#create empty list
mod <- list()
#perfrom n-model runs for lm
for(i in 1:10) {
mod[[paste("run",i,sep="")]] <- lm(Y~X1+X2())
}
#define coeficients and how to extract them from lm
All_Model_runs <- function(lm){
out <- c(lm$coefficients[1],
lm$coefficients[2],
summary(lm)$coefficients[2,2],
pf(summary(lm)$fstatistic[1], summary(lm)$fstatistic[2],
summary(lm)$fstatistic[3], lower.tail = FALSE),
summary(lm)$r.squared)
names(out) <-
c("intercept","slope","slope.SE","p.value","r.squared")
return(out)
}
#create empty list
results <- list()
#get coeffiencts for all model runs into list: results
for (i in 1:length(mod)) results[[names(mod)[i]]] <-
All_Model_runs(mod[[i]])
Now my questions you might probably be able to answer:
1) Is that so far good what I was doing (according to your code)?
2) How can I get a mean/average p value for example or an average
over all model runs?
3) Is there any special function to call a mean of these coefficients?
Thank you very much
/Johannes
--