knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
## Warning: package 'ggplot2' was built under R version 4.4.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 4.0.0 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(knitr)
library(data.table)
## Warning: package 'data.table' was built under R version 4.4.3
##
## Adjuntando el paquete: 'data.table'
##
## The following objects are masked from 'package:lubridate':
##
## hour, isoweek, mday, minute, month, quarter, second, wday, week,
## yday, year
##
## The following objects are masked from 'package:dplyr':
##
## between, first, last
##
## The following object is masked from 'package:purrr':
##
## transpose
library(haven)
library(geepack)
## Warning: package 'geepack' was built under R version 4.4.3
library(corrplot)
## Warning: package 'corrplot' was built under R version 4.4.3
## corrplot 0.95 loaded
library(psych)
## Warning: package 'psych' was built under R version 4.4.3
##
## Adjuntando el paquete: 'psych'
##
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
#library(sjPlot) opcional para ver resultados = tab_model(modelo)
library(kableExtra)
## Warning: package 'kableExtra' was built under R version 4.4.3
##
## Adjuntando el paquete: 'kableExtra'
##
## The following object is masked from 'package:dplyr':
##
## group_rows
options(scipen=999, digits=3)
library(readxl)
TITO <- read_excel("C:/Users/Administrador/Downloads/TITO.xlsx",
sheet = "Hoja1")
View(TITO)
N y porcentaje de sexo
table1=table(TITO$sexo)
table1
##
## F M
## 26 9
prop.table(table1)
##
## F M
## 0.743 0.257
Media de edad
describe(TITO$edad)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 35 57.9 13.5 56 58.4 14.8 32 78 46 -0.11 -1.11 2.28
sd(TITO$edad)
## [1] 13.5
Superficie
describe(TITO$SUP)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 35 40.1 44 24 32 17.8 6 160 154 1.59 1.33 7.44
median(TITO$SUP)
## [1] 24
quantile(TITO$SUP,0.25)
## 25%
## 13.5
quantile(TITO$SUP,0.75)
## 75%
## 42
Frecuencias tipo de úlcera
table2=table(TITO$dx)
table2
##
## AR DBT HTA HTV IG LES MARTORELL
## 12 6 1 3 1 6 1
## TRAUMATICA VASC
## 1 4
prop.table(table2)
##
## AR DBT HTA HTV IG LES MARTORELL
## 0.3429 0.1714 0.0286 0.0857 0.0286 0.1714 0.0286
## TRAUMATICA VASC
## 0.0286 0.1143
Gráfico
freq <- c(
AR = 0.3429,
DBT = 0.1714,
HTA = 0.0286,
HTV = 0.0857,
IG = 0.0286,
LES = 0.1714,
MARTORELL = 0.0286,
TRAUMATICA = 0.0286,
VASC = 0.1143
)
df <- data.frame(
causa = names(freq),
frecuencia = freq
)
library(ggplot2)
ggplot(df, aes(x = reorder(causa, -frecuencia), y = frecuencia)) +
geom_col(fill = "#2C7FB8") +
geom_text(
aes(label = scales::percent(frecuencia, accuracy = 0.1)),
vjust = -0.3,
size = 4
) +
scale_y_continuous(labels = scales::percent_format(accuracy = 1)) +
labs(
x = "EtiologÃa",
y = "Frecuencia relativa",
title = "Distribución de etiologÃas"
) +
theme_minimal(base_size = 14)
ggplot(df, aes(x = reorder(causa, frecuencia), y = frecuencia)) +
geom_col(fill = "#2C7FB8") +
geom_text(
aes(label = scales::percent(frecuencia, accuracy = 0.1)),
hjust = -0.1,
size = 4
) +
scale_y_continuous(labels = scales::percent_format(accuracy = 1)) +
coord_flip() +
labs(
x = "EtiologÃa",
y = "Frecuencia relativa"
) +
theme_minimal(base_size = 14)
Evaluación de EVA
describe(TITO$EVA_0)
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 35 8.59 1.17 9 8.67 1.48 6 10 4 -0.47 -0.65 0.2
median(TITO$EVA_0)
## [1] 9
quantile(TITO$EVA_0,0.25)
## 25%
## 8
quantile(TITO$EVA_0,0.75)
## 75%
## 9.5
Modelo longitudinal
library(tidyverse)
library(knitr)
library(data.table)
library(haven)
library(lme4)
## Cargando paquete requerido: Matrix
##
## Adjuntando el paquete: 'Matrix'
## The following objects are masked from 'package:tidyr':
##
## expand, pack, unpack
library(geepack)
library(corrplot)
library(psych)
library(sjPlot)
##
## Adjuntando el paquete: 'sjPlot'
## The following object is masked from 'package:ggplot2':
##
## set_theme
library(broom.mixed)
## Warning: package 'broom.mixed' was built under R version 4.4.3
library(lmerTest)
## Warning: package 'lmerTest' was built under R version 4.4.3
##
## Adjuntando el paquete: 'lmerTest'
## The following object is masked from 'package:lme4':
##
## lmer
## The following object is masked from 'package:stats':
##
## step
library(marginaleffects)
## Warning: package 'marginaleffects' was built under R version 4.4.3
library(stevemisc) # instalar si quieren pero es solo para gráficos no muy útiles
## Warning: package 'stevemisc' was built under R version 4.4.3
##
## Adjuntando el paquete: 'stevemisc'
## The following object is masked from 'package:lubridate':
##
## dst
## The following object is masked from 'package:dplyr':
##
## tbl_df
library(kableExtra)
Paso a base long
TITO_long <- TITO %>%
pivot_longer(
cols = starts_with("EVA"), # las columans que empiecen con
names_to = "PERIOD", # nueva columna a las que le voy a pasar el periodo de tiempo
names_prefix = "EVA_", # El valor que le voy a asignar a PERIOD es el que sigue a este prefijo
values_to = "EVA" # valores de TAS
)
TITO_long$PERIOD <- as.numeric(TITO_long$PERIOD)
Gráfico de correlación
corrplot.mixed(cor(TITO[,c(6, 7, 8, 9)], use = "pairwise.complete"), lower = "number", upper = "circle", title = "Correlacion Valores de dolor")
Tendencia por sexo
g1 <- TITO_long %>% group_by(factor(PERIOD), sexo) %>%
mutate(meanEVA = mean(EVA, na.rm = TRUE)) %>% ungroup() %>% # ordenamos
ggplot(aes(x =PERIOD, y = meanEVA))+ #graficamos
geom_point(aes(colour =sexo)) + geom_line(aes(colour=sexo), size =1) +
theme_classic()+ ggtitle("Tendencia EVA por SEXO") +
labs(x = "Periodo", y = "media EVA")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
g1
Modelo ajustado por edad y sexo Modelo de regresión lineal asumiendo
DEPENDENCIA (correlación no estructurada) con tiempo como variable
categórica (factor(PERIOD))
mod_gee2 <- geeglm(EVA ~ factor(PERIOD) ,
data = TITO_long,
id = TITO_long$SUP,
family = gaussian,
corstr = "unstructured")
tab_model(mod_gee2)
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Converting into numeric values currently not possible for variables of
## class 'NULL'.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
| Â | Dependent variable | ||
|---|---|---|---|
| Predictors | Estimates | CI | p |
| (Intercept) | 8.59 | 8.20 – 8.97 | <0.001 |
| factor(PERIOD)7 | -7.53 | -8.12 – -6.94 | <0.001 |
| factor(PERIOD)30 | -7.56 | -8.35 – -6.77 | <0.001 |
| factor(PERIOD)90 | -8.26 | -8.69 – -7.83 | <0.001 |
| Observations | 140 | ||
mod_gee2
##
## Call:
## geeglm(formula = EVA ~ factor(PERIOD), family = gaussian, data = TITO_long,
## id = TITO_long$SUP, corstr = "unstructured")
##
## Coefficients:
## (Intercept) factor(PERIOD)7 factor(PERIOD)30 factor(PERIOD)90
## 8.59 -7.53 -7.56 -8.26
##
## Degrees of Freedom: 140 Total (i.e. Null); 136 Residual
##
## Scale Link: identity
## Estimated Scale Parameters: [1] 2.02
##
## Correlation: Structure = unstructured Link = identity
## Estimated Correlation Parameters:
## alpha.1:2 alpha.1:3 alpha.1:4 alpha.2:3 alpha.2:4 alpha.3:4
## 0.2099 -0.1286 -0.0352 0.0417 0.0190 -0.0684
##
## Number of clusters: 35 Maximum cluster size: 4
Ajustando por sexo y edad
mod_gee3 <- geeglm(EVA ~ factor(PERIOD) + edad ,
data = TITO_long,
id = TITO_long$SUP,
family = gaussian,
corstr = "unstructured")
tab_model(mod_gee3)
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Converting into numeric values currently not possible for variables of
## class 'NULL'.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
| Â | Dependent variable | ||
|---|---|---|---|
| Predictors | Estimates | CI | p |
| (Intercept) | 7.04 | 5.80 – 8.29 | <0.001 |
| factor(PERIOD)7 | -7.53 | -8.12 – -6.94 | <0.001 |
| factor(PERIOD)30 | -7.56 | -8.35 – -6.77 | <0.001 |
| factor(PERIOD)90 | -8.26 | -8.69 – -7.83 | <0.001 |
| edad | 0.03 | 0.01 – 0.05 | 0.008 |
| Observations | 140 | ||
mod_gee3
##
## Call:
## geeglm(formula = EVA ~ factor(PERIOD) + edad, family = gaussian,
## data = TITO_long, id = TITO_long$SUP, corstr = "unstructured")
##
## Coefficients:
## (Intercept) factor(PERIOD)7 factor(PERIOD)30 factor(PERIOD)90
## 7.0425 -7.5286 -7.5571 -8.2571
## edad
## 0.0266
##
## Degrees of Freedom: 140 Total (i.e. Null); 135 Residual
##
## Scale Link: identity
## Estimated Scale Parameters: [1] 1.91
##
## Correlation: Structure = unstructured Link = identity
## Estimated Correlation Parameters:
## alpha.1:2 alpha.1:3 alpha.1:4 alpha.2:3 alpha.2:4 alpha.3:4
## 0.17147 -0.22329 0.00414 -0.11503 -0.01050 -0.13931
##
## Number of clusters: 35 Maximum cluster size: 4
Con edad y modif de efecto
mod_gee4 <- geeglm(EVA ~ factor(PERIOD) + edad + EVA*sexo ,
data = TITO_long,
id = TITO_long$SUP,
family = gaussian,
corstr = "unstructured")
## Warning in model.matrix.default(mt, mf, contrasts): La respuesta apareció en el
## lado derecho y se descartó
## Warning in model.matrix.default(mt, mf, contrasts): problema con el término 3
## en model.matrix: no se asignaron columnas
## Warning in model.matrix.default(glmFit, data = structure(list(EVA = c(9, : La
## respuesta apareció en el lado derecho y se descartó
## Warning in model.matrix.default(glmFit, data = structure(list(EVA = c(9, :
## problema con el término 3 en model.matrix: no se asignaron columnas
## Warning in model.matrix.default(mt, mf, contrasts): La respuesta apareció en el
## lado derecho y se descartó
## Warning in model.matrix.default(mt, mf, contrasts): problema con el término 3
## en model.matrix: no se asignaron columnas
tab_model(mod_gee4)
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Converting into numeric values currently not possible for variables of
## class 'NULL'.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
## Warning in formula.character(object, env = baseenv()): Using formula(x) is deprecated when x is a character vector of length > 1.
## Consider formula(paste(x, collapse = " ")) instead.
| Â | Dependent variable | ||
|---|---|---|---|
| Predictors | Estimates | CI | p |
| (Intercept) | 6.83 | 5.49 – 8.17 | <0.001 |
| factor(PERIOD)7 | -7.03 | -7.88 – -6.18 | <0.001 |
| factor(PERIOD)30 | -6.96 | -7.89 – -6.03 | <0.001 |
| factor(PERIOD)90 | -7.62 | -8.26 – -6.97 | <0.001 |
| edad | 0.02 | 0.00 – 0.04 | 0.031 |
| sexoM | -0.90 | -1.45 – -0.35 | 0.001 |
| EVA:sexoM | 0.30 | 0.14 – 0.45 | <0.001 |
| Observations | 140 | ||
mod_gee4
##
## Call:
## geeglm(formula = EVA ~ factor(PERIOD) + edad + EVA * sexo, family = gaussian,
## data = TITO_long, id = TITO_long$SUP, corstr = "unstructured")
##
## Coefficients:
## (Intercept) factor(PERIOD)7 factor(PERIOD)30 factor(PERIOD)90
## 6.8303 -7.0310 -6.9584 -7.6163
## edad sexoM EVA:sexoM
## 0.0228 -0.9012 0.2951
##
## Degrees of Freedom: 140 Total (i.e. Null); 133 Residual
##
## Scale Link: identity
## Estimated Scale Parameters: [1] 1.8
##
## Correlation: Structure = unstructured Link = identity
## Estimated Correlation Parameters:
## alpha.1:2 alpha.1:3 alpha.1:4 alpha.2:3 alpha.2:4 alpha.3:4
## -0.2022 -0.2552 -0.0912 -0.1048 0.1275 -0.1403
##
## Number of clusters: 35 Maximum cluster size: 4
Supuestos
library(tidyverse)
library(marginaleffects)
library(data.table)
library(haven)
library(lme4)
library(geepack)
library(performance)
## Warning: package 'performance' was built under R version 4.4.3
library(psych)
library(sjPlot)
library(lmerTest)
library(sjstats)
##
## Adjuntando el paquete: 'sjstats'
## The following objects are masked from 'package:performance':
##
## icc, r2
## The following object is masked from 'package:psych':
##
## phi
Supuestos del modelo.
resid_pearson <- residuals(mod_gee4, type = "pearson")
fitted_vals <- fitted(mod_gee4)
id <- mod_gee4$id
plot(fitted_vals, resid_pearson,
xlab = "Valores ajustados",
ylab = "Residuos de Pearson",
main = "GEE: Residuos vs Ajustados")
abline(h = 0, col = "red")
plot(fitted_vals, abs(resid_pearson),
xlab = "Valores ajustados",
ylab = "|Residuos de Pearson|",
main = "Chequeo de varianza")
boxplot(resid_pearson ~ id,
xlab = "Cluster",
ylab = "Residuos de Pearson",
las = 2)
#correlación de trabajo
summary(mod_gee4)$working.correlation
## NULL
library(ggplot2)
ggplot(data.frame(fitted_vals, resid_pearson),
aes(fitted_vals, resid_pearson)) +
geom_point(alpha = 0.6) +
geom_hline(yintercept = 0, color = "red") +
labs(x = "Valores ajustados",
y = "Residuos de Pearson",
title = "Diagnóstico GEE") +
theme_minimal()