在R上创建柯西分布

问题描述 投票:0回答:1

我正在执行this question的c)部分,这需要柯西分布。这是我的尝试:

counter <- 0
slopes <- c()

while(counter < 1000) {
  xvals <- runif(n = 100, min = -1, max = 1)
  evals <- rcauchy(100)
  y <- 5 + 3 * xvals + evals
  fit <- lm(y ~ xvals)
  slopes <- c(slopes, fit$coefficients[[2]])
  counter <- sum(counter, 1)
}
mean(slopes)
print(evals)
plot(evals)

但是,我得到了一些非常奇怪的结果,我怀疑它们是否正确:

plot of evalshistogram with values of the slopes of 10,000 regression linesfirst random set with regression line

我也尝试设置evals

r statistics linear-regression distribution
1个回答
0
投票

如注释中所述,您的代码正在做“正确的事情”,但是您可能需要调整直觉,以了解尾部发生的事情的重要性

至于功能之间的区别:

有许多与此相关的代码位,rnormdnorm用于正态分布,但是您可以在https://stats.stackexchange.com/q/157662/17060中找到有关此差异的更多注释

© www.soinside.com 2019 - 2024. All rights reserved.