R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

library(readxl)
library(ggplot2)
DatasetA2 <- read_excel ("C:/Users/tanie/Downloads/DatasetA2.xlsx")
DatasetB2 <- read_excel ("C:/Users/tanie/Downloads/DatasetB2.xlsx")
table(DatasetA2$FavoriteDrink)
## 
## Coffee   Soda    Tea  Water 
##     26     29     28     17
ggplot(DatasetA2, aes(x = FavoriteDrink, fill = FavoriteDrink)) +
  geom_bar() +
  labs(
    x = "FavoriteDrink",
    y = "Frequency",
    title = "Distribution of Prefered Beverage"
  ) +
  theme(
    text = element_text(size = 14),       
    axis.title = element_text(size = 14),  
    axis.text = element_text(size = 14),  
    plot.title = element_text(size = 14),  
    legend.position = "none"              
  )

observed <- c(26, 29, 28, 17) 
expected <- c(0.25, 0.25, 0.25, 0.25)
chisq.test(x = observed, p = expected)
## 
##  Chi-squared test for given probabilities
## 
## data:  observed
## X-squared = 3.6, df = 3, p-value = 0.308

A chi square goodness of fit test indicated that the observed frequencies were not significantly different from the expected equal frequencies χ²(3) = 3.6, p= 0.31 indicating that the beverage preferences did not significantly differ from an equal distribution.

library(readxl)
library(ggplot2)
library(rcompanion)
DatasetB2 <- read_excel ("C:/Users/tanie/Downloads/DatasetB2.xlsx")
tab <- table(DatasetB2$StudentType, DatasetB2$PetOwnership)
ggplot(DatasetB2, aes(x = StudentType, fill = PetOwnership)) +
  geom_bar(position = "dodge") +                 
  labs(
    x = "StudentType",
    y = "Frequency",
    title = "Pet ownership by student type"
  ) +
  theme(
    text = element_text(size = 14),
    axis.title = element_text(size = 14),
    axis.text = element_text(size = 14),
    plot.title = element_text(size = 14),
    legend.position = "none"                 
  ) 

chisq.test(tab)
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  tab
## X-squared = 0.040064, df = 1, p-value = 0.8414

The Chi-Square Test of Independence indicated there was not a significant association between studenttype and petownership, χ²(1) = 0.04, p = 0.8.