Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- corr_arr <- function(a,b){
- corr = 0
- a_bar <- sum(a)/length(a)
- b_bar <- sum(b)/length(b)
- var_a = sum((a - a_bar)^2)/(length(a) - 1)
- var_b = sum((b - b_bar)^2)/(length(b) - 1)
- covar_a_b = sum((a - a_bar) * (b - b_bar))/ (length(b) - 1)
- corr = covar_a_b/sqrt(var_a * var_b)
- return(corr)
- }
- data <- data_loader("death_rates.csv",",")
- female_data = data[data$Sex == "F",]
- male_data = data[data$Sex == "M",]
- display_correlation <- function(female_data){
- #we are encoding the sex feature (F,M) -> (1,2)
- data$Sex = as.numeric(factor(data$Sex,levels = c("F","M"),labels = c(1, 2)))
- result <- matrix(, nrow = ncol(data), ncol =ncol(data))
- for (i in 1:ncol(data)){
- for (j in 1:ncol(data)){
- result[i,j] <- corr_arr(data[,i],data[,j])
- }
- }
- colnames(result) <- colnames(data)
- rownames(result) <- colnames(data)
- return(result)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement