install.packages(c(“dplyr”, “e1071”, “ggplot2”, “lsr”, “moments”))— title: “Practica laura bertel” author: “yo. Lau” date: “2026-08-06” output: html_document —
En esta sección se cargan los paquetes necesarios para realizar los analisis estadísticoos y gráficos que se desarrollarán en el documento.
library(lsm) # Para descargar una base de datos
library(dplyr)
##
## Adjuntando el paquete: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(moments) # Para hallar las medidas de forma
library(e1071)
##
## Adjuntando el paquete: 'e1071'
## The following objects are masked from 'package:moments':
##
## kurtosis, moment, skewness
library(ggplot2)
##
## Adjuntando el paquete: 'ggplot2'
## The following object is masked from 'package:e1071':
##
## element
En esta sección se presenta y explora la base de datos que será utilizada para realizar los diferentes análisis estadísticos.
datosCompleto <- lsm::survey
Interpretación: La base de datosCompleto es nombre que le pusimos a la encuesta que tiene información de las diferentes caracteristicas del ejercicio en R y survey es la base de datos. Ejemplo: caracteristicas personales, académicas y sociales de los participantes. Estos son todos los datos que se utilizan para hacer el análisis estadístico.
head(datosCompleto) #A) Por defecto, solo las primeras 6 observaciones
## # A tibble: 6 × 66
## Observation ID Gender Like Age Smoke Height Weight BMI School SES
## <dbl> <chr> <chr> <chr> <dbl> <chr> <dbl> <dbl> <dbl> <chr> <chr>
## 1 1 SB11201… Female TV 21.4 No 1.58 75 30.0 Priva… Medi…
## 2 2 SB11201… Male Netw… 21.1 Yes 1.6 80 31.2 Public High
## 3 3 SB11201… Male Netw… 20.9 Yes 1.5 64 28.4 Priva… High
## 4 4 SB11201… Male TV 18.4 Yes 1.53 49 20.9 Public Low
## 5 5 SB11201… Female TV 16.6 Yes 1.78 82 25.9 Priva… High
## 6 6 SB11201… Female Netw… 16.0 No 1.65 80 29.4 Public Low
## # ℹ 55 more variables: Enrollment <chr>, Score <dbl>, MotherHeight <chr>,
## # MotherAge <dbl>, MotherCHD <dbl>, FatherHeight <chr>, FatherAge <dbl>,
## # FatherCHD <dbl>, Status <chr>, SemAcum <dbl>, Exam1 <dbl>, Exam2 <dbl>,
## # Exam3 <dbl>, Exam4 <dbl>, ExamAcum <dbl>, Definitive <dbl>, Expense <dbl>,
## # Income <dbl>, Gas <dbl>, Course <chr>, Law <chr>, Economic <chr>,
## # Race <chr>, Region <chr>, EMO1 <dbl>, EMO2 <dbl>, EMO3 <dbl>, EMO4 <dbl>,
## # EMO5 <dbl>, GOAL1 <chr>, GOAL2 <chr>, GOAL3 <chr>, Pre_STAT1 <dbl>, …
head(datosCompleto, 3) #B) Solo las primeras 3 observaciones
## # A tibble: 3 × 66
## Observation ID Gender Like Age Smoke Height Weight BMI School SES
## <dbl> <chr> <chr> <chr> <dbl> <chr> <dbl> <dbl> <dbl> <chr> <chr>
## 1 1 SB11201… Female TV 21.4 No 1.58 75 30.0 Priva… Medi…
## 2 2 SB11201… Male Netw… 21.1 Yes 1.6 80 31.2 Public High
## 3 3 SB11201… Male Netw… 20.9 Yes 1.5 64 28.4 Priva… High
## # ℹ 55 more variables: Enrollment <chr>, Score <dbl>, MotherHeight <chr>,
## # MotherAge <dbl>, MotherCHD <dbl>, FatherHeight <chr>, FatherAge <dbl>,
## # FatherCHD <dbl>, Status <chr>, SemAcum <dbl>, Exam1 <dbl>, Exam2 <dbl>,
## # Exam3 <dbl>, Exam4 <dbl>, ExamAcum <dbl>, Definitive <dbl>, Expense <dbl>,
## # Income <dbl>, Gas <dbl>, Course <chr>, Law <chr>, Economic <chr>,
## # Race <chr>, Region <chr>, EMO1 <dbl>, EMO2 <dbl>, EMO3 <dbl>, EMO4 <dbl>,
## # EMO5 <dbl>, GOAL1 <chr>, GOAL2 <chr>, GOAL3 <chr>, Pre_STAT1 <dbl>, …
Interpretación: Al resaltar el número 3, se muestran unicamente las tres primeras observaciones de la base de datos. Esto ayuda a ver por menos cantidad los registros.
Tail () permite ver las ultimas observaciones de la base datos.
tail(datosCompleto) #C) Por defecto, solo las últimas 6 observaciones
## # A tibble: 6 × 66
## Observation ID Gender Like Age Smoke Height Weight BMI School SES
## <dbl> <chr> <chr> <chr> <dbl> <chr> <dbl> <dbl> <dbl> <chr> <chr>
## 1 795 AC31201… Female <NA> NA <NA> 1.64 NA NA <NA> Low
## 2 796 AC31201… Female TV 13.5 <NA> 1.71 78 26.7 Public <NA>
## 3 797 AC31201… <NA> Netw… 15.8 No 1.68 53 18.8 Priva… Medi…
## 4 798 AC31201… Male <NA> 15.7 No NA 83 NA <NA> Low
## 5 799 AC31201… Female TV NA No 1.76 73 23.6 Priva… Low
## 6 800 AC31201… Male TV 16.6 No 1.62 70 26.7 Priva… <NA>
## # ℹ 55 more variables: Enrollment <chr>, Score <dbl>, MotherHeight <chr>,
## # MotherAge <dbl>, MotherCHD <dbl>, FatherHeight <chr>, FatherAge <dbl>,
## # FatherCHD <dbl>, Status <chr>, SemAcum <dbl>, Exam1 <dbl>, Exam2 <dbl>,
## # Exam3 <dbl>, Exam4 <dbl>, ExamAcum <dbl>, Definitive <dbl>, Expense <dbl>,
## # Income <dbl>, Gas <dbl>, Course <chr>, Law <chr>, Economic <chr>,
## # Race <chr>, Region <chr>, EMO1 <dbl>, EMO2 <dbl>, EMO3 <dbl>, EMO4 <dbl>,
## # EMO5 <dbl>, GOAL1 <chr>, GOAL2 <chr>, GOAL3 <chr>, Pre_STAT1 <dbl>, …
tail(datosCompleto, 2) #D) Solo las últimas 2 observaciones
## # A tibble: 2 × 66
## Observation ID Gender Like Age Smoke Height Weight BMI School SES
## <dbl> <chr> <chr> <chr> <dbl> <chr> <dbl> <dbl> <dbl> <chr> <chr>
## 1 799 AC31201… Female TV NA No 1.76 73 23.6 Priva… Low
## 2 800 AC31201… Male TV 16.6 No 1.62 70 26.7 Priva… <NA>
## # ℹ 55 more variables: Enrollment <chr>, Score <dbl>, MotherHeight <chr>,
## # MotherAge <dbl>, MotherCHD <dbl>, FatherHeight <chr>, FatherAge <dbl>,
## # FatherCHD <dbl>, Status <chr>, SemAcum <dbl>, Exam1 <dbl>, Exam2 <dbl>,
## # Exam3 <dbl>, Exam4 <dbl>, ExamAcum <dbl>, Definitive <dbl>, Expense <dbl>,
## # Income <dbl>, Gas <dbl>, Course <chr>, Law <chr>, Economic <chr>,
## # Race <chr>, Region <chr>, EMO1 <dbl>, EMO2 <dbl>, EMO3 <dbl>, EMO4 <dbl>,
## # EMO5 <dbl>, GOAL1 <chr>, GOAL2 <chr>, GOAL3 <chr>, Pre_STAT1 <dbl>, …
Interpretación: Al especificar el número 2, se muestran únicamente las dos ultimas observaciones de a base de datos, correspondientes a los registros 799 y 800.
En esta sección se identifican las variables disponibles en la base de datos y se revisa la información que contiene cada una de ellas.
str(datosCompleto) #A) Estructura de los datos
## tibble [800 × 66] (S3: tbl_df/tbl/data.frame)
## $ Observation : num [1:800] 1 2 3 4 5 6 7 8 9 10 ...
## $ ID : chr [1:800] "SB11201910010435" "SB11201910004475" "SB11201910011427" "SB11201910041975" ...
## $ Gender : chr [1:800] "Female" "Male" "Male" "Male" ...
## $ Like : chr [1:800] "TV" "Network" "Network" "TV" ...
## $ Age : num [1:800] 21.4 21.1 20.9 18.4 16.6 ...
## $ Smoke : chr [1:800] "No" "Yes" "Yes" "Yes" ...
## $ Height : num [1:800] 1.58 1.6 1.5 1.53 1.78 1.65 1.73 1.53 1.64 1.52 ...
## $ Weight : num [1:800] 75 80 64 49 82 80 90 55 50 78 ...
## $ BMI : num [1:800] 30 31.2 28.4 20.9 25.9 ...
## $ School : chr [1:800] "Private" "Public" "Private" "Public" ...
## $ SES : chr [1:800] "Medium" "High" "High" "Low" ...
## $ Enrollment : chr [1:800] "Credit" "Scholarship" "Scholarship" "Credit" ...
## $ Score : num [1:800] 81 78 77 70 68 65 54 50 36 35 ...
## $ MotherHeight: chr [1:800] "Short_M" "Normal_M" "Normal_M" "Tall_M" ...
## $ MotherAge : num [1:800] 41 45 45 45 46 46 47 48 48 48 ...
## $ MotherCHD : num [1:800] 0 0 0 0 1 0 0 0 0 1 ...
## $ FatherHeight: chr [1:800] "Normal_F" "Short_F" "Tall_F" "Short_F" ...
## $ FatherAge : num [1:800] 40 43 44 45 45 46 46 48 48 49 ...
## $ FatherCHD : num [1:800] 1 1 1 2 1 1 1 1 1 1 ...
## $ Status : chr [1:800] "Distinguished" "Distinguished" "Distinguished" "Regular" ...
## $ SemAcum : num [1:800] 4.25 2.8 4.15 3.2 3.45 2.75 2.7 4.35 4.3 2.8 ...
## $ Exam1 : num [1:800] 1.5 2.3 3.4 2.5 3.1 3.8 5 4 2.5 2.4 ...
## $ Exam2 : num [1:800] 5 4.9 3.6 4.2 3.5 4.4 3 2.3 3.3 2.6 ...
## $ Exam3 : num [1:800] 5 3.7 2 5 5 4.2 3.5 4.6 3.8 4.3 ...
## $ Exam4 : num [1:800] 4.5 3.3 1.9 2.5 3 5 3.6 4.3 1.9 5 ...
## $ ExamAcum : num [1:800] 16 14.2 10.9 14.2 14.6 17.4 15.1 15.2 11.5 14.3 ...
## $ Definitive : num [1:800] 4 3.55 2.73 3.55 3.65 ...
## $ Expense : num [1:800] 48.9 72.1 85.2 56.6 64.6 63 40.8 65.4 37.3 63 ...
## $ Income : num [1:800] 1.61 2.07 2.84 1.55 2.32 2.1 1.69 2.18 1.71 2.1 ...
## $ Gas : num [1:800] 27.4 24.2 22.3 23.1 27.3 ...
## $ Course : chr [1:800] "Face-to-Face" "Virtual" "Face-to-Face" "Virtual" ...
## $ Law : chr [1:800] "Agree" "Agree" "Agree" "Agree" ...
## $ Economic : chr [1:800] "Regular" "Good" "Regular" "Bad" ...
## $ Race : chr [1:800] "Ethnic" "Ethnic" "Ethnic" "Ethnic" ...
## $ Region : chr [1:800] "North" "Center" "North" "Center" ...
## $ EMO1 : num [1:800] 1 4 3 4 2 3 2 3 4 2 ...
## $ EMO2 : num [1:800] 2 4 1 2 1 1 4 1 2 2 ...
## $ EMO3 : num [1:800] 2 1 3 3 2 4 2 4 3 3 ...
## $ EMO4 : num [1:800] 1 2 3 1 4 2 3 2 1 1 ...
## $ EMO5 : num [1:800] 4 1 2 2 2 2 1 1 2 2 ...
## $ GOAL1 : chr [1:800] "Strongly agree" "Undecided" "Agree" "Agree" ...
## $ GOAL2 : chr [1:800] "Agree" "Disagree" "Disagree" "Undecided" ...
## $ GOAL3 : chr [1:800] "Strongly agree" "Disagree" "Agree" "Strongly agree" ...
## $ Pre_STAT1 : num [1:800] 2 1 5 4 1 4 4 2 2 2 ...
## $ Pre_STAT2 : num [1:800] 4 1 1 3 4 1 2 3 3 5 ...
## $ Pre_STAT3 : num [1:800] 2 1 3 1 1 5 4 3 3 2 ...
## $ Pre_STAT4 : num [1:800] 5 1 1 2 2 3 2 3 2 4 ...
## $ Post_STAT1 : num [1:800] 4 5 5 3 5 2 3 3 2 5 ...
## $ Post_STAT2 : num [1:800] 5 1 2 2 3 3 2 3 2 3 ...
## $ Post_STAT3 : num [1:800] 2 3 3 4 3 5 5 4 5 4 ...
## $ Post_STAT4 : num [1:800] 2 3 3 5 4 4 3 5 5 1 ...
## $ Pre_IDARE1 : chr [1:800] "Quite a bit" "Quite a bit" "Quite a bit" "Little" ...
## $ Pre_IDARE2 : chr [1:800] "Little" "Little" "Little" "Nothing" ...
## $ Pre_IDARE3 : chr [1:800] "Quite a bit" "A lot" "Quite a bit" "Quite a bit" ...
## $ Pre_IDARE4 : chr [1:800] "Quite a bit" "Nothing" "Quite a bit" "Quite a bit" ...
## $ Pre_IDARE5 : chr [1:800] "Little" "Quite a bit" "Little" "Nothing" ...
## $ Post_IDARE1 : chr [1:800] "A lot" "A little" "Nothing" "Quite a bit" ...
## $ Post_IDARE2 : chr [1:800] "A lot" "Nothing" "Quite a bit" "A little" ...
## $ Post_IDARE3 : chr [1:800] "A little" "Quite a bit" "Nothing" "A lot" ...
## $ Post_IDARE4 : chr [1:800] "Quite a bit" "A lot" "Nothing" "Quite a bit" ...
## $ Post_IDARE5 : chr [1:800] "A lot" "Quite a bit" "Nothing" "A lot" ...
## $ PSICO1 : chr [1:800] "Frequently" "Frequently" "Sometimes" "Almost always" ...
## $ PSICO2 : chr [1:800] "Almost always" "Sometimes" "Sometimes" "Frequently" ...
## $ PSICO3 : chr [1:800] "Frequently" "Sometimes" "Sometimes" "Frequently" ...
## $ PSICO4 : chr [1:800] "Almost always" "Frequently" "Frequently" "Almost never" ...
## $ PSICO5 : chr [1:800] "Almost always" "Frequently" "Sometimes" "Sometimes" ...
Interpretación: La función str () permite conocer la estructura de la base de datos. La observación muestra que datosCompleto contiene 800 observaciones y 66 variables.
En esta sección se identifican los nombres de las variables que contiene la base de datos, con el fin de conocer la información disponible para realizar los análisis posteriores.
names(datosCompleto) #A) Muestra los nombres de las columnas (variables).
## [1] "Observation" "ID" "Gender" "Like" "Age"
## [6] "Smoke" "Height" "Weight" "BMI" "School"
## [11] "SES" "Enrollment" "Score" "MotherHeight" "MotherAge"
## [16] "MotherCHD" "FatherHeight" "FatherAge" "FatherCHD" "Status"
## [21] "SemAcum" "Exam1" "Exam2" "Exam3" "Exam4"
## [26] "ExamAcum" "Definitive" "Expense" "Income" "Gas"
## [31] "Course" "Law" "Economic" "Race" "Region"
## [36] "EMO1" "EMO2" "EMO3" "EMO4" "EMO5"
## [41] "GOAL1" "GOAL2" "GOAL3" "Pre_STAT1" "Pre_STAT2"
## [46] "Pre_STAT3" "Pre_STAT4" "Post_STAT1" "Post_STAT2" "Post_STAT3"
## [51] "Post_STAT4" "Pre_IDARE1" "Pre_IDARE2" "Pre_IDARE3" "Pre_IDARE4"
## [56] "Pre_IDARE5" "Post_IDARE1" "Post_IDARE2" "Post_IDARE3" "Post_IDARE4"
## [61] "Post_IDARE5" "PSICO1" "PSICO2" "PSICO3" "PSICO4"
## [66] "PSICO5"
Interpretación: La base de datos contiene 66 variables, cuyos nombres permite identificar la información disponibe. ESto ayuda a conocer los nombres de as variables facilita la identificación y selección para los análisis siguientes.
length(datosCompleto) #A) Revisando número de variables del objeto
## [1] 66
dim(datosCompleto) #B Muestra las dimensiones del objeto.
## [1] 800 66
ncol(datosCompleto) #C) Muestra el número de columnas del objeto.
## [1] 66
nrow(datosCompleto) #D) Muestra el número de filas del objeto.
## [1] 800
Interpretación: Los resultados indican que datosCompleto contiene 800 observaciones y 66 variables. Las funciones length () y ncol() coinciden con el numero de variabes, mientras que nrow () permite indentificar el número de observaciones.
En esta sección se muestra cómo seleccionar una parte de la base de datos utilizando la función de cochetes []. Esto permite trabajar con determinadas filas y columnas y crear una nueva base de dats a partir de la información seleccionada.
Muestra1 <- datosCompleto[1:10,2:7] # A) Un nuevo data frame
Muestra1
## # A tibble: 10 × 6
## ID Gender Like Age Smoke Height
## <chr> <chr> <chr> <dbl> <chr> <dbl>
## 1 SB11201910010435 Female TV 21.4 No 1.58
## 2 SB11201910004475 Male Network 21.1 Yes 1.6
## 3 SB11201910011427 Male Network 20.9 Yes 1.5
## 4 SB11201910041975 Male TV 18.4 Yes 1.53
## 5 SB11201910013623 Female TV 16.6 Yes 1.78
## 6 SB11201910038122 Female Network 16.0 No 1.65
## 7 SB11201910037905 Female TV 19.3 Yes 1.73
## 8 SB11201910038140 Female TV 18.6 Yes 1.53
## 9 SB11201910038005 Female TV 17.0 Yes 1.64
## 10 SB11201910037919 Male TV 19.7 Yes 1.52
Interpretación: Esta es una nueva base de datos llamada Muestra1 seeccionando las primeras 10 observaciones y las variables de la columnas 2 y 7 de datosCompleto. El resultado contiene 10 observaciones y 6 variables.
El objetivo es reconocer los diferentes tipos de variables de la base de datos y conocer las caractericas de los datos que se utilizan en los análisis posteriores.
str(datosCompleto) #A) Estructura de los datos
## tibble [800 × 66] (S3: tbl_df/tbl/data.frame)
## $ Observation : num [1:800] 1 2 3 4 5 6 7 8 9 10 ...
## $ ID : chr [1:800] "SB11201910010435" "SB11201910004475" "SB11201910011427" "SB11201910041975" ...
## $ Gender : chr [1:800] "Female" "Male" "Male" "Male" ...
## $ Like : chr [1:800] "TV" "Network" "Network" "TV" ...
## $ Age : num [1:800] 21.4 21.1 20.9 18.4 16.6 ...
## $ Smoke : chr [1:800] "No" "Yes" "Yes" "Yes" ...
## $ Height : num [1:800] 1.58 1.6 1.5 1.53 1.78 1.65 1.73 1.53 1.64 1.52 ...
## $ Weight : num [1:800] 75 80 64 49 82 80 90 55 50 78 ...
## $ BMI : num [1:800] 30 31.2 28.4 20.9 25.9 ...
## $ School : chr [1:800] "Private" "Public" "Private" "Public" ...
## $ SES : chr [1:800] "Medium" "High" "High" "Low" ...
## $ Enrollment : chr [1:800] "Credit" "Scholarship" "Scholarship" "Credit" ...
## $ Score : num [1:800] 81 78 77 70 68 65 54 50 36 35 ...
## $ MotherHeight: chr [1:800] "Short_M" "Normal_M" "Normal_M" "Tall_M" ...
## $ MotherAge : num [1:800] 41 45 45 45 46 46 47 48 48 48 ...
## $ MotherCHD : num [1:800] 0 0 0 0 1 0 0 0 0 1 ...
## $ FatherHeight: chr [1:800] "Normal_F" "Short_F" "Tall_F" "Short_F" ...
## $ FatherAge : num [1:800] 40 43 44 45 45 46 46 48 48 49 ...
## $ FatherCHD : num [1:800] 1 1 1 2 1 1 1 1 1 1 ...
## $ Status : chr [1:800] "Distinguished" "Distinguished" "Distinguished" "Regular" ...
## $ SemAcum : num [1:800] 4.25 2.8 4.15 3.2 3.45 2.75 2.7 4.35 4.3 2.8 ...
## $ Exam1 : num [1:800] 1.5 2.3 3.4 2.5 3.1 3.8 5 4 2.5 2.4 ...
## $ Exam2 : num [1:800] 5 4.9 3.6 4.2 3.5 4.4 3 2.3 3.3 2.6 ...
## $ Exam3 : num [1:800] 5 3.7 2 5 5 4.2 3.5 4.6 3.8 4.3 ...
## $ Exam4 : num [1:800] 4.5 3.3 1.9 2.5 3 5 3.6 4.3 1.9 5 ...
## $ ExamAcum : num [1:800] 16 14.2 10.9 14.2 14.6 17.4 15.1 15.2 11.5 14.3 ...
## $ Definitive : num [1:800] 4 3.55 2.73 3.55 3.65 ...
## $ Expense : num [1:800] 48.9 72.1 85.2 56.6 64.6 63 40.8 65.4 37.3 63 ...
## $ Income : num [1:800] 1.61 2.07 2.84 1.55 2.32 2.1 1.69 2.18 1.71 2.1 ...
## $ Gas : num [1:800] 27.4 24.2 22.3 23.1 27.3 ...
## $ Course : chr [1:800] "Face-to-Face" "Virtual" "Face-to-Face" "Virtual" ...
## $ Law : chr [1:800] "Agree" "Agree" "Agree" "Agree" ...
## $ Economic : chr [1:800] "Regular" "Good" "Regular" "Bad" ...
## $ Race : chr [1:800] "Ethnic" "Ethnic" "Ethnic" "Ethnic" ...
## $ Region : chr [1:800] "North" "Center" "North" "Center" ...
## $ EMO1 : num [1:800] 1 4 3 4 2 3 2 3 4 2 ...
## $ EMO2 : num [1:800] 2 4 1 2 1 1 4 1 2 2 ...
## $ EMO3 : num [1:800] 2 1 3 3 2 4 2 4 3 3 ...
## $ EMO4 : num [1:800] 1 2 3 1 4 2 3 2 1 1 ...
## $ EMO5 : num [1:800] 4 1 2 2 2 2 1 1 2 2 ...
## $ GOAL1 : chr [1:800] "Strongly agree" "Undecided" "Agree" "Agree" ...
## $ GOAL2 : chr [1:800] "Agree" "Disagree" "Disagree" "Undecided" ...
## $ GOAL3 : chr [1:800] "Strongly agree" "Disagree" "Agree" "Strongly agree" ...
## $ Pre_STAT1 : num [1:800] 2 1 5 4 1 4 4 2 2 2 ...
## $ Pre_STAT2 : num [1:800] 4 1 1 3 4 1 2 3 3 5 ...
## $ Pre_STAT3 : num [1:800] 2 1 3 1 1 5 4 3 3 2 ...
## $ Pre_STAT4 : num [1:800] 5 1 1 2 2 3 2 3 2 4 ...
## $ Post_STAT1 : num [1:800] 4 5 5 3 5 2 3 3 2 5 ...
## $ Post_STAT2 : num [1:800] 5 1 2 2 3 3 2 3 2 3 ...
## $ Post_STAT3 : num [1:800] 2 3 3 4 3 5 5 4 5 4 ...
## $ Post_STAT4 : num [1:800] 2 3 3 5 4 4 3 5 5 1 ...
## $ Pre_IDARE1 : chr [1:800] "Quite a bit" "Quite a bit" "Quite a bit" "Little" ...
## $ Pre_IDARE2 : chr [1:800] "Little" "Little" "Little" "Nothing" ...
## $ Pre_IDARE3 : chr [1:800] "Quite a bit" "A lot" "Quite a bit" "Quite a bit" ...
## $ Pre_IDARE4 : chr [1:800] "Quite a bit" "Nothing" "Quite a bit" "Quite a bit" ...
## $ Pre_IDARE5 : chr [1:800] "Little" "Quite a bit" "Little" "Nothing" ...
## $ Post_IDARE1 : chr [1:800] "A lot" "A little" "Nothing" "Quite a bit" ...
## $ Post_IDARE2 : chr [1:800] "A lot" "Nothing" "Quite a bit" "A little" ...
## $ Post_IDARE3 : chr [1:800] "A little" "Quite a bit" "Nothing" "A lot" ...
## $ Post_IDARE4 : chr [1:800] "Quite a bit" "A lot" "Nothing" "Quite a bit" ...
## $ Post_IDARE5 : chr [1:800] "A lot" "Quite a bit" "Nothing" "A lot" ...
## $ PSICO1 : chr [1:800] "Frequently" "Frequently" "Sometimes" "Almost always" ...
## $ PSICO2 : chr [1:800] "Almost always" "Sometimes" "Sometimes" "Frequently" ...
## $ PSICO3 : chr [1:800] "Frequently" "Sometimes" "Sometimes" "Frequently" ...
## $ PSICO4 : chr [1:800] "Almost always" "Frequently" "Frequently" "Almost never" ...
## $ PSICO5 : chr [1:800] "Almost always" "Frequently" "Sometimes" "Sometimes" ...
Interpretación: Esta estructura permite conocer de manera general los tipos de variables presentes en la base de datos. R reconoce numericas (num) y caracteres (chr). Esto ayuda a saber como deben ser tratadas las variables durante el análisis estadísticos.
Codigo <- datosCompleto$ID #B) Si es tipo caracter, es correcto)
Edad <- datosCompleto$Age #C) Si es tipo caracter, es incorrecto (ver ejemplo 4)
Sexo <- datosCompleto$Gender #D) Si es tipo caracter, es incorrecto (ver ejemplo 5)
Interpretación: La variable de ID es de ttipo caracter, ya que los códigos permiten identificar observaciones y no representan cantidades numéricas para realizar operaciones matemáticas. La variable de Age contiene valores numéricos que son la edad de los participantes, por lo que debe tratase como variabe numérica. La variable de Gender tiene categorias “female” “male”. Aunque R la puede reconocer como categorias puede convertirse en una variable de tipo factor.
P1 <- datosCompleto$Exam1 #E) Numérica
P2 <- datosCompleto$Exam2 #F) Numérica
Edad <- datosCompleto$Age #G) Numérica
Interpretación: Las variables Exam1, Exam2 y Age son valores numéricos. Por esta razon, pueden ser utilizadas en procedimientos estadístios que requiren variables cuantitativas.
Sexo <- as.factor(Sexo) #H) Convirtiendo a factor
class(Sexo) #I) Sale: "factor"
## [1] "factor"
str(Sexo) #J) Sale: Factor w/ 2 levels "Female","Masculino": 1 2 2 2 1 1 1 1 1 2 ...
## Factor w/ 2 levels "Female","Male": 1 2 2 2 1 1 1 1 1 2 ...
levels(Sexo) #K) Sale: "Female" "Masculino"
## [1] "Female" "Male"
Interpretación: Se convierte sexo a factor y R reconoce la variabe como categórica. Esto permite trabajar con el Sexo como una variable cualitativa formada por dos categorias “female” “male”.