0
如何使用R將T密度疊加到我的直方圖?這裏是我的功能:使用R覆蓋t分佈到我的直方圖?
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)
B=raply(1000,statfun(simfun()))
(hist(B[,2]))
'x'在這裏是什麼? – Seth
請參閱?曲線。曲線函數需要一個涉及「x」的表達式,它在表達式 –
的上下文中通過xlim範圍內的一系列遞增值,並感謝dwin,儘管看起來似乎更安全一些,從= -4到到= 4「或其他。我幾乎總是有一個名爲'x'的對象會污染事物。 – Seth