[密度图使用R?中的假设检验显示了关键区域]]

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

假设从具有已知方差的正态分布中进行抽样,那么将使用z检验(而不是t检验)。

mu0 <- 4                ## Null hypothesis mean value
stdev <- 3              ## Known population standard deviation
signif.level <- 0.05    ## Test significance level
sample.mean <- 6.07     ## Mean of the random sample
n <- 10                 ## Sample size
mu1 <- 6.2              ## Alternative hypotesis mean value to use for error type 2 


hyp.testing <- function(mu0, stdev, signif.level, 
                        sample.mean, n, show_crit, 
                        show_pvalue, show_alt, mu1, 
                        show_beta, show_power, two_sided) {
                      } 

我需要用红色条纹显示关键区域的密度图。

我尝试使用也称为类型1错误的多边形。我们可以使用多边形解决此问题吗?

hyp.testing(4,3,0.05,6.07,10)  {

xval <- seq(-3.2, 3.2, length = 1000)
yval <- dnorm(xval)

 plot(xval, yval, type = "l", axes = TRUE, frame = FALSE, lwd = 3, 
 xlab = "", ylab = "")

 x <- seq(qnorm(.95), 3.2, length = 100)

 polygon(c(x, rev(x)),c(dnorm(x), rep(0, length(x))), col = "salmon")

 text(mean(x), mean(dnorm(x))+.02, "9%", cex = 1)

 text(qnorm(.95), .01, "1.645", cex = 1) }

但是,我无法获得所需的输出,如下所示:

预期的输出是这样的:

输出:

enter image description here

假定从具有已知方差的正态分布中进行采样,因此将使用z检验(而非t检验)。 mu0

r statistics normal-distribution density-plot hypothesis-test
1个回答
0
投票

您的问题对您实际想要的内容有点含糊。如果需要跟踪曲线下面积的功能,则可以使用我的此功能并使之适应您的需求。

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