```{} knitr::opts_chunk$set( echo = TRUE, message = FALSE, warning = FALSE )

library(readxl) library(dplyr) library(ggplot2) library(car) library(lmtest) library(plotly) datos_raw <- read_excel(“datos_PAD.xlsx”) dim(datos_raw) datos <- datos_raw |> mutate( cant_servicios = as.numeric(CANTIDAD DE SERVICIOS SOLICITADOS), barthel = as.numeric(Escala De Barthel), edad = as.numeric(Edad), sexo = as.factor(Genero) ) |> select(cant_servicios, barthel, edad, sexo) |> filter( !is.na(cant_servicios), !is.na(barthel), !is.na(edad), !is.na(sexo) )

summary(datos) datos |> group_by(sexo) |> summarise( n = n(), servicios_mediana = median(cant_servicios), barthel_mediana = median(barthel), edad_media = mean(edad) ) ggplot(datos, aes(x = barthel, y = cant_servicios)) + geom_point(alpha = 0.4) + labs( title = “Relación entre escala de Barthel y cantidad de servicios”, x = “Escala de Barthel”, y = “Cantidad de servicios” ) + theme_minimal() ggplot(datos, aes(x = edad)) + geom_histogram(binwidth = 5, fill = “#74a9cf”, color = “white”) + labs( title = “Distribución de la edad”, x = “Edad”, y = “Frecuencia” ) + theme_minimal() plot_ly( data = datos |> sample_n(3000), x = ~barthel, y = ~edad, z = ~cant_servicios, type = “scatter3d”, mode = “markers”, marker = list(size = 3, opacity = 0.6) ) |> layout( scene = list( xaxis = list(title = “Escala de Barthel”), yaxis = list(title = “Edad”), zaxis = list(title = “Cantidad de servicios”) ), title = “Relación tridimensional entre Barthel, edad y servicios” ) modelo_final <- lm(cant_servicios ~ barthel + edad + sexo, data = datos) summary(modelo_final) par(mfrow = c(2,2)) plot(modelo_final) par(mfrow = c(1,1))

bptest(modelo_final) vif(modelo_final)