R/sb_number.R

Defines functions sb_number

#' sb_number
#'
#' This function loads the census data around class, dices by ward
#'calculates based on information provided from lucid talk for unionists
#' @return sb_predictor output for UUP
#' @export sb_number
#' @import dplyr
sb_number <- function(LTABC, LTCTWO, abcweight,ctwodeweight){
  
  
  load("~/andymacmillan/data/Dataset_3004_2011_1_.rda")
  
  sb_ds <- Dataset_3004_2011_1_ %>% 
    filter(Dataset_3004_2011_1_$Ward %in% c('Beechill', 'Botanic','Belvoir', 'Blackstaff', 'Cairnshill', 'Carryduff East', 'Carryduff West', 'Wynchurch','Cregagh', 'Falls', 'Finaghy', 'Galwally', 'Hillfoot', 'Knockbracken','Malone','Minnowburn','Musgrave','Newtownbreda', 'Shaftesbury', 'Ravenhill', 'Rosetta','Stranmillis','Upper Malone', 'Windsor','Woodstock'))
  sb_ds$abcone <- sb_ds$`Approximated social grade of HRP aged 16-64 years: AB` + sb_ds$`Approximated social grade of HRP aged 16-64 years: C1`
  sb_ds$ctwode <- sb_ds$`Approximated social grade of HRP aged 16-64 years: C2` + sb_ds$`Approximated social grade of HRP aged 16-64 years: DE`
  
  #lucidtalk numbers
  LTABC = LTABC
  LTCTWO = LTCTWO
  
  sb_ds$adbc_unweighted <- sb_ds$abcone * LTABC
  sb_ds$ctwode_unweighted <- sb_ds$ctwode * LTCTWO
  #adjusted census 2011 with no exponetial growth
  Religion <- c("None", "Catholic", "Protestant", "Other")
  Number <- c(0.22, 0.41, 0.37, 0.01)
  
  demographic <- cbind(Religion, Number)
  demographic <- as.data.frame(demographic)
  #assembly info demogaphic eb with no exponetial growth
  sb_religion <- c("None", "Catholic", "Protestant", "Other")
  sb_number <- c(0.09, 0.46, 0.42,0.03)
  
  sb_demographic <- cbind(demographic, sb_number) 
  sb_demographic$Number <- as.numeric(sb_demographic$Number)
  sb_demographic$ratio <- sb_demographic$sb_number/sb_demographic$Number 
  
  sb_ds$weighted_abc <- ((sb_ds$adbc_unweighted*0.09)*0.4090909) + 
    ((sb_ds$adbc_unweighted*0.46)*1.1219512) +
    ((sb_ds$adbc_unweighted*0.42)*1.1351351) +
    ((sb_ds$adbc_unweighted*0.03)*3)  
  
  sb_ds$weighted_ctwode <- ((sb_ds$ctwode_unweighted*0.09)*0.4090909) + 
    ((sb_ds$ctwode_unweighted*0.46)*1.1219512) +
    ((sb_ds$ctwode_unweighted*0.42)*1.1351351) +
    ((sb_ds$ctwode_unweighted*0.03)*3)  
  
  sb_ds$support_by_ward_raw <- (sb_ds$weighted_abc*abcweight) + (sb_ds$weighted_ctwode*ctwodeweight)
  
  sb_ds$percentage_ward <- sb_ds$support_by_ward_raw / (sb_ds$abcone + sb_ds$ctwode)
  
  sb_ds[3] <- NULL
  
  return(sb_ds)}

devtools::document()
colinberrygithub/andymacmillan documentation built on Aug. 3, 2022, 12:25 a.m.