Question
library(tidyverse) chimp
library(tidyverse)
chimp <- read.csv("ChimpBrains.csv") summary(chimp) head(chimp)
cannibalism <- read.csv("SagebrushCrickets.csv") summary(cannibalism) head(cannibalism)
cannibalism$feedingStatus <- factor(cannibalism$feedingStatus , levels = c("starved", "fed"))
twoMedians <- tapply(cannibalism$timeToMating, cannibalism$feedingStatus, median)
diffMedian <- twoMedians[1] - twoMedians[2]
boot.diffMedian <- function(x, i){ twoMedians <- tapply(x$timeToMating[i], x$feedingStatus[i], median) diffMedian <- twoMedians[1] - twoMedians[2] }
Questions:
Now that we have the function above defined, go ahead and obtain the bootstrap replicate estimates on the data using the output bootResults and the function boot with the inputs into the boot function being cannibalism, and the function we just created, boot.diffMedian and run R=10000 for your bootstrap replicas. Comment on your Results from the observed difference in the medians
Plot the estimate of our sampling distribution using the ggplot function. Make your plot a histogram plot. Remember to put your data into a data.frame and within the data.frame apply the diffMedians=bootResults$t syntax. Label your x-axis Bootstrap replicate difference in median and label your y-axis Frequency. For aesthetics you can set your x=diffMedians and add the geom_histogram function. Color can be of any preference you choose, a binwidth=5 is fine, closed=left and set boundary=0
Calculate the bootstrap confidence interval using the function boot.ci and the inputs bootResults and type = perc
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started