Seeing if data is normally distributed in R

前端 未结 8 1584
我寻月下人不归
我寻月下人不归 2020-11-27 08:57

Can someone please help me fill in the following function in R:

#data is a single vector of decimal values
normally.distributed <- function(data) {
if(dat         


        
8条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 09:48

    when you perform a test, you ever have the probabilty to reject the null hypothesis when it is true.

    See the nextt R code:

    p=function(n){
      x=rnorm(n,0,1)
      s=shapiro.test(x)
      s$p.value
    }
    
    rep1=replicate(1000,p(5))
    rep2=replicate(1000,p(100))
    plot(density(rep1))
    lines(density(rep2),col="blue")
    abline(v=0.05,lty=3)
    

    The graph shows that whether you have a sample size small or big a 5% of the times you have a chance to reject the null hypothesis when it s true (a Type-I error)

提交回复
热议问题