AndriSignorell / DescTools

Tools for Descriptive Statistics and Exploratory Data Analysis
http://andrisignorell.github.io/DescTools/
82 stars 18 forks source link

Strange script in DescTools:::VarTest.default() #108

Open DrJerryTAO opened 1 year ago

DrJerryTAO commented 1 year ago

Hi @AndriSignorell, when testing a one-sample variance against a hypothesized population variance in VarTest(), the confidence interval appears only for the sample variance but not the ratio of sample variance to the population variance. Would you consider adding the confidence interval of the ratio based on https://stats.libretexts.org/Bookshelves/Introductory_Statistics/Book%3A_Introductory_Statistics_(OpenStax)/11%3A_The_Chi-Square_Distribution/11.07%3A_Test_of_a_Single_Variance?

Further, the confidence interval calculation for appears strange for alternative = "two.sided", as it seems to use a t distribution between line 34 and 41.

      pval <- 2 * min(pchisq(xstat, df), pchisq(xstat, 
        df, lower.tail = FALSE))
      alpha <- 1 - conf.level
      cint <- qt(1 - alpha/2, df)
      cint <- xstat + c(-cint, cint)
      cint <- df * vx/c(qchisq((1 - conf.level)/2, df, 
        lower.tail = FALSE), qchisq((1 - conf.level)/2, 
        df))
AndriSignorell commented 1 year ago

Thanks for that. The qt/xstat code is indeed bullshit and some historical phantom code. I dismissed it. But I don't see, how you would like the confidence intervals to be. From my point of view, the implementation exactly inverses the teststatistic with cint <- df * vx / c(qchisq((1 - conf.level)/2, df, lower.tail = FALSE), qchisq((1 - conf.level)/2, df)) Could you be more specific?