births.csv file into an object
called births. Print out the first 6 rows and verify it
matches the lab manual.# Type your CODE in here
births<-read.csv("births.csv")
head(births)
births data that
contains the eighth and eleventh rows, and the Visits and
Gained variables. Only use numeric vectors to make this
subset.# Type your CODE in here
births[c(8, 11), c(10, 16)]
births data that
contains the second through seventh rows, and the Racemom
and Racedad variables. Only use numeric vectors created
with the colon operator to make this subset.# Type your CODE in here
births_sub <- births[2:7, 12:13]
head(births_sub)
births data that
contains the second, third, and sixth rows, and the Premie
and weight variables. Only use a character vector to
specify the columns to subset.# Type your CODE in here
births[c(2, 3,6), c("Premie", "weight")]
# Type your CODE in here
mean(~ Fage | Marital, data = births)
## Married Unmarried
## 31.57728 28.40992
# Type your CODE in here
mean(~ weight | Gender, data = births)
## Female Male
## 113.7503 118.1986
# Type your CODE in here
var(~ weight | Premie, data = births)
## No Yes
## 255.3130 652.4227
# Type your CODE in here
histogram(~ Mage, data = births)
# Type your CODE in here
histogram(~ Mage | Marital, data = births)
# Type your CODE in here
# Parameters
M <- 100
n <- 1
pi <- 0.5
# Random Sampling
set.seed(95472)
X <- rbinom(M, size = n, prob = pi)
mean(X)
## [1] 0.53
# Type your CODE in here
# Parameters
M <- 1000
n <- 1
pi <- 0.5
# Random Sampling
set.seed(83954)
X <- rbinom(M, size = n, prob = pi)
mean(X)
## [1] 0.525
# Type your CODE in here
# Parameters
M <- 10000
n <- 1
pi <- 0.5
# Random Sampling
set.seed(64732)
X <- rbinom(M, size = n, prob = pi)
mean(X)
## [1] 0.5047
As our sample trials increases our proportion is getting closer to 0.5. This because this because as our trials increase the closer our expected proportion balances out the various results and you thus gets closer to 0.5.
\[H_{0}: \pi=0.5\] \[H_{1}: \pi>0.5\]
X. Print the frequencies of X with the
tally() function.# Type your CODE in here
# Parameters
M <- 1000
n <- 1
pi <- 0.5
# Random Sampling
set.seed(485)
X <- rbinom(M, size = n, prob = pi)
tally(X)
## X
## 0 1
## 514 486
tally() and data.frame() functions to start a
data frame of sums and frequencies. Call this data frame
prob_dist. Print this data frame.# Type your CODE in here
prob_dist <- data.frame(tally(X))
prob_dist
p in the
prob_dist data frame. Print the prob_dist data
frame.# Type your CODE in here
prob_dist$p <- paste0(0:1, "/", n)
prob_dist
prob_p in the
prob_dist data frame. Print the prob_dist data
frame.# Type your CODE in here
prob_dist$prob_p <- prob_dist$Freq/M
prob_dist
# Type your CODE in here
pvalue <- sum(prob_dist[1:1, "prob_p"])
pvalue
## [1] 0.514
We reject H0 based on our results.
The coin is more biased to heads on average.