Skip to content

Commit

Permalink
Merge pull request #78 from nhs-r-community/77-reduce-output
Browse files Browse the repository at this point in the history
77 reduce output
  • Loading branch information
Lextuga007 authored Apr 17, 2024
2 parents 5c9ad1b + 36540f6 commit 45d6338
Showing 1 changed file with 49 additions and 36 deletions.
85 changes: 49 additions & 36 deletions imd.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -170,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)
Expand All @@ -193,14 +203,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
```

Expand Down Expand Up @@ -234,14 +247,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
Expand Down

0 comments on commit 45d6338

Please sign in to comment.