1
$\begingroup$

As per my study material, there is no default function in R to conduct hypothesis test for single population variance. So, I have written the following code in R to calculate p-value under (i) Assuming theoretical distribution, as well as (ii) Bootstrap approach. However, as seen below, there is huge difference in p-values under both - 0.1244934 under (i) and 0.02545 under (ii), also clearly seen in comparative graphs. Am I doing it correctly?

Single Variance Test -

weight

[Output] 242 290 340 363 430 450 500 390 450 500 475 500 500 340 600 600 700 700 610 650 575 685 620 680 700 725 720 714 850 1000 920 955 925 975 950

qqnorm(weight)

qqline(weight)

QQ-Plot

boxplot(weight)

Boxplot

var(weight)

[Output] 43767.03

#H0 : var0=60000

#H1 : var0<60000

Using theoretical distribution

tsv<-(NROW(weight)-1)*var(weight)/60000

tsv

[Output] 24.80132

pv.th<-pchisq(tsv,NROW(weight)-1)

pv.th

[Output] 0.1244934

Using Bootstrap approach

var.est<-vector()

n<-1:100000

for(i in n){x<-sample(weight,NROW(weight),replace = TRUE);var.est[i]<-60000+(var(x)-var(weight))}

hist(var.est)

pv.emp<-length(var.est[var.est<=var(weight)])/length(var.est)

pv.emp

[Output] 0.02545

Comparative graphs

trans<-var.est*(NROW(weight)-1)/60000

hist(trans,probability = TRUE,xlim = c(0,70))

curve(dchisq(x,df=NROW(weight)-1),add = TRUE,lwd=2,col="red")

pv.th

[Output] 0.1244934

length(trans[trans<=tsv])/length(trans)

[Output] 0.02545

pv.emp

[Output] 0.02545

Comparative graphs

$\endgroup$
1
  • $\begingroup$ These notes seem relevant for your bootstrap test. $\endgroup$
    – BruceET
    May 8, 2020 at 0:39

1 Answer 1

0
$\begingroup$

Minitab statistical software has a procedure for testing a single variance. Assuming that $n = 35$ [deduced from what you show], here are relevant parts of the output from a recent release of Minitab. The P-value $0.124$ agrees with your theoretical result.

 Test and CI for One Variance 

 Method

 Null hypothesis         σ-squared = 60000
 Alternative hypothesis  σ-squared < 60000

 The chi-square method is only for 
 the normal distribution.

 Statistics

  N  StDev  Variance
 35    209     43765

 95% One-Sided Confidence Interval

             Upper
             Bound
               for   Upper Bound
 Method      StDev  for Variance
 Chi-Square    262         68684

 Test
                  Test
 Method      Statistic  DF  P-Value
 Chi-Square      24.80  34    0.124

So it seems you need to look for trouble in your bootstrap method. I can't check your bootstrap because (a) you don't explain your method [except via undocumented code] and (b) I don't have access to your data.

However, I wonder whether you have looked at your data to see whether they are consistent with a random sample from a normal distribution. If they are not, then there is no reason to expect any bootstrap procedure to match normal-based theoretical results.

$\endgroup$
4
  • $\begingroup$ Thanks for the reply. I have added sample data "weight", its Normal Q-Q Plot and Boxplot. Please check. Also, I don't know what you mean by method (my study material doesn't have any, it simply asks to carry out hypothesis test by Bootstrap method). I will be thankful if you can give me link to the resources explaining different methods of Bootstrap. $\endgroup$ May 8, 2020 at 5:23
  • $\begingroup$ Suggested a link in my Comment just below your Q. Mainly process-oriented, but rationales given for some steps. Google 'bootstrap testing' and similar phrases for more. Try to find lecture notes from major universities. (Any idiot with an Internet connection can claim to be a bootstrapping guru, and there are links to illustrate that.) // I have to say I have a personal preference to do bootstrapping for CIs and to do testing via permutation tests. Some good links on permutation tests also. If interested, Google eudey permutation test education for one of them. $\endgroup$
    – BruceET
    May 8, 2020 at 5:36
  • $\begingroup$ I have now installed "wBoot" package in R. However, it is calculating p-value differently and I have verified their method by calculating it separately myself by running code numerous times. As per the definition, we calculate p-value as prob of obtaining the "observed or more extreme value", given Null Hypothesis is true. This "wBoot" package is calculating p-value in case of bootstrap approach as prob of obtaining "null hypothesis or more extreme value", given the bootstrap sampling distribution. Is this approach correct? $\endgroup$ May 9, 2020 at 5:23
  • $\begingroup$ There many styles of bootstraps and I am not sure the one you are using in R is exactly the same as my very simple version. You don't say how much different your result is. Also, the number of re-samples can make a difference in the results. Finally, because bootstrapping involves simulation, even the same method with the same number of re-samples may give slightly different results on different runs. $\endgroup$
    – BruceET
    May 9, 2020 at 5:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.