Question 1

Construct the corresponding polygon given the following points below.

\[A \space (10,1) \space B \space (8,5) \space C \space (14,-1)\]

# install.packages("tidyverse")
library(tidyverse)
## Warning: package 'lubridate' was built under R version 4.5.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.1     ✔ stringr   1.5.2
## ✔ ggplot2   4.0.0     ✔ tibble    3.3.0
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.1.0     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
q1_data <- data.frame(Label = LETTERS[1:3],
                      X = c(10,8,14),
                      Y = c(1,5,-1))
ggplot(q1_data,aes(x = X,y = Y)) +
  geom_polygon(fill = "yellow",color = "black",lwd = 1.25) +
  geom_point(size = 4) +
  coord_equal() +
  theme_gray()

Question 2

There are nineteen sweets in a jar - 4 blue, 4 red, 4 green, 5 yellow, and 2 black. You shake the jar and choose one sweet from the jar without looking.

A. What is the probability the sweet is yellow?

jar1 <- c(rep("Blue",4),rep("Red",4),rep("Green",4),rep("Yellow",5),rep("Black",2))
counter1 <- 0
N1 <- 1e6
for (i in 1:N1) {
  pick1 <- sample(x = jar1,size = 1,replace = T)
  if (pick1 == "Yellow") {
    counter1 <- counter1 + 1
  }
}
probability1 <- counter1 / N1
cat("The probability the sweet is yellow is:",probability1,"\n")
## The probability the sweet is yellow is: 0.262657

B. What is the probability the sweet is not yellow?

jar2 <- c(rep("Blue",4),rep("Red",4),rep("Green",4),rep("Yellow",5),rep("Black",2))
counter2 <- 0
N2 <- 1e6
for (j in 1:N2) {
  pick2 <- sample(x = jar2,size = 1,replace = T)
  if (pick2 != "Yellow") {
    counter2 <- counter2 + 1
  }
}
probability2 <- counter2 / N2
cat("The probability the sweet is not yellow is:",probability2,"\n")
## The probability the sweet is not yellow is: 0.736729

Question 3

Calculate the Pearson correlation coefficient using each method below with the following data.

Define the data frame…

q3_data <- data.frame(x = c(15,13.5,12,9.5,9,5.5,2,-1.5),
                      y = c(11,10,7,4.5,0,-2,-4.5,-10))
q3_data
##      x     y
## 1 15.0  11.0
## 2 13.5  10.0
## 3 12.0   7.0
## 4  9.5   4.5
## 5  9.0   0.0
## 6  5.5  -2.0
## 7  2.0  -4.5
## 8 -1.5 -10.0

A. Use the cor() function.

cor(x = q3_data$x,y = q3_data$y) # correlation coefficient only
## [1] 0.9817631

B. Use the cor.test() function.

cor.test(x = q3_data$x,y = q3_data$y) # correlation coefficient and other information
## 
##  Pearson's product-moment correlation
## 
## data:  q3_data$x and q3_data$y
## t = 12.65, df = 6, p-value = 1.496e-05
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.8991233 0.9968165
## sample estimates:
##       cor 
## 0.9817631