Dear Alexandra,

Perhaps you can use a different approach but I think it works:


# Chi-suared CI
var.ci=function(x,alpha=0.05){
n=length(x)-sum(is.na(x))
s2=var(x,na.rm=T)
li=s2*(n-1)/qchisq(1-alpha/2,n-1)
ls=s2*(n-1)/qchisq(alpha/2,n-1)
c(li,ls)
}

# Example
set.seed(123)
y=rnorm(1000,25,2)
var.ci(y)             # 3.610426 4.302965


# Bootstrap CI
var.bs=function(x,FUN=var,alpha=0.05,NSIM=1000){
temp=matrix(rep(x,NSIM),ncol=NSIM)
temp2=apply(temp,2,sample,replace=TRUE)
vars=apply(temp2,2,var)
quantile(vars,probs=c(alpha/2,1-alpha/2))
}


var.bs(y)  # 3.618220 4.274773


I hope this helps,

-- 
JIV


On Mon, Apr 7, 2008 at 10:13 AM, Alexandra Ramos <[EMAIL PROTECTED]> wrote:

> Hi,
>
>
>
> Does anyone know an instruction to perform a test (or to construct a
> confidence interval) for the variance of a normal population (distribution).
>
> The test statistic is  (n-1)*S´^2/sigma^2  and has chi square (n-1)
> distribution.
>
>
>
> Thank you,
>
> Alexandra
>
>
>
>
>
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to