plovers<-read.csv("C:/Users/joshu/Downloads/PenGPT - Copy/PenGPT - Copy/PenGPT/pen_v2/datasheets/MA2611_Lab3_files/plovers.csv",header=TRUE)
summary(plovers[2:5])
## Wingspan Body.Length Weight Eggs
## Min. :30.30 Min. :11.90 Min. :31.80 Min. :2.00
## 1st Qu.:34.00 1st Qu.:13.15 1st Qu.:40.67 1st Qu.:3.00
## Median :35.20 Median :14.40 Median :46.50 Median :3.00
## Mean :36.36 Mean :15.43 Mean :48.40 Mean :3.25
## 3rd Qu.:39.48 3rd Qu.:18.18 3rd Qu.:54.98 3rd Qu.:4.00
## Max. :42.30 Max. :19.10 Max. :63.80 Max. :4.00
ggplot(data=plovers,aes(x=as.factor(Eggs),y=Wingspan,fill=as.factor(Eggs))) +
geom_boxplot(color="black") +
scale_fill_manual(values=c("tomato","gold","royalblue")) +
labs(title="Boxplot of Plover Wingspan by Egg Count",
x="Eggs in Nest",y="Wingspan (cm)",fill="Eggs")
The three boxplots sit at roughly similar levels, though the 2-egg group is a single observation (no visible box, just a line at ~41 cm) so it cannot really be compared. The 3-egg and 4-egg groups have overlapping IQRs and comparable medians (mid-30s cm), which suggests wingspan is not strongly tied to nest egg count in this sample.
ggplot(data=plovers,aes(x=Weight,fill=as.factor(Eggs))) +
geom_histogram(binwidth=5,color="black",position="identity",alpha=0.6) +
scale_fill_manual(values=c("tomato","gold","royalblue")) +
labs(title="Histogram of Plover Weight by Egg Count",
x="Weight (g)",y="Count",fill="Eggs")
The Weight histograms for the 3-egg and 4-egg groups overlap heavily across the 40–55 g range with no clean separation between them. The single 2-egg observation sits inside that range as well. There is no obvious weight cluster tied to a particular egg count.
Based on both the boxplot in part (a) and the histogram in part (b), there is no strong indication that Wingspan or Weight differ meaningfully with the number of eggs in a nest. The distributions for the 3-egg and 4-egg groups overlap almost entirely for both variables, and the 2-egg group is represented by a single bird — far too little data to support a real difference. A larger sample and a formal test (e.g., ANOVA) would be needed to draw a firm conclusion.
Flipping an unfair coin with \(p_H = 0.2\) and \(p_T = 0.8\), sampled \(n = 1000\) times. Let “1” represent heads and “0” represent tails.
random_coin<-sample(x=c(0,1),size=1000,replace=TRUE,prob=c(0.8,0.2))
coin.data<-data.frame(Values=table(random_coin),
Names=as.factor(c("Tails","Heads")))
coin.data
## Values.random_coin Values.Freq Names
## 1 0 797 Tails
## 2 1 203 Heads
ggplot(coin.data,aes(x=Names,y=Values.Freq)) +
geom_col(fill=c("orange","purple"),color="black") +
labs(title="Bar Graph of 1000 Unfair Coin Flips (p_H = 0.2)",
x="Outcome",y="Counts")
sum(random_coin==1)/1000 # observed proportion of heads
## [1] 0.203
The tails bar towers over the heads bar, matching the loaded probabilities \(p_T = 0.8\) and \(p_H = 0.2\). The observed proportion of heads is close to 0.2, and with \(n = 1000\) trials the relative frequency is a tight estimate of the true probability.
Let \(X \sim \text{Binomial}(8, 0.5)\); generate \(n = 20{,}000\) values.
x<-rbinom(n=20000,size=8,prob=0.5)
sum(x==5)/20000 # estimated P(X = 5)
## [1] 0.21765
sum(x>=4 & x<7)/20000 # estimated P(4 <= X < 7)
## [1] 0.59755
dbinom(5,size=8,prob=0.5) # exact P(X = 5)
## [1] 0.21875
sum(dbinom(4:6,size=8,prob=0.5)) # exact P(4 <= X < 7)
## [1] 0.6015625
The exact probabilities are \(P(X=5) = \binom{8}{5}(0.5)^8 = 0.21875\) and \(P(4 \le X < 7) = \binom{8}{4}(0.5)^8 + \binom{8}{5}(0.5)^8 + \binom{8}{6}(0.5)^8 \approx 0.6016\). The estimates from 20,000 sampled values fall within a fraction of a percent of these exact values, showing that a large simulated sample tightly approximates the true binomial probabilities.
mean(x) # estimated expected value
## [1] 3.98875
sd(x) # estimated standard deviation
## [1] 1.409157
n<-8; p<-0.5
n*p # exact E(X) = np
## [1] 4
sqrt(n*p*(1-p)) # exact s(X) = sqrt(np(1-p))
## [1] 1.414214
The exact values are \(E(X) = np = 4\) and \(s(X) = \sqrt{np(1-p)} = \sqrt{2} \approx 1.4142\). The sample mean and standard deviation come out very close to these theoretical values — a consequence of the large sample size (\(n = 20{,}000\)).
x.data<-data.frame(Values=table(x),
Names=as.factor(as.character(0:8)))
x.data
## Values.x Values.Freq Names
## 1 0 89 0
## 2 1 621 1
## 3 2 2127 2
## 4 3 4524 3
## 5 4 5462 4
## 6 5 4353 5
## 7 6 2136 6
## 8 7 605 7
## 9 8 83 8
ggplot(x.data,aes(x=Names,y=Values.Freq)) +
geom_col(fill="royalblue",color="black") +
labs(title="Bar Graph of X ~ Binomial(8, 0.5) Sample (n = 20000)",
x="X Values",y="Counts")
The bar graph is symmetric and centered on \(X = 4\), with the tallest bar at 4 and shorter bars falling off on either side toward 0 and 8. The center of the graph matches the estimated expected value of ~4, and the spread (most values falling between 2 and 6) matches an SD of ~1.41 — the bulk of the mass sits within one standard deviation of the mean, as expected for a symmetric binomial with \(p = 0.5\).