密度图显示了在R?

密度图显示了在R?,r,statistics,normal-distribution,density-plot,hypothesis-test,R,Statistics,Normal Distribution,Density Plot,Hypothesis Test,假设样本来自方差已知的正态分布,因此将采用z检验(而非t检验) mu0你的问题对你真正想要的东西有点模糊。如果你需要一个函数来追踪曲线下的面积,你可以使用我的这个函数,并根据你的需要调整它 area_poly <- function(cur, cutoff, side=c(1,-1), col = "grey", border=NA, ...) { if (side[1]>0 )# on the right { pos <- min(which(cur$x &g

假设样本来自方差已知的正态分布,因此将采用z检验(而非t检验)


mu0你的问题对你真正想要的东西有点模糊。如果你需要一个函数来追踪曲线下的面积,你可以使用我的这个函数,并根据你的需要调整它

area_poly <- function(cur, cutoff, side=c(1,-1), col = "grey", border=NA, ...)
{
  if (side[1]>0 )# on the right
  {
    pos <- min(which(cur$x > cutoff))
    end <- length(cur$x)
  }
  else # on the left
  {
    pos <- max(which(cur$x < cutoff))
    end <- 1
  }
  polygon(x=c(cur$x[end:pos], cur$x[pos], cur$x[end]),
          y=c(cur$y[end:pos], 0, 0), col=col, border=border, ...)
}
area_poly 0)#右侧
{
pos切断)

结束一些需要澄清的问题:函数
hyp.testing
应该做什么?你是否只想对样本均值6.07进行假设检验,以均值4为零?然后
qnorm(0.05,4,3,FALSE)
将给出95%的拒绝区域(单侧假设),以及
(6.07-4)/(3/sqrt(10))
将为您提供测试统计信息。我想在用户定义的函数hyp.testing()中编写此代码,例如,hyp.testing(4,3,0.05,6.07,10){在此处编写代码}是的,但是您可以指定函数的输出吗?像“双面”等术语信息量不大,需要同时绘制单面和双面测试图
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) }
area_poly <- function(cur, cutoff, side=c(1,-1), col = "grey", border=NA, ...)
{
  if (side[1]>0 )# on the right
  {
    pos <- min(which(cur$x > cutoff))
    end <- length(cur$x)
  }
  else # on the left
  {
    pos <- max(which(cur$x < cutoff))
    end <- 1
  }
  polygon(x=c(cur$x[end:pos], cur$x[pos], cur$x[end]),
          y=c(cur$y[end:pos], 0, 0), col=col, border=border, ...)
}
cc <- curve(dnorm(x, mean = 4, sd = 3), from = -5, to = 10, n = 100, lwd = 3,
            xlab = "", ylab = "Density", frame = F)
area_poly(cc, cutoff = 6, side = 1, col = "grey50", density = 10)