From 4feb8980581872621d21357b78c2df32b14a736f Mon Sep 17 00:00:00 2001 From: Lextuga007 Date: Wed, 17 Apr 2024 15:49:53 +0100 Subject: [PATCH 1/2] Changed code to print 15 of 100 generated points --- imd.qmd | 84 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/imd.qmd b/imd.qmd index 2d5b9d7..81a5eee 100644 --- a/imd.qmd +++ b/imd.qmd @@ -79,7 +79,7 @@ To be able to join to the data scores will need to be put into quintiles (group ```{r} #| echo: false -#| tbl-subcap: +#| tbl-subcap: #| - "Deciles" #| - "Quintiles" #| - "Quartiles" @@ -89,36 +89,43 @@ library(gt) # decile -data.frame("Number after decimal point" = - c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8), - "Deciles receiving an extra area" = - c("None","1","1, 6","1, 4, 7","1, 3, 6, 8", - "1, 3, 5, 7, 9","1, 2, 4, 6, 7, 9", - "1, 2, 3, 5, 6, 8, 9","1, 2, 3, 4, 6, 7, 8, 9"), - check.names = F) |> +data.frame( + "Number after decimal point" = + c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8), + "Deciles receiving an extra area" = + c( + "None", "1", "1, 6", "1, 4, 7", "1, 3, 6, 8", + "1, 3, 5, 7, 9", "1, 2, 4, 6, 7, 9", + "1, 2, 3, 5, 6, 8, 9", "1, 2, 3, 4, 6, 7, 8, 9" + ), + check.names = F +) |> gt() |> tab_header(title = md("Deciles")) # quintile -data.frame("Number after decimal point" = - c(0,0.2,0.4,0.6,0.8), - "Quintiles receiving an extra area" = - c("None","1","1, 3","1, 2, 4","1, 2, 3, 4"), - check.names = F) |> +data.frame( + "Number after decimal point" = + c(0, 0.2, 0.4, 0.6, 0.8), + "Quintiles receiving an extra area" = + c("None", "1", "1, 3", "1, 2, 4", "1, 2, 3, 4"), + check.names = F +) |> gt() |> tab_header(title = md("Quintiles")) # quantile -data.frame("Number after decimal point" = - c(0,0.25,0.5,0.75), - "Quantiles receiving an extra area" = - c("None","1","1, 3","1, 2, 3"), - check.names = F) |> +data.frame( + "Number after decimal point" = + c(0, 0.25, 0.5, 0.75), + "Quantiles receiving an extra area" = + c("None", "1", "1, 3", "1, 2, 3"), + check.names = F +) |> gt() |> tab_header(title = md("Quantiles")) - ``` ### Quintiles in SQL @@ -148,14 +155,18 @@ library(PHEindicatormethods) #| label: r-quintile df <- data.frame( - region = as.character(rep(c("Region1","Region2","Region3","Region4"), - each=250)), - smallarea = as.character(paste0("Area",seq_along(1:1000))), + region = as.character(rep(c("Region1", "Region2", "Region3", "Region4"), + each = 250 + )), + smallarea = as.character(paste0("Area", seq_along(1:1000))), vals = as.numeric(sample(200, 1000, replace = TRUE)), - stringsAsFactors = FALSE) + stringsAsFactors = FALSE +) # assign small areas to deciles across whole data frame -PHEindicatormethods::phe_quantile(df, vals, type = "standard") +# print the top 15 +PHEindicatormethods::phe_quantile(df, vals, type = "standard") |> + dplyr::slice_head(n = 15) ``` # Creating local IMDs @@ -193,14 +204,17 @@ tibble_postcodes <- dplyr::tibble( random_postcodes = postcodes, ) -NHSRpopulation::get_data(tibble_postcodes, - column = "random_postcodes", - url_type = "imd") |> - dplyr::select(random_postcodes, - new_postcode, - imd_decile, - imd_rank, - imd_score) |> +NHSRpopulation::get_data(tibble_postcodes, + column = "random_postcodes", + url_type = "imd" +) |> + dplyr::select( + random_postcodes, + new_postcode, + imd_decile, + imd_rank, + imd_score + ) |> mutate(imd_decile_local = ntile(-imd_score, n = 10)) # creating new deciles from the data provided ``` @@ -234,14 +248,14 @@ la_code_notts_county <- tibble::tribble( "E01013810", "Nottingham 018A", "E06000018", "Nottingham", "E01013811", "Nottingham 018B", "E06000018", "Nottingham", "E01013815", "Nottingham 022C", "E06000018", "Nottingham" -) |> - dplyr::select(LSOAcode2011) |> +) |> + dplyr::select(LSOAcode2011) |> dplyr::pull() # Combine all districts into one object la_code_nott_city_notts_county <- c(la_code_nott_city, la_code_notts_county) -la_code_nott_city_notts_county +la_code_nott_city_notts_county ``` # Other useful links From 36540f62f32cfa4e3821f20558ab3705a75d9c80 Mon Sep 17 00:00:00 2001 From: Lextuga007 Date: Wed, 17 Apr 2024 15:51:27 +0100 Subject: [PATCH 2/2] Set the local IMD creation chunk to eval: true --- imd.qmd | 1 - 1 file changed, 1 deletion(-) diff --git a/imd.qmd b/imd.qmd index 81a5eee..525f7b2 100644 --- a/imd.qmd +++ b/imd.qmd @@ -181,7 +181,6 @@ To apply a rank use the windows partition function `ROW_NUMBER() OVER(ORDER BY I ```{r} #| label: localRank -#| eval: false library(tidyverse) library(PostcodesioR)