0% found this document useful (0 votes)
39 views3 pages

L06 Backpack Example

This document discusses using bootstrapping to test the hypothesis that the proportion of backpack weight to body weight is less than or equal to 10% for a dataset of backpack weights and body weights. It generates 1000 bootstrap samples, calculates the median and mean for each, and plots the results. The standard deviation is larger for the bootstrap medians than means. It shifts the bootstrap results by the difference between the sample mean and the null hypothesis of 10% and calculates the p-value as the proportion of shifted bootstrap medians below the observed sample median. The p-value is estimated to be 0.

Uploaded by

Lim Yohan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views3 pages

L06 Backpack Example

This document discusses using bootstrapping to test the hypothesis that the proportion of backpack weight to body weight is less than or equal to 10% for a dataset of backpack weights and body weights. It generates 1000 bootstrap samples, calculates the median and mean for each, and plots the results. The standard deviation is larger for the bootstrap medians than means. It shifts the bootstrap results by the difference between the sample mean and the null hypothesis of 10% and calculates the p-value as the proportion of shifted bootstrap medians below the observed sample median. The p-value is estimated to be 0.

Uploaded by

Lim Yohan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

MA256 Lesson 6 - Backpack Example - Generalization (2.3, 2.

4)
For the backpack example, we are trying to see if the proportion of backpack weight to body weight is less than
10%.
H0 : percent = 10%
Ha : percent ≤ 10%

library(tidyverse)

backpack <- read.csv("Backpack.csv")

perc <- (backpack$BackpackWt / backpack$BodyWt) * 100

summary(perc)

## Min. 1st Qu. Median Mean 3rd Qu. Max.


## 1.600 5.121 7.143 7.713 9.630 18.103

We resample, with replacement, to get a bootstrap estimate of the standard deviation.

set.seed(256)

M <- 1000
RES <- data.frame(res.med = rep(NA, M),
res.mean = rep(NA, M))
n <- 100

for(i in seq(1:M)){
x <- sample(perc, n, replace = TRUE)
RES$res.med[i] <- median(x)
RES$res.mean[i] <- mean(x)}

Here we plot the results of the bootstrap for the mean and the median.

RES %>% ggplot(aes(x=res.mean)) + geom_histogram()

## ‘stat_bin()‘ using ‘bins = 30‘. Pick better value with ‘binwidth‘.

100

75
count

50

25

7 8 9
res.mean

1
RES %>% ggplot(aes(x=res.med)) + geom_histogram()

## ‘stat_bin()‘ using ‘bins = 30‘. Pick better value with ‘binwidth‘.

150

100
count

50

6 7 8 9
res.med

sd(RES$res.mean)

## [1] 0.3662797

sd(RES$res.med)

## [1] 0.5149362

We can see that the standard deviation of the median is larger than it is for the mean.
Since the bootstrap will be centered around the actual data (and not the null hypothesis), we will shift the results
of the bootstrap by the difference in the mean of the data and the null hypothesis.
To estimate the p-value, we will count the number of observations that are below the observed median.

my.shift <- 10 - 7.713


my.median <- 7.143

RES %>% ggplot(aes(x=res.med + my.shift)) +


geom_histogram() +
geom_vline(xintercept= my.median, linetype="dashed", color = "red")

## ‘stat_bin()‘ using ‘bins = 30‘. Pick better value with ‘binwidth‘.

150

100
count

50

7 8 9 10 11
res.med + my.shift

2
# estimated p-value
sum(RES$res.med + my.shift <= my.median) / M

## [1] 0

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy