John is looking to invest in the Canadian Stock Market. In particular, John wants to maximize his received cash flows, so he would like to invest in companies that have a high dividend per share ratio. Load the FinanceCanada.csv dataset. This contains randomly chosen Canadian companies sorted into seven industry groups (1=real estate, 2=financial, etc), along with a variety of financial metrics. To direct his investing, John would like to test whether certain types of industries have on average a higher dividend per share ratio. b) Run a one-way ANOVA at 𝛼 = 0.05. Print out the ANOVA table, make a decision, and interpret your result. (HINT: we want to use TypeOfIndustry as a factor, but since the values are numeric (1 through 7) we must use the command as.factor(TypeOfIndustry) to treat it as a grouping variable)
library(readr) finance <- read_csv("FinanceCanada.csv") library(car) library(dplyr) finance$TypeOfIndustry <- as.factor(finance$TypeOfIndustry) collapse_factor <- function(x){ factor_num <- as.integer(x) if(factor_num %in% c(1,2,3)){ factor_num <- 1 } else if(factor_num %in% c(4,6)){ factor_num <- 2 } else if(factor_num %in% c(5,7)){ factor_num <- 3 } return(factor_num) } finance$TypeOfIndustry <- sapply(finance$TypeOfIndustry, collapse_factor) finance$TypeOfIndustry <- as.factor(finance$TypeOfIndustry) DPS <- finance$DPS TypeOfIndustry <- finance$TypeOfIndustry lm