Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
(as 'lib' is unspecified)
install.packages("tidyverse")
Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
(as 'lib' is unspecified)
install.packages("janitor")
Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
(as 'lib' is unspecified)
install.packages("tibble")
Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
(as 'lib' is unspecified)
install.packages("magrittr")
Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
(as 'lib' is unspecified)
install.packages("Amelia")
Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
(as 'lib' is unspecified)
install.packages("dplyr")
Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
(as 'lib' is unspecified)
install.packages("mice")
Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
(as 'lib' is unspecified)
install.packages("ggplot2")
Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
(as 'lib' is unspecified)
library(readxl) library(tidyverse)
── 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 3.5.1 ✔ 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(janitor)
Attaching package: 'janitor'
The following objects are masked from 'package:stats':
chisq.test, fisher.test
library(tibble)library(magrittr)
Attaching package: 'magrittr'
The following object is masked from 'package:purrr':
set_names
The following object is masked from 'package:tidyr':
extract
library(Amelia)
Loading required package: Rcpp
##
## Amelia II: Multiple Imputation
## (Version 1.8.2, built: 2024-04-10)
## Copyright (C) 2005-2024 James Honaker, Gary King and Matthew Blackwell
## Refer to http://gking.harvard.edu/amelia/ for more information
##
library(dplyr)library(mice)
Warning in check_dep_version(): ABI version mismatch:
lme4 was built with Matrix ABI version 0
Current Matrix ABI version is 1
Please re-install lme4 from source or restore original 'Matrix' package
Attaching package: 'mice'
The following object is masked from 'package:stats':
filter
The following objects are masked from 'package:base':
cbind, rbind
df_tabla <-as.data.frame(tabla_contingencia)ggplot(df_tabla, aes(x = Var1, y = Freq, fill = Var2)) +geom_bar(stat ="identity", position ="stack") +labs(x ="Variable 1", y ="Frecuencia", fill ="Variable 2") +ggtitle("Gráfico de barras apiladas")
Prueba chi cuadrado entre genero y ocupacion(homogeneidad)
# Convertir la tabla de contingencia en un data framedf_tabla <-as.data.frame(tabla_contingencia)# Crear el gráfico de barras apiladasggplot(df_tabla, aes(x = Var1, y = Freq, fill = Var2)) +geom_bar(stat ="identity", position ="stack") +labs(x ="Variable 1", y ="Frecuencia", fill ="Variable 2") +ggtitle("Gráfico de barras apiladas")
Correlacion y regresion lineal (edad e ingresos , satisfaccion con la vida y estres respectivamente)
Warning in cor.test.default(tabla_limpia$edad, tabla_limpia$ingresos, method =
"spearman"): Cannot compute exact p-value with ties
print(correlacion)
Spearman's rank correlation rho
data: tabla_limpia$edad and tabla_limpia$ingresos
S = 97235295, p-value = 0.3373
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho
0.03304633
plot(tabla_limpia$edad, tabla_limpia$ingresos, main ="Relación entre Edad e Ingresos",xlab ="Edad", ylab ="Ingresos", pch =19, col ="blue")model <-lm(ingresos ~ edad, data = tabla_limpia)abline(model, col ="red")
modelo_regresion <-lm(estres ~ satisfaccion_con_la_vida, data = tabla_limpia)summary(modelo_regresion)
Call:
lm(formula = estres ~ satisfaccion_con_la_vida, data = tabla_limpia)
Residuals:
Min 1Q Median 3Q Max
-4.6483 -2.5906 0.3734 2.3734 4.4167
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.576121 0.210671 26.468 <2e-16 ***
satisfaccion_con_la_vida 0.007216 0.034604 0.209 0.835
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 2.747 on 843 degrees of freedom
Multiple R-squared: 5.158e-05, Adjusted R-squared: -0.001135
F-statistic: 0.04348 on 1 and 843 DF, p-value: 0.8349
ggplot(tabla_limpia, aes(x = estres, y = satisfaccion_con_la_vida)) +geom_point() +geom_smooth(method ="lm", col ="blue") +labs(title ="Gráfico de dispersión con línea de regresión",x ="Estres",y ="Satisfacción con la vida")
`geom_smooth()` using formula = 'y ~ x'
Anova genero e ingresos(igualdad de medias)
anova <-aov(ingresos ~ genero, data = tabla_limpia)anova
Call:
aov(formula = ingresos ~ genero, data = tabla_limpia)
Terms:
genero Residuals
Sum of Squares 1383474 1207815135
Deg. of Freedom 2 842
Residual standard error: 1197.689
Estimated effects may be unbalanced
summary(anova)
Df Sum Sq Mean Sq F value Pr(>F)
genero 2 1.383e+06 691737 0.482 0.618
Residuals 842 1.208e+09 1434460
ggplot(tabla_limpia, aes(x = genero, y = ingresos, fill = genero)) +geom_boxplot() +labs(title ="Ingresos por género",x ="Género",y ="Ingresos") +theme_minimal()
Anova estado civil y depresion
anova <-aov(depresion ~ estado_civil, data = tabla_limpia)anova
Call:
aov(formula = depresion ~ estado_civil, data = tabla_limpia)
Terms:
estado_civil Residuals
Sum of Squares 26.561 6671.444
Deg. of Freedom 3 841
Residual standard error: 2.816514
Estimated effects may be unbalanced
summary(anova)
Df Sum Sq Mean Sq F value Pr(>F)
estado_civil 3 27 8.854 1.116 0.342
Residuals 841 6671 7.933
ggplot(tabla_limpia, aes(x = estado_civil, y = depresion, fill = estado_civil)) +geom_boxplot() +labs(title ="Depresión por estado civil",x ="Estado civil",y ="Depresión") +theme_minimal()