Notes for updates 10/17/2023

  1. I have checked the false positive CIC “Community Integrated Care (CIC) - 2 Seafarers Walk” found in the 2019 dataset. It is NOT in the 2017 dataset
  2. Added data cleaning for dropping overlapping provider rating
  3. Drop certain rating categories as discussed

Setting up the R session and Loading packages

# environment setup to run ordered logit properly
options(contrasts = rep("contr.treatment", 2))

This chunk loads all the packages to use

#packages for ordered logit
library(ordinal) # package for ordinal logit regression
library(brant) # brant test for the parallel assumption for ordered logit
library(MASS) # models that work with the brant test

library(tidyverse) # package for data cleaning and plotting
library(readxl) # package for reading excel file
library(broom) # extracting model summary as data frame
library(modelsummary) # deriving model tables
library(scales) # label percent
library(lubridate) # working with dates
library(marginaleffects) #to calculate marginal effects

Import the cleaned data

merged <- read_csv("D:/Archive/Socialcare UK/data/spinout_2017.csv")

Prepare the data for ordinal regression

#select relevant columns, rename and relabel 
merged_cleaned <- merged %>% 
  # recode legal form types to be more readable / easier to present
  mutate(# inherited = ifelse(inherited == "Y", TRUE, FALSE),
         rating = recode(rating, 
                         "Insufficient evidence to rate" = "NA",
                         "Requires improvement" = "Req improv"),
         date = ymd(publication_date)) %>% 
  
  # assign order in the rating levels
  mutate(rating = ordered(rating, levels = c("Inadequate","Req improv", "Good", "Outstanding")),
         form_spinout = case_when(form == "GOV" ~ "GOV",
                           form == "CIC" & spin_out == "TRUE" ~ "SP_CIC",
                           form == "CIC" & spin_out == "FALSE" ~ "NSP_CIC"),
         socialcare = ifelse(type == "Social Care Org", TRUE, FALSE)) %>% 
  
  # creating a new dummy variable for facility category
  mutate(year = year(date),
         year2 = year-2013,
         Year = factor(year)) %>%
  
  # regroup care type

  mutate(service_type = case_when(
      str_detect(primary_cat, "Acute hospital") ~ "Acute hospital",
      str_detect(primary_cat, "Mental health") ~ "Mental health",
      TRUE ~ primary_cat  # Keep the original value if none of the conditions match
    )) %>%
  
  # drop unmatched service types
  filter(!service_type %in% c("Acute hospital", "Ambulance service", "Dentists", 
                              "Independent consulting doctors", "Prison Healthcare")) %>% 
  
  # drop overlapping provider data
  group_by(provider_name) %>% 
  mutate(overlap = ifelse(
    n() > 1 & level == "provider" & report_type == "Provider", "drop", "keep"
  )) %>%
  ungroup()  %>% 
  filter(overlap != "drop") %>% 
  
  # converting the ordinal variable to numerical 
  mutate(rating_num = case_when(rating == "Inadequate" ~ 1,
                                rating == "Req improv" ~ 2,
                                rating == "Good" ~ 3,
                                rating == "Outstanding" ~ 4)) 
# show first several rows of the data set derived 
nrow(merged_cleaned)
## [1] 11309
merged_cleaned %>% 
  group_by(form_spinout) %>% 
  summarize(count_provider = n_distinct(provider_name),
            count_rating = n())
## # A tibble: 3 × 3
##   form_spinout count_provider count_rating
##   <chr>                 <int>        <int>
## 1 GOV                     218         9785
## 2 NSP_CIC                  62          777
## 3 SP_CIC                   21          747

Overall distribution

datasummary(form_spinout + socialcare  + region + Year ~ 1, data = merged_cleaned, fmt = 0)
All
form_spinout GOV 9785
NSP_CIC 777
SP_CIC 747
socialcare FALSE 6257
TRUE 5052
region East Midlands 1120
East of England 1025
London 1338
North East 519
North West 1823
South East 1757
South West 1072
West Midlands 1176
Yorkshire and The Humber 1479
Year 2013 0
2014 492
2015 1447
2016 5085
2017 4285

Comparison table on Primary Inspection Category

datasummary(service_type  ~ form, data = merged_cleaned, fmt = 0)
service_type CIC GOV
Community based adult social care services 354 1944
Community health - NHS & Independent 264 846
GP Practices 546 203
Hospice services 12 6
Mental health 144 3930
Out of hours 6 6
Residential social care 186 2832
Urgent care services & mobile doctors 12 18
datasummary(service_type  ~ form_spinout, data = merged_cleaned, fmt = 0)
service_type GOV NSP_CIC SP_CIC
Community based adult social care services 1944 252 102
Community health - NHS & Independent 846 96 168
GP Practices 203 285 261
Hospice services 6 6 6
Mental health 3930 24 120
Out of hours 6 6 0
Residential social care 2832 102 84
Urgent care services & mobile doctors 18 6 6

whole models with continous year trend

Since service_type is inclusive of variation/information from socialcare and level, we drop this variable from the model

model_order_overall <- clm(rating ~ form_spinout  + service_type + region + year2,
                data = filter(merged_cleaned, domain == "Overall"),
                link = "logit")

model_order_safe <- clm(rating ~ form_spinout  + service_type+ region + year2,
                data = filter(merged_cleaned, domain == "Safe"),
                link = "logit")
model_order_effective <- clm(rating ~ form_spinout  + service_type + region + year2,
                data = filter(merged_cleaned, domain == "Effective"),
                link = "logit")
model_order_caring <- clm(rating ~ form_spinout  + service_type + region + year2,
                data = filter(merged_cleaned, domain == "Caring"),
                link = "logit")
model_order_well_led <- clm(rating ~ form_spinout + service_type + region + year2,
                data = filter(merged_cleaned, domain == "Well-led"),
                link = "logit")
model_order_responsive <- clm(rating ~ form_spinout + service_type + region + year2,
                data = filter(merged_cleaned, domain == "Responsive"),
                link = "logit")
ordinal_models <-
  modelsummary(
    list(
      "overall" = model_order_overall,
      "safe" = model_order_safe,
      "effective" = model_order_effective,
      "caring" = model_order_caring,
      "well-led" = model_order_well_led,
      "responsive" = model_order_responsive
    ),
    coef_omit = "region",
    exponentiate = F,
    statistic = "({p.value}) {stars}")
ordinal_models
overall safe effective caring well-led responsive
Inadequate|Req improv -6.494 -6.365 -6.484 -5.711 -5.687
(<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) ***
Req improv|Good -3.568 -3.018 -2.684 -3.690 -2.779 -2.640
(<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) ***
Good|Outstanding 1.252 3.821 2.982 3.384 2.251 2.695
(<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) ***
form_spinoutNSP_CIC 0.534 0.432 0.303 0.358 0.079 0.655
(0.011) * (0.146) (0.314) (0.350) (0.763) (0.033) *
form_spinoutSP_CIC 0.397 0.469 0.264 0.149 0.715 0.407
(0.063) + (0.105) (0.390) (0.708) (0.015) * (0.197)
service_typeCommunity health - NHS & Independent -1.107 -1.652 -0.907 1.262 -0.887 -1.011
(<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) ***
service_typeGP Practices 0.154 -0.282 1.028 0.508 0.854 -0.114
(0.453) (0.511) (0.017) * (0.337) (0.026) * (0.787)
service_typeHospice services 0.103 0.924 0.345 -0.027 0.519 -0.091
(0.945) (0.692) (0.848) (0.991) (0.737) (0.961)
service_typeMental health -0.682 -1.538 -0.762 0.866 -0.304 -0.598
(<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (0.065) + (0.001) **
service_typeOut of hours -1.487 -1.792 -3.836 -0.498 -1.431 0.137
(0.271) (0.196) (0.064) + (0.868) (0.291) (0.946)
service_typeResidential social care -0.363 -0.552 -0.398 -0.372 -0.422 -0.243
(0.031) * (0.005) ** (0.039) * (0.187) (0.013) * (0.210)
service_typeUrgent care services & mobile doctors 0.761 1.585 0.869 -0.436 0.960 0.253
(0.509) (0.378) (0.531) (0.816) (0.425) (0.844)
year2 -0.584 -0.370 -0.331 0.086 -0.385 -0.162
(<0.001) *** (<0.001) *** (<0.001) *** (0.426) (<0.001) *** (0.048) *
Num.Obs. 2198 1823 1820 1820 1824 1824
AIC 2936.7 2233.6 2014.0 1187.3 2409.7 2030.3
BIC 3056.3 2349.3 2129.7 1297.5 2525.4 2145.9
RMSE 2.28 2.12 2.18 1.28 2.22 2.23
ordinal_models_exp <-
  modelsummary(
    list(
      "overall" = model_order_overall,
      "safe" = model_order_safe,
      "effective" = model_order_effective,
      "caring" = model_order_caring,
      "well-led" = model_order_well_led,
      "responsive" = model_order_responsive
    ),
    coef_omit = "region",
    exponentiate = T,
    statistic = "({p.value}) {stars}")
ordinal_models_exp
overall safe effective caring well-led responsive
Inadequate|Req improv 0.002 0.002 0.002 0.003 0.003
(<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) ***
Req improv|Good 0.028 0.049 0.068 0.025 0.062 0.071
(<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) ***
Good|Outstanding 3.499 45.668 19.735 29.500 9.498 14.803
(<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) ***
form_spinoutNSP_CIC 1.706 1.541 1.354 1.431 1.082 1.925
(0.011) * (0.146) (0.314) (0.350) (0.763) (0.033) *
form_spinoutSP_CIC 1.487 1.599 1.302 1.160 2.044 1.502
(0.063) + (0.105) (0.390) (0.708) (0.015) * (0.197)
service_typeCommunity health - NHS & Independent 0.331 0.192 0.404 3.532 0.412 0.364
(<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) ***
service_typeGP Practices 1.166 0.754 2.797 1.662 2.350 0.892
(0.453) (0.511) (0.017) * (0.337) (0.026) * (0.787)
service_typeHospice services 1.108 2.518 1.412 0.974 1.681 0.913
(0.945) (0.692) (0.848) (0.991) (0.737) (0.961)
service_typeMental health 0.506 0.215 0.467 2.377 0.738 0.550
(<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (0.065) + (0.001) **
service_typeOut of hours 0.226 0.167 0.022 0.608 0.239 1.147
(0.271) (0.196) (0.064) + (0.868) (0.291) (0.946)
service_typeResidential social care 0.696 0.576 0.672 0.689 0.656 0.784
(0.031) * (0.005) ** (0.039) * (0.187) (0.013) * (0.210)
service_typeUrgent care services & mobile doctors 2.140 4.879 2.384 0.647 2.611 1.288
(0.509) (0.378) (0.531) (0.816) (0.425) (0.844)
year2 0.558 0.691 0.718 1.090 0.680 0.851
(<0.001) *** (<0.001) *** (<0.001) *** (0.426) (<0.001) *** (0.048) *
Num.Obs. 2198 1823 1820 1820 1824 1824
AIC 2936.7 2233.6 2014.0 1187.3 2409.7 2030.3
BIC 3056.3 2349.3 2129.7 1297.5 2525.4 2145.9
RMSE 2.28 2.12 2.18 1.28 2.22 2.23

Models with Year fixed effects

model_order_overall_fe <- clm(rating ~ form_spinout  + service_type + region + Year,
                data = filter(merged_cleaned, domain == "Overall"),
                link = "logit")

model_order_safe_fe <- clm(rating ~ form_spinout  + service_type + region + Year,
                data = filter(merged_cleaned, domain == "Safe"),
                link = "logit")
model_order_effective_fe <- clm(rating ~ form_spinout  + service_type + region + Year,
                data = filter(merged_cleaned, domain == "Effective"),
                link = "logit")
model_order_caring_fe <- clm(rating ~ form_spinout  + service_type + region + Year,
                data = filter(merged_cleaned, domain == "Caring"),
                link = "logit")
model_order_well_led_fe <- clm(rating ~ form_spinout + service_type + region + Year,
                data = filter(merged_cleaned, domain == "Well-led"),
                link = "logit")
model_order_responsive_fe <- clm(rating ~ form_spinout + service_type + region + Year,
                data = filter(merged_cleaned, domain == "Responsive"),
                link = "logit")
ordinal_models_fe <-
  modelsummary(
    list(
      "overall" = model_order_overall_fe,
      "safe" = model_order_safe_fe,
      "effective" = model_order_effective_fe,
      "caring" = model_order_caring_fe,
      "well-led" = model_order_well_led_fe,
      "responsive" = model_order_responsive_fe
    ),
    coef_omit = "region",
    exponentiate = F,
    statistic = "({p.value}) {stars}")
ordinal_models_fe
overall safe effective caring well-led responsive
Inadequate|Req improv -5.354 -5.617 -5.841 -4.821 -5.213
(<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) ***
Req improv|Good -2.422 -2.266 -2.041 -2.730 -1.886 -2.166
(<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) ***
Good|Outstanding 2.430 4.591 3.638 4.398 3.159 3.177
(<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) ***
form_spinoutNSP_CIC 0.573 0.458 0.303 0.417 0.095 0.673
(0.006) ** (0.125) (0.314) (0.279) (0.716) (0.029) *
form_spinoutSP_CIC 0.341 0.463 0.262 0.137 0.699 0.395
(0.111) (0.110) (0.393) (0.732) (0.017) * (0.210)
service_typeCommunity health - NHS & Independent -0.958 -1.574 -0.861 1.455 -0.785 -0.929
(<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) ***
service_typeGP Practices 0.236 -0.255 1.030 0.547 0.876 -0.087
(0.251) (0.553) (0.017) * (0.304) (0.022) * (0.837)
service_typeHospice services -0.054 0.856 0.348 -0.199 0.462 -0.154
(0.971) (0.714) (0.847) (0.935) (0.766) (0.935)
service_typeMental health -0.603 -1.516 -0.756 0.944 -0.271 -0.566
(<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (0.103) (0.002) **
service_typeOut of hours -1.318 -1.738 -3.844 -0.527 -1.431 0.134
(0.330) (0.210) (0.062) + (0.856) (0.291) (0.946)
service_typeResidential social care -0.308 -0.535 -0.401 -0.342 -0.409 -0.225
(0.069) + (0.006) ** (0.038) * (0.232) (0.016) * (0.248)
service_typeUrgent care services & mobile doctors 0.957 1.674 0.898 -0.230 1.055 0.343
(0.410) (0.353) (0.518) (0.903) (0.382) (0.791)
Year2015 -0.213 0.137 0.209 1.321 0.271 0.183
(0.504) (0.655) (0.558) (0.017) * (0.409) (0.601)
Year2016 -0.402 -0.250 -0.321 1.483 -0.168 0.082
(0.169) (0.361) (0.314) (0.005) ** (0.569) (0.796)
Year2017 -1.346 -0.764 -0.667 1.205 -0.695 -0.230
(<0.001) *** (0.005) ** (0.036) * (0.022) * (0.019) * (0.469)
Num.Obs. 2198 1823 1820 1820 1824 1824
AIC 2926.1 2233.5 2015.7 1182.3 2408.5 2032.0
BIC 3057.1 2360.2 2142.3 1303.4 2535.2 2158.7
RMSE 2.28 2.12 2.18 1.28 2.22 2.23
ordinal_models_fe_exp <-
  modelsummary(
    list(
      "overall" = model_order_overall_fe,
      "safe" = model_order_safe_fe,
      "effective" = model_order_effective_fe,
      "caring" = model_order_caring_fe,
      "well-led" = model_order_well_led_fe,
      "responsive" = model_order_responsive_fe
    ),
    coef_omit = "region",
    exponentiate = T,
    statistic = "({p.value}) {stars}")
ordinal_models_fe_exp
overall safe effective caring well-led responsive
Inadequate|Req improv 0.005 0.004 0.003 0.008 0.005
(<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) ***
Req improv|Good 0.089 0.104 0.130 0.065 0.152 0.115
(<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) ***
Good|Outstanding 11.354 98.561 38.021 81.269 23.545 23.985
(<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) ***
form_spinoutNSP_CIC 1.773 1.580 1.355 1.517 1.100 1.960
(0.006) ** (0.125) (0.314) (0.279) (0.716) (0.029) *
form_spinoutSP_CIC 1.406 1.590 1.299 1.147 2.012 1.484
(0.111) (0.110) (0.393) (0.732) (0.017) * (0.210)
service_typeCommunity health - NHS & Independent 0.383 0.207 0.423 4.285 0.456 0.395
(<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (<0.001) ***
service_typeGP Practices 1.266 0.775 2.800 1.727 2.402 0.917
(0.251) (0.553) (0.017) * (0.304) (0.022) * (0.837)
service_typeHospice services 0.947 2.353 1.416 0.819 1.587 0.857
(0.971) (0.714) (0.847) (0.935) (0.766) (0.935)
service_typeMental health 0.547 0.220 0.470 2.570 0.763 0.568
(<0.001) *** (<0.001) *** (<0.001) *** (<0.001) *** (0.103) (0.002) **
service_typeOut of hours 0.268 0.176 0.021 0.590 0.239 1.144
(0.330) (0.210) (0.062) + (0.856) (0.291) (0.946)
service_typeResidential social care 0.735 0.585 0.670 0.710 0.664 0.799
(0.069) + (0.006) ** (0.038) * (0.232) (0.016) * (0.248)
service_typeUrgent care services & mobile doctors 2.604 5.332 2.455 0.794 2.872 1.409
(0.410) (0.353) (0.518) (0.903) (0.382) (0.791)
Year2015 0.808 1.147 1.233 3.748 1.311 1.200
(0.504) (0.655) (0.558) (0.017) * (0.409) (0.601)
Year2016 0.669 0.779 0.725 4.405 0.845 1.086
(0.169) (0.361) (0.314) (0.005) ** (0.569) (0.796)
Year2017 0.260 0.466 0.513 3.335 0.499 0.794
(<0.001) *** (0.005) ** (0.036) * (0.022) * (0.019) * (0.469)
Num.Obs. 2198 1823 1820 1820 1824 1824
AIC 2926.1 2233.5 2015.7 1182.3 2408.5 2032.0
BIC 3057.1 2360.2 2142.3 1303.4 2535.2 2158.7
RMSE 2.28 2.12 2.18 1.28 2.22 2.23