2013-09-30 64 views
0

如何使用R來計算N = 1000 MLR模型擬閤中各個係數的均值和標準差? 這裏是我的功能:使用R?的係數向量的均值和標準差?

simfun <- function(a=56.25102409,b=1.78977412,c=0.08664925,n=18,x1.sd=18.87671,x2.sd=18.87671,e.sd=18.87671) { 
    X1 <- rnorm(n, mean=0, sd=x1.sd) 
    X2 <- rnorm(n, mean=0, sd=x2.sd) 
    e <- rnorm(n, mean=0, sd=e.sd) 
    Z <- a+b*X1+c*X2+e 
    data.frame(X1,X2,Z) 
} 

statfun <- function(samples) { 
    coef(lm(Z~X1+X2,data=samples)) 
} 

library(plyr) 
raply(1000,statfun(simfun())) 

回答

0

資源< - .Last.value

> apply(res,2,mean) 
(Intercept)   X1   X2 
57.9515278 1.6696702 0.1116194 
> apply(res,2,sd) 
(Intercept)   X1   X2 
    2.5550134 0.3177064 0.2789701 
相關問題