+ Reply to Thread
Results 1 to 4 of 4

Thread: Bootstrap confidence interval

  1. #1
    Points: 838, Level: 15
    Level completed: 38%, Points required for next Level: 62

    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Bootstrap confidence interval



    Hey guys, Would you guys please help me do this exercise ? as I'm new to R program and also not very good at it. I need to have this homework finished by this friday but still can not figure it out how to do it. It's about how to construct bootstrap confidence interval by using R program. And I saved it as PDF file. Thank you very much for your help
    Attached Images

  2. #2
    Point Mass at Zero
    Points: 5,855, Level: 49
    Level completed: 53%, Points required for next Level: 95
    ledzep's Avatar
    Location
    Berks,UK
    Posts
    635
    Thanks
    169
    Thanked 130 Times in 128 Posts

    Re: Bootstrap confidence interval

    Why don't you start from Kabacoff's page on bootstrapping. There is an example on how to compute 95% bootstrap CI for model estimates.

    http://www.statmethods.net/advstats/bootstrapping.html


    Code: 
    
    ## From Kabacoff's page
    
    library(boot)
    
    # function to obtain regression 
    bootstrap<- function(formula, data, indices) {
      d <- data[indices,] # allows boot to select sample 
      fit <- lm(formula, data=d)
      return(coef(fit)) 
    } 
    
    # bootstrapping with 1000 replications 
    results <- boot(data=test, statistic=bootstrap, R=1000, formula=y~x)
    
    # Get 95% confidence interval for the slope 
    boot.ci(results, type="bca", index=2)  ## for the slope
    HTH
    Oh Thou Perelman! Poincare's was for you and Riemann's is for me.

  3. #3
    Points: 838, Level: 15
    Level completed: 38%, Points required for next Level: 62

    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bootstrap confidence interval

    Thank you Ledzep. I already checked it out but I still don't really get it. I did try to do it but It was said there were over 50 warnings, so would you please help me check it this code for me ?

    function (n,alpha,B)
    {
    L=numeric(B)
    U=numeric(B)

    for(j in 1:B)
    {
    x=c(2,4,6,8,10,12,14)
    y=c(63,128,194,257,322,387,451)
    t=qt(alpha/2,n-2)

    xbar.b=numeric(B)
    ybar.b=numeric(B)
    for(i in 1:n)
    {
    xb=sample(x,n,replace=T)
    x.bar = mean(xb)
    yb=sample(y,n,replace=T)
    y.bar = mean(y)
    }
    xbar=mean(x.bar)
    ybar=mean(y.bar)

    b1 = (sum(x*y)-(n*(xbar)*(ybar)))/(sum(x^2)-(n*(xbar^2)))
    b0 = (ybar)-(b1*xbar)
    y.hat = b0+(b1*x)
    s2 = sum((y-y.hat)^2)/n-2
    s2.b1 = s2/(sum(x^2)-(n*((xbar^2))))
    s.b1 = sqrt(s2.b1)

    L=b1-abs((t*s.b1))
    U=b1+abs((t*s.b1))
    }
    out=cbind(Lower=L,Upper=U)
    print(out)

    }

  4. #4
    Points: 838, Level: 15
    Level completed: 38%, Points required for next Level: 62

    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Bootstrap confidence interval


    > fix(bootstrap)
    > bootstrap(7,0.05,1000)
    Lower Upper
    [1,] -320.7183 703.0341
    There were 50 or more warnings (use warnings() to see the first 50)
    this is what I got.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats