Utentes rastreadas
setwd("C:/Users/patricia.soares/OneDrive - SPMS - Serviços Partilhados do Ministério da Saúde, EPE/Supervision/PhD/Rita Sousa/CITS")
library(readxl)
## Warning: package 'readxl' was built under R version 4.2.3
library(MASS)
library(lmtest)
## Warning: package 'lmtest' was built under R version 4.2.3
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.2.3
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.2.3
##
## Attaching package: 'dplyr'
## The following object is masked from 'package:MASS':
##
## select
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(gtsummary)
## Warning: package 'gtsummary' was built under R version 4.2.3
##
## Attaching package: 'gtsummary'
## The following object is masked from 'package:MASS':
##
## select
library(ggplot2)
data <- read_excel("ARS_Agregados.xlsx", sheet = "base_semestre")
# change reference
data$Impacto_Covid <- relevel(as.factor(data$Impacto_Covid), ref = "pre-pandemic")
data$Grupo <- relevel(as.factor(data$Grupo), ref = "RCCU")
m_level <- glm(Utentes_rastreadas ~ time + Level + Impacto_Covid + Grupo +
Grupo:Level, offset = log(Populacao_elegivel),
family = poisson(link = "log"),
data = data)
summary(m_level)
##
## Call:
## glm(formula = Utentes_rastreadas ~ time + Level + Impacto_Covid +
## Grupo + Grupo:Level, family = poisson(link = "log"), data = data,
## offset = log(Populacao_elegivel))
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -52.920 -14.572 -1.639 14.744 44.268
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.9471885 0.0025917 -365.48 <2e-16
## time 0.0234560 0.0003238 72.44 <2e-16
## Level -0.2341201 0.0047441 -49.35 <2e-16
## Impacto_Covidnormalization 0.1436759 0.0046904 30.63 <2e-16
## Impacto_Covidsuspension_partial_recovery -0.1624949 0.0044306 -36.68 <2e-16
## GrupoRCM 0.3938538 0.0021536 182.88 <2e-16
## Level:GrupoRCM -0.0655087 0.0034391 -19.05 <2e-16
##
## (Intercept) ***
## time ***
## Level ***
## Impacto_Covidnormalization ***
## Impacto_Covidsuspension_partial_recovery ***
## GrupoRCM ***
## Level:GrupoRCM ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 100034 on 39 degrees of freedom
## Residual deviance: 22471 on 33 degrees of freedom
## AIC: 22978
##
## Number of Fisher Scoring iterations: 4
# check for overdispersion
dispersion <- sum(residuals(m_level, type = "pearson")^2) / m_level$df.residual
dispersion
## [1] 678.9591
m_level_nb <- glm.nb(Utentes_rastreadas ~ time + Level + Impacto_Covid + Grupo +
Grupo:Level, offset(log(Populacao_elegivel)),
data = data)
summary(m_level_nb)
##
## Call:
## glm.nb(formula = Utentes_rastreadas ~ time + Level + Impacto_Covid +
## Grupo + Grupo:Level, data = data, weights = offset(log(Populacao_elegivel)),
## init.theta = 40.3590969, link = log)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -10.9377 -2.0776 0.1249 2.3262 5.2365
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 10.385788 0.023087 449.854 < 2e-16
## time 0.002374 0.003040 0.781 0.4350
## Level -0.148711 0.042007 -3.540 0.0004
## Impacto_Covidnormalization 0.023225 0.042196 0.550 0.5820
## Impacto_Covidsuspension_partial_recovery -0.276439 0.038037 -7.268 3.66e-13
## GrupoRCM 0.393955 0.020063 19.636 < 2e-16
## Level:GrupoRCM -0.002049 0.030067 -0.068 0.9457
##
## (Intercept) ***
## time
## Level ***
## Impacto_Covidnormalization
## Impacto_Covidsuspension_partial_recovery ***
## GrupoRCM ***
## Level:GrupoRCM
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for Negative Binomial(40.3591) family taken to be 1)
##
## Null deviance: 1566.82 on 39 degrees of freedom
## Residual deviance: 446.32 on 33 degrees of freedom
## AIC: 8951.2
##
## Number of Fisher Scoring iterations: 1
##
##
## Theta: 40.36
## Std. Err.: 2.70
##
## 2 x log-likelihood: -8935.205
lrtest(m_level, m_level_nb)
## Likelihood ratio test
##
## Model 1: Utentes_rastreadas ~ time + Level + Impacto_Covid + Grupo + Grupo:Level
## Model 2: Utentes_rastreadas ~ time + Level + Impacto_Covid + Grupo + Grupo:Level
## #Df LogLik Df Chisq Pr(>Chisq)
## 1 7 -11482.0
## 2 8 -4467.6 1 14029 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
tbl_regression(m_level_nb, exponentiate = TRUE)
| Characteristic |
IRR |
95% CI |
p-value |
| time |
1.00 |
1.00, 1.01 |
0.4 |
| Level |
0.86 |
0.79, 0.94 |
<0.001 |
| Impacto_Covid |
|
|
|
| pre-pandemic |
— |
— |
|
| normalization |
1.02 |
0.94, 1.11 |
0.6 |
| suspension_partial_recovery |
0.76 |
0.70, 0.82 |
<0.001 |
| Grupo |
|
|
|
| RCCU |
— |
— |
|
| RCM |
1.48 |
1.43, 1.54 |
<0.001 |
| Level * Grupo |
|
|
|
| Level * RCM |
1.00 |
0.94, 1.06 |
>0.9 |
m_slope <- glm(Utentes_rastreadas ~ time + Level + Impacto_Covid + Grupo +
Tempo_after + Grupo:Level + Grupo:Tempo_after,
offset = log(Populacao_elegivel),
family = poisson(link = "log"),
data = data)
summary(m_slope)
##
## Call:
## glm(formula = Utentes_rastreadas ~ time + Level + Impacto_Covid +
## Grupo + Tempo_after + Grupo:Level + Grupo:Tempo_after, family = poisson(link = "log"),
## data = data, offset = log(Populacao_elegivel))
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -42.781 -14.370 -1.168 18.031 40.319
##
## Coefficients:
## Estimate Std. Error z value
## (Intercept) -0.9301250 0.0026384 -352.531
## time 0.0206696 0.0003353 61.654
## Level -0.2168783 0.0052822 -41.059
## Impacto_Covidnormalization -0.1065658 0.0091370 -11.663
## Impacto_Covidsuspension_partial_recovery -0.2614362 0.0054338 -48.113
## GrupoRCM 0.3932726 0.0021536 182.610
## Tempo_after 0.0421444 0.0014738 28.595
## Level:GrupoRCM -0.0665974 0.0055103 -12.086
## GrupoRCM:Tempo_after -0.0008049 0.0010350 -0.778
## Pr(>|z|)
## (Intercept) <2e-16 ***
## time <2e-16 ***
## Level <2e-16 ***
## Impacto_Covidnormalization <2e-16 ***
## Impacto_Covidsuspension_partial_recovery <2e-16 ***
## GrupoRCM <2e-16 ***
## Tempo_after <2e-16 ***
## Level:GrupoRCM <2e-16 ***
## GrupoRCM:Tempo_after 0.437
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 100034 on 39 degrees of freedom
## Residual deviance: 21439 on 31 degrees of freedom
## AIC: 21950
##
## Number of Fisher Scoring iterations: 4
# check for overdispersion
dispersion <- sum(residuals(m_slope, type = "pearson")^2) / m_slope$df.residual
dispersion
## [1] 685.9618
m_slope_nb <- glm.nb(Utentes_rastreadas ~ time + Level + Impacto_Covid +
Grupo + Tempo_after + Grupo:Level +
Grupo:Tempo_after, offset(log(Populacao_elegivel)),
data = data)
summary(m_slope_nb)
##
## Call:
## glm.nb(formula = Utentes_rastreadas ~ time + Level + Impacto_Covid +
## Grupo + Tempo_after + Grupo:Level + Grupo:Tempo_after, data = data,
## weights = offset(log(Populacao_elegivel)), init.theta = 49.19033743,
## link = log)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -9.3908 -2.3702 0.1774 2.5049 6.4417
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 10.3975115 0.0214860 483.920 < 2e-16
## time 0.0004438 0.0028739 0.154 0.877
## Level 0.0201131 0.0413799 0.486 0.627
## Impacto_Covidnormalization -0.0984990 0.0710496 -1.386 0.166
## Impacto_Covidsuspension_partial_recovery -0.3252496 0.0414720 -7.843 4.41e-15
## GrupoRCM 0.3935560 0.0181753 21.653 < 2e-16
## Tempo_after -0.0198970 0.0108224 -1.839 0.066
## Level:GrupoRCM -0.3202176 0.0414778 -7.720 1.16e-14
## GrupoRCM:Tempo_after 0.0795820 0.0078660 10.117 < 2e-16
##
## (Intercept) ***
## time
## Level
## Impacto_Covidnormalization
## Impacto_Covidsuspension_partial_recovery ***
## GrupoRCM ***
## Tempo_after .
## Level:GrupoRCM ***
## GrupoRCM:Tempo_after ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for Negative Binomial(49.1903) family taken to be 1)
##
## Null deviance: 1909.17 on 39 degrees of freedom
## Residual deviance: 446.02 on 31 degrees of freedom
## AIC: 8866.8
##
## Number of Fisher Scoring iterations: 1
##
##
## Theta: 49.19
## Std. Err.: 3.29
##
## 2 x log-likelihood: -8846.75
lrtest(m_slope, m_slope_nb)
## Likelihood ratio test
##
## Model 1: Utentes_rastreadas ~ time + Level + Impacto_Covid + Grupo + Tempo_after +
## Grupo:Level + Grupo:Tempo_after
## Model 2: Utentes_rastreadas ~ time + Level + Impacto_Covid + Grupo + Tempo_after +
## Grupo:Level + Grupo:Tempo_after
## #Df LogLik Df Chisq Pr(>Chisq)
## 1 9 -10966.0
## 2 10 -4423.4 1 13085 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
tbl_regression(m_slope_nb, exponentiate = TRUE)
| Characteristic |
IRR |
95% CI |
p-value |
| time |
1.00 |
1.0, 1.01 |
0.9 |
| Level |
1.02 |
0.94, 1.11 |
0.6 |
| Impacto_Covid |
|
|
|
| pre-pandemic |
— |
— |
|
| normalization |
0.91 |
0.79, 1.04 |
0.2 |
| suspension_partial_recovery |
0.72 |
0.66, 0.79 |
<0.001 |
| Grupo |
|
|
|
| RCCU |
— |
— |
|
| RCM |
1.48 |
1.43, 1.54 |
<0.001 |
| Tempo_after |
0.98 |
0.96, 1.00 |
0.066 |
| Level * Grupo |
|
|
|
| Level * RCM |
0.73 |
0.67, 0.79 |
<0.001 |
| Grupo * Tempo_after |
|
|
|
| RCM * Tempo_after |
1.08 |
1.07, 1.10 |
<0.001 |
Testes positivos
m_level <- glm(Utentes_rastreadas ~ time + Level + Impacto_Covid + Grupo +
Grupo:Level, offset = log(Utentes_rastreadas),
family = poisson(link = "log"),
data = data)
summary(m_level)
##
## Call:
## glm(formula = Utentes_rastreadas ~ time + Level + Impacto_Covid +
## Grupo + Grupo:Level, family = poisson(link = "log"), data = data,
## offset = log(Utentes_rastreadas))
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.692e-06 0.000e+00 0.000e+00 1.478e-06 2.691e-06
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 2.965e-16 2.579e-03 0 1
## time -1.327e-17 3.232e-04 0 1
## Level -6.332e-16 4.777e-03 0 1
## Impacto_Covidnormalization 6.401e-16 4.678e-03 0 1
## Impacto_Covidsuspension_partial_recovery 4.233e-16 4.439e-03 0 1
## GrupoRCM -3.095e-17 2.153e-03 0 1
## Level:GrupoRCM -9.586e-17 3.440e-03 0 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 2.6433e-11 on 39 degrees of freedom
## Residual deviance: 2.6433e-11 on 33 degrees of freedom
## AIC: 506.56
##
## Number of Fisher Scoring iterations: 2
# check for overdispersion
dispersion <- sum(residuals(m_level, type = "pearson")^2) / m_level$df.residual
dispersion
## [1] 1.256156e-26
m_level_nb <- glm.nb(Teste_positivo ~ time + Level + Impacto_Covid + Grupo +
Grupo:Level, offset(log(Utentes_rastreadas)),
data = data)
summary(m_level_nb)
##
## Call:
## glm.nb(formula = Teste_positivo ~ time + Level + Impacto_Covid +
## Grupo + Grupo:Level, data = data, weights = offset(log(Utentes_rastreadas)),
## init.theta = 18.30560012, link = log)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -8.3711 -2.5579 0.0334 2.4133 6.7713
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 7.725806 0.035601 217.012 < 2e-16
## time -0.006000 0.004664 -1.286 0.198277
## Level -0.242554 0.064863 -3.739 0.000184
## Impacto_Covidnormalization 0.323400 0.064930 4.981 6.33e-07
## Impacto_Covidsuspension_partial_recovery -0.049752 0.058833 -0.846 0.397748
## GrupoRCM -0.275229 0.030778 -8.942 < 2e-16
## Level:GrupoRCM 0.124190 0.046208 2.688 0.007196
##
## (Intercept) ***
## time
## Level ***
## Impacto_Covidnormalization ***
## Impacto_Covidsuspension_partial_recovery
## GrupoRCM ***
## Level:GrupoRCM **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for Negative Binomial(18.3056) family taken to be 1)
##
## Null deviance: 638.23 on 39 degrees of freedom
## Residual deviance: 423.05 on 33 degrees of freedom
## AIC: 6260.2
##
## Number of Fisher Scoring iterations: 1
##
##
## Theta: 18.31
## Std. Err.: 1.27
##
## 2 x log-likelihood: -6244.166
lrtest(m_level, m_level_nb)
## Likelihood ratio test
##
## Model 1: Utentes_rastreadas ~ time + Level + Impacto_Covid + Grupo + Grupo:Level
## Model 2: Teste_positivo ~ time + Level + Impacto_Covid + Grupo + Grupo:Level
## #Df LogLik Df Chisq Pr(>Chisq)
## 1 7 -246.28
## 2 8 -3122.08 1 5751.6 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
tbl_regression(m_level_nb, exponentiate = TRUE)
| Characteristic |
IRR |
95% CI |
p-value |
| time |
0.99 |
0.98, 1.00 |
0.2 |
| Level |
0.78 |
0.69, 0.89 |
<0.001 |
| Impacto_Covid |
|
|
|
| pre-pandemic |
— |
— |
|
| normalization |
1.38 |
1.22, 1.57 |
<0.001 |
| suspension_partial_recovery |
0.95 |
0.85, 1.07 |
0.4 |
| Grupo |
|
|
|
| RCCU |
— |
— |
|
| RCM |
0.76 |
0.71, 0.81 |
<0.001 |
| Level * Grupo |
|
|
|
| Level * RCM |
1.13 |
1.03, 1.24 |
0.007 |
m_slope <- glm(Teste_positivo ~ time + Level + Impacto_Covid + Grupo +
Tempo_after + Grupo:Level + Grupo:Tempo_after,
offset = log(Utentes_rastreadas),
family = poisson(link = "log"),
data = data)
summary(m_slope)
##
## Call:
## glm(formula = Teste_positivo ~ time + Level + Impacto_Covid +
## Grupo + Tempo_after + Grupo:Level + Grupo:Tempo_after, family = poisson(link = "log"),
## data = data, offset = log(Utentes_rastreadas))
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -13.5702 -6.1460 -0.9891 5.3535 19.0200
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -2.614809 0.011184 -233.802 < 2e-16
## time -0.015641 0.001539 -10.166 < 2e-16
## Level -0.019682 0.023211 -0.848 0.396
## Impacto_Covidnormalization 0.231161 0.039986 5.781 7.42e-09
## Impacto_Covidsuspension_partial_recovery 0.178691 0.025011 7.144 9.03e-13
## GrupoRCM -0.674634 0.009823 -68.679 < 2e-16
## Tempo_after 0.011933 0.006219 1.919 0.055
## Level:GrupoRCM 0.103096 0.025255 4.082 4.46e-05
## GrupoRCM:Tempo_after 0.005665 0.004643 1.220 0.222
##
## (Intercept) ***
## time ***
## Level
## Impacto_Covidnormalization ***
## Impacto_Covidsuspension_partial_recovery ***
## GrupoRCM ***
## Tempo_after .
## Level:GrupoRCM ***
## GrupoRCM:Tempo_after
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 9443.3 on 39 degrees of freedom
## Residual deviance: 2024.4 on 31 degrees of freedom
## AIC: 2414.6
##
## Number of Fisher Scoring iterations: 4
# check for overdispersion
dispersion <- sum(residuals(m_slope, type = "pearson")^2) / m_slope$df.residual
dispersion
## [1] 66.56706
m_slope_nb <- glm.nb(Teste_positivo ~ time + Level + Impacto_Covid +
Grupo + Tempo_after + Grupo:Level +
Grupo:Tempo_after, offset(log(Utentes_rastreadas)),
data = data)
summary(m_slope_nb)
##
## Call:
## glm.nb(formula = Teste_positivo ~ time + Level + Impacto_Covid +
## Grupo + Tempo_after + Grupo:Level + Grupo:Tempo_after, data = data,
## weights = offset(log(Utentes_rastreadas)), init.theta = 20.47539043,
## link = log)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -7.1830 -2.6995 0.2846 2.3417 7.2832
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 7.741086 0.034588 223.810 < 2e-16
## time -0.008704 0.004603 -1.891 0.058638
## Level -0.076053 0.066998 -1.135 0.256310
## Impacto_Covidnormalization 0.179150 0.114256 1.568 0.116888
## Impacto_Covidsuspension_partial_recovery -0.085163 0.067106 -1.269 0.204410
## GrupoRCM -0.273452 0.029118 -9.391 < 2e-16
## Tempo_after -0.016000 0.017432 -0.918 0.358695
## Level:GrupoRCM -0.250915 0.067131 -3.738 0.000186
## GrupoRCM:Tempo_after 0.092082 0.012655 7.276 3.43e-13
##
## (Intercept) ***
## time .
## Level
## Impacto_Covidnormalization
## Impacto_Covidsuspension_partial_recovery
## GrupoRCM ***
## Tempo_after
## Level:GrupoRCM ***
## GrupoRCM:Tempo_after ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for Negative Binomial(20.4754) family taken to be 1)
##
## Null deviance: 712.96 on 39 degrees of freedom
## Residual deviance: 422.51 on 31 degrees of freedom
## AIC: 6216.8
##
## Number of Fisher Scoring iterations: 1
##
##
## Theta: 20.48
## Std. Err.: 1.42
##
## 2 x log-likelihood: -6196.82
lrtest(m_slope, m_slope_nb)
## Likelihood ratio test
##
## Model 1: Teste_positivo ~ time + Level + Impacto_Covid + Grupo + Tempo_after +
## Grupo:Level + Grupo:Tempo_after
## Model 2: Teste_positivo ~ time + Level + Impacto_Covid + Grupo + Tempo_after +
## Grupo:Level + Grupo:Tempo_after
## #Df LogLik Df Chisq Pr(>Chisq)
## 1 9 -1198.3
## 2 10 -3098.4 1 3800.2 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
tbl_regression(m_slope_nb, exponentiate = TRUE)
| Characteristic |
IRR |
95% CI |
p-value |
| time |
0.99 |
0.98, 1.00 |
0.059 |
| Level |
0.93 |
0.81, 1.06 |
0.3 |
| Impacto_Covid |
|
|
|
| pre-pandemic |
— |
— |
|
| normalization |
1.20 |
0.95, 1.50 |
0.12 |
| suspension_partial_recovery |
0.92 |
0.80, 1.05 |
0.2 |
| Grupo |
|
|
|
| RCCU |
— |
— |
|
| RCM |
0.76 |
0.72, 0.81 |
<0.001 |
| Tempo_after |
0.98 |
0.95, 1.02 |
0.4 |
| Level * Grupo |
|
|
|
| Level * RCM |
0.78 |
0.68, 0.89 |
<0.001 |
| Grupo * Tempo_after |
|
|
|
| RCM * Tempo_after |
1.10 |
1.07, 1.13 |
<0.001 |