Para el análisis fue preciso definir ciertos conceptos.
Una encuesta es una investigación realizada sobre una muestra de sujetos representativa de un colectivo más amplio, utilizando procedimientos estandarizados de interrogación con intención de obtener mediciones cuantitativas de una gran variedad de características objetivas y subjetivas de la población. Obtenido de: García Ferrado (Fuente: http://www.estadistica.mat.uson.mx/Material/queesunaencuesta.pdf)
Es una herramienta, la cual permite recolección de información relevante para un estudio en específico, generalmente respaldado con un análisis estadístico. La información recolectada, se convierte luego en data la cual refleja las preferencias o decisiones de la muestra elegida.
Obtenido de: Open Intro Statistics (Survey, https://drive.google.com/file/d/0B-DHaDEbiOGkc1RycUtIcUtIelE/view)
Mediante la encuesta se obtienen datos de interés sociológico interrogando a los miembros de un colectivo o de una población. Las encuestas son una de las escasas técnicas de que se dispone para el estudio de las actitudes, valores y creencias motivos, estudiando las variables del estudio. Obtenido de: http://www.estadistica.mat.uson.mx/Material/queesunaencuesta.pdf
Encuestas descriptivas: Buscan reflejar o documentar las actitudes o condiciones presentes. Encuestas analíticas: buscan describir y explicar los por qué de una determinada situación.
De respuesta abierta: se le pide al interrogado que responda con sus propias palabras a la pregunta formulada. Se le otorga mayor libertad al entrevistado y al mismo tiempo se posibilitan adquirir respuestas más profundas así como también preguntar sobre el por qué y cómo de las respuestas realizadas.
De respuesta cerrada: los encuestados deben elegir para responder una de las opciones que se presentan en un listado que formularon los investigadores. Este tipo de encuesta obtiene como resultado respuestas más fáciles de cuantificar y de carácter uniforme. El problema que puede presentar es que no se tenga en el listado una opción que coincida con la respuesta que se quiere dar, por este motivo es ideal que siempre se agregue la opción a otros.
Por correo: se requiere que una determinada muestra llene un cuestionario, la encuesta es enviada por correo junto con sobres de respuestas, con sus correspondientes sellos, para que sean devueltos a los investigadores.
Por teléfono: se realizan vía telefónica y las hacen un equipo de personas entrenadas que serán las encargadas de verbalizar las preguntas y apuntar las respuestas.
Personal: se realizan cara a cara, pueden hacerse tanto en un lugar de trabajo u hogar del entrevistado, a personas que caminan por la calle o bien, que los entrevistados sean invitados a una sede para realizarla. Las encuestas pueden ser estructuradas, es decir que las preguntas fueron fijadas previamente, o inestructuradas, en estas el encuestador tiene mayo libertad para intervenir en la conversación ya que las preguntas son más generales.
Obtenido de: ( TIPOSDE, Enciclopedia de tipos, http://www.tiposde.org/escolares/123-tipos-de-encuestas/)
Es una herramienta de la investigación científica, cuya función básica es determinar qué parte de la población debe examinarse, con la finalidad de hacer inferencias de dicha población.
La muestra debe lograr una representación adecuada de la población, en la que se produzca de la mejor manera los rasgos esenciales que son importantes para la investigación. Para que una muestra sea representativa, por lo tanto útil, debe reflejar las similitudes y diferencias encontradas en la población, es decir ejemplificar las características de esta.
Obtenido de: ( Muestreo, www.estadistica.mat)
Existen cuatro formas de muestreo, las cuales son:
Simple Random Sample: Cada caso elegido de la población, tiene una posibilidad igual para llegar a la muestra final, y es importante así saber que cualquier caso incluido en la muestra no revela información relevante de los otros casos incluidos.
Stratified Sample: La población es dividida en grupos llamadas “estratos”, y los casos similares son agrupados juntos. Generalmente se emplea una segunda técnica de muestra aleatoria para cada estrato. El resultado de la muestra, será representativo.
Cluster Sample: Partimos la población en varios grupos que comparten características en común, y solo se elige un grupo aleatorio de muestras del conjunto de grupos “clusters”. Es importante hacer énfasis, que los grupos de muestras deben tener la misma posibilidad de ser elegidos.
Multistage Sample: Sólo se selecciona un número de estudiantes de cada grupo mediante el uso de un muestreo aleatorio simple o sistemático.
Obtenido de: ( Open Intro Statistics, Chapter 1, Observational Studies and Sampling Strategies, “Four Sampling Method”, al archivo), (Sampling Methods, Sampling, Explorable.com )
El modelo de distribución normal, siempre describe una figura simétrica, unimodal, y en forma de campana. Su forma, puede ser modificada con dos parámetros; desviación estándar, la cual modifica la forma de la curva en su ancho, y el promedio, mueve la campa para la derecha o izquierda. Es denominado “Distribución Normal Estandizará” cuando la distribución normal tiene de promedio 0 y desviación estándar 1. Obtenido de: ( Open Intro Statistics, Chapter 3, “Distributions of Random Variables”)
La distribución de Bernoulli, que toma valores “1”, con probabilidad de éxito, o “0”, con probabilidad de fracaso..
La distribución de Rademacher, donde una variable aleatoria X toma valores “1” o “-1” con probabilidad 1/2 cada uno.
La distribución binomial, que describe el número de aciertos en una serie de n experimentos independientes con posibles resultados “si” o “no”
Obtenido de: (Distribución de probabilidades, https://es.wikipedia.org/wiki/Distribucion_de_probabilidad)
Esta ley también es conocida como Ley del Azar, ya que repetir un experimento aleatorio por una cantidad determinada de veces y analizarlo detenidamente, se puede observar la tendencia y probabilidad de obtener un resultado o el otro.
Obtenido de: Ley de los Grandes Numeros, Probabilidad
CNN basándose WBUR En la encuesta se hace un análisis de la últimas encuestas, se encontró que la mayoría de personas que apoyan a Trump son del género masculino y raza blanca. Mientras que a Clinton es favorecida por la razas diversas no blancas y mujeres.
CBS basándose en Gallup En esta encuesta también analizan sobre qué candidato les parece más inspirador y tiene mejores características presidenciables, los resultados mostraron que Clinton recibía mayor aceptación por parte de los votantes.
NBC La encuesta muestra que el 27% de las mujeres luego de ver el primer debate sus impresiones de Trump desmejoraron. El 30% dijo que su opinión hacia Clinton mejoró.
Huffington Post En esta encuesta se identifica las preferencias de los votantes así cómo las fluctuaciones de de las mismas según las decisiones y percepciones de cada individuo.
ABC Esta encuesta ya no tiene relevancia para mayor estudio ya que fue previo al Primer Debate Presidencial, por lo que los resultados no serían del todo concluyentes.
Predicción: anunciar por revelación, ciencia o conjetura algo que ha de suceder. Obtenido de: (DRAE, Vigésima segunda edición).
La encuesta toma datos reales de personas, la decisión final, con la limitación que se hace por muestras. La predicción no va a la persona directa (en casos sí), usa en vez métodos de deducción y supuestos.
1. 2016 General Election (Trump vs Clinton):
2. DataSet Hillary vrs Donald and December 15:
Sample: indica tipo de encuesta (llamada, email, nota de voz email).Tipo: categorical.
Attempt: Número de intentos. Tipo: numeric.
Refusal: Si la encuesta se cancela o se le da seguimiento según requerimientos. Tipo: categorical.
Ilang: En que lenguaje se realizó la encuesta. Tipo: categorical.
Cregion: Región en la que se encuentra el entrevistado. Tipo: categorical.
State: Estado en el que se encuentra el entrevistado. Tipo: categorical.
USR: Si es en el área urbana o rural. *Tipo:+ categorical
Form: tipo de formato utilizado segun tipo de encuesta: Tipo: categorical.
q1-q31: Son preguntas directas. Cada una tiene una serie de x opciones por lo que se le considera categorical. En la mayoria de casos 9= Don’t know/refused.
N=2,000 entrevistados de adultos +18. (500 por teléfono fijo y 1500 por teléfono móvil) en español e inglés. Form 1/Form 2: each a random half sample 50 estados(incluyendo a Alaska y a Hawaii) Period: Jan. 7-14, 2016 Pretest: Jan 5, 2016
Este dataset trata de recopilar todo tipo de información incluyendo religión, opinión sobre esta misma y su influencia en las votaciones, opiniones sobre los candidatos, entre otros. Uno de los que más nos llamo la atención fue que hay poca diferencia entre opiniones sobre las creencias y religión de los candidatos, pero que es de gran preocupación que estos no se fijen en usar y apoyar doctrinas religiosas.
Este dataset contiene 2009 observaciones y 153 variables, por lo que nos limitaremos a unas cuantas para el análisis.
Sample: indica tipo de encuesta (llamada, email, nota de voz email).Tipo: categorical.
Attempt: Número de intentos. Tipo: numeric.
Refusal: Si la encuesta se cancela o se le da seguimiento según requerimientos. Tipo: categorical.
Ilang: En que lenguaje se realizó la encuesta. Tipo: categorical.
Cregion: Región en la que se encuentra el entrevistado. Tipo: categorical.
State: Estado en el que se encuentra el entrevistado. Tipo: categorical.
USR: Si es en el área urbana o rural. *Tipo:+ categorical
Form: tipo de formato utilizado segun tipo de encuesta: Tipo: categorical.
q1-q31: Son preguntas directas. Cada una tiene una serie de x opciones por lo que se le considera categorical. En la mayoria de casos 9= Don’t know/refused.
Los requerimientos necesarios para aplicar a la encuesta son pocos: mayor de 18 años y que no esté manejando(o actividades similares que necesiten de mucha atención).
Las variables numéricas que encontramos fueron: +attempt +density +sdensity
Para analizar el dataset se utilizó otra librería distinta a la habitual ya que este estaba en formato .sav
library(foreign)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
dt <- read.spss('Jan16 public.sav',use.value.labels=TRUE, max.value.labels=TRUE, to.data.frame=TRUE)
## Warning in read.spss("Jan16 public.sav", use.value.labels = TRUE,
## max.value.labels = TRUE, : Jan16 public.sav: Unrecognized record type 7,
## subtype 14 encountered in system file
## Warning in read.spss("Jan16 public.sav", use.value.labels = TRUE,
## max.value.labels = TRUE, : Jan16 public.sav: Unrecognized record type 7,
## subtype 18 encountered in system file
## Warning in read.spss("Jan16 public.sav", use.value.labels = TRUE,
## max.value.labels = TRUE, : Jan16 public.sav: Unrecognized record type 7,
## subtype 24 encountered in system file
De los datos pudimos extraer razones estadísticas de variables numéricas:
summary(select(dt, attempt, density, sdensity))
## attempt density sdensity
## Min. :1.000 Min. :1.000 Min. :1.000
## 1st Qu.:1.000 1st Qu.:2.000 1st Qu.:2.000
## Median :2.000 Median :3.000 Median :3.000
## Mean :2.332 Mean :2.904 Mean :3.048
## 3rd Qu.:3.000 3rd Qu.:4.000 3rd Qu.:4.000
## Max. :9.000 Max. :5.000 Max. :5.000
Attempts <- dt$attempt
Density <- dt$density
SDensity <- dt$sdensity
sd(Attempts)
## [1] 1.535959
sd(Density)
## [1] 1.40532
sd(SDensity)
## [1] 1.417084
var(Attempts)
## [1] 2.359171
var(Density)
## [1] 1.974926
var(SDensity)
## [1] 2.008126
hist(Attempts)
hist(Density)
hist(SDensity)
Y de las variables categóricas:
summary(select(dt, ilang, sample,refusal, usr))
## ilang sample refusal usr
## Min. :1.000 Min. :1.000 Min. :0.00000 : 80
## 1st Qu.:1.000 1st Qu.:1.000 1st Qu.:0.00000 R:354
## Median :1.000 Median :2.000 Median :0.00000 S:854
## Mean :1.061 Mean :1.749 Mean :0.03435 U:721
## 3rd Qu.:1.000 3rd Qu.:2.000 3rd Qu.:0.00000
## Max. :2.000 Max. :2.000 Max. :1.00000
factor(dt$ilang)[1]
## [1] 1
## Levels: 1 2
factor(dt$sample)[1]
## [1] 1
## Levels: 1 2
factor(dt$refusal)[1]
## [1] 0
## Levels: 0 1
factor(dt$usr)[1]
## [1] S
## Levels: R S U
q25: Do you think there has been too much, too little or the right amount of expression of religious faith and prayer by political leaders? 1 Too much 2 Too little 3 Right amount 9 Don’t know/Refused (VOL.)
q26: At the present time, do you think religion as a whole is increasing its influence on American life or losing its influence? 1 Increasing influence 2 Losing influence 3 Same (VOL.) 9 Don’t know/refused (VOL.)
q27:All in all, do you think this is a good thing or a bad thing? 1 Good thing 2 Bad thing 3 Both (VOL.) 4 Neither (VOL.) 5 Depends (VOL.) 9 Don’t know/refused (VOL.)
q28: How important is it to you that a president shares your religious beliefs? Is it [READ IN ORDER]? 1 Very important 2 Somewhat important 3 Not too important [OR] 4 Not at all important 9 Don’t know/Refused (VOL.)
hist(dt$q25) #too little
hist(dt$q26) #losing influence
hist(dt$q27) #bad thing
hist(dt$q28)#very similar opinions
## cargamos datos y librerias a utlizar.
library(dplyr)
library(readr)
library(foreign)
data <- read.spss("Dec15 public.sav", to.data.frame = TRUE)
## Warning in read.spss("Dec15 public.sav", to.data.frame = TRUE): Dec15
## public.sav: Unrecognized record type 7, subtype 14 encountered in system
## file
## Warning in read.spss("Dec15 public.sav", to.data.frame = TRUE): Dec15
## public.sav: Unrecognized record type 7, subtype 18 encountered in system
## file
## Warning in read.spss("Dec15 public.sav", to.data.frame = TRUE): Dec15
## public.sav: Unrecognized record type 7, subtype 24 encountered in system
## file
Conocer la data, comenzamos a ver las dimensionales, es decir el numero de filas y columnas del datawt, y luego desglosamos cada variable y su estructura.
dim(data) #1500 filas, y 140 columnas
## [1] 1500 140
str(data) #las primeras 18 columnas, son variables, y luego las demas son las preguntas que se realizaron a cada sujeto en las llamadas realizadas.
## 'data.frame': 1500 obs. of 140 variables:
## $ psraid : num 1e+05 1e+05 1e+05 1e+05 1e+05 ...
## $ sample : Factor w/ 2 levels "LL","cell": 1 1 1 1 1 1 1 1 1 1 ...
## $ int_date : num 120815 120815 120815 121015 120815 ...
## $ ilang : Factor w/ 2 levels "English","Spanish": 1 1 1 1 1 1 1 1 1 1 ...
## $ usr : Factor w/ 3 levels "Rural","Suburban",..: 3 3 2 2 2 3 3 3 2 1 ...
## $ cregion : Factor w/ 4 levels "Northeast","Midwest",..: 2 3 2 1 2 3 2 2 2 2 ...
## $ state : Factor w/ 51 levels "Alabama","Alaska",..: 14 44 36 33 14 10 14 50 26 42 ...
## $ density : atomic 2 4 3 5 4 4 2 3 3 1 ...
## ..- attr(*, "value.labels")= Named num 5 1
## .. ..- attr(*, "names")= chr "Highest" "Lowest"
## $ scregion : Factor w/ 4 levels "Northeast","Midwest",..: 2 3 2 1 2 3 2 2 2 2 ...
## $ sstate : Factor w/ 51 levels "Alabama","Alaska",..: 14 44 36 33 14 10 14 50 26 42 ...
## $ susr : Factor w/ 4 levels " ","R","S","U": 4 4 3 3 3 4 4 4 3 2 ...
## $ igender : Factor w/ 3 levels "Male","Female",..: 2 2 2 1 1 1 2 2 2 2 ...
## $ irace : Factor w/ 6 levels "White","Black or African-American",..: 2 1 1 2 1 2 2 4 3 4 ...
## $ attempt : num 1 1 1 2 1 2 1 1 1 1 ...
## $ fcall : num 151208 151208 151208 151208 151208 ...
## $ refusal : Factor w/ 2 levels "No","Yes": 1 1 1 2 1 1 1 1 1 1 ...
## $ treatment : Factor w/ 2 levels "Offer 1","Offer 2": NA NA NA NA NA NA NA NA NA NA ...
## $ form : Factor w/ 2 levels "Form 1","Form 2": 2 2 2 2 2 1 1 1 2 2 ...
## $ llitext0 : Factor w/ 2 levels "Youngest Male First",..: 2 2 2 2 1 2 1 2 2 1 ...
## $ offer2 : Factor w/ 2 levels "Reimbursement",..: NA NA NA NA NA NA NA NA NA NA ...
## $ qs1 : Factor w/ 3 levels "Under 18","18 or older",..: NA NA NA NA NA NA NA NA NA NA ...
## $ q1 : Factor w/ 3 levels "Approve","Disapprove",..: 2 1 1 1 1 1 2 2 2 2 ...
## $ q2 : Factor w/ 3 levels "Satisfied","Dissatisfied",..: 2 1 1 2 1 2 2 2 2 2 ...
## $ q7 : Factor w/ 3 levels "Answer given <U+0096> RECORD UP TO THREE RESPONSES",..: 1 1 1 NA 1 1 1 1 1 1 ...
## $ q7vb : Factor w/ 719 levels " "| __truncated__,..: 419 328 395 1 404 12 107 83 245 412 ...
## $ Q7VB0 : Factor w/ 2 levels " ",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ q7_oe1 : Factor w/ 71 levels "Economy (unsp)",..: 64 30 69 NA 69 22 1 1 64 35 ...
## $ q7_oe2 : Factor w/ 71 levels "Economy (unsp)",..: NA NA NA NA NA NA 63 27 37 NA ...
## $ q7_oe3 : Factor w/ 71 levels "Economy (unsp)",..: NA NA NA NA NA NA NA NA NA NA ...
## $ q11a : Factor w/ 5 levels "Very satisfied",..: 3 2 1 1 1 1 1 1 1 5 ...
## $ q11b : Factor w/ 5 levels "Very satisfied",..: 4 1 1 1 1 2 1 2 1 5 ...
## $ q11c : Factor w/ 5 levels "Very satisfied",..: 1 2 1 1 1 3 1 2 1 5 ...
## $ q15a : Factor w/ 3 levels "Approve","Disapprove",..: 2 2 1 1 2 1 2 1 2 3 ...
## $ q15b : Factor w/ 3 levels "Approve","Disapprove",..: 2 1 1 1 2 1 2 2 2 3 ...
## $ q15c : Factor w/ 3 levels "Approve","Disapprove",..: 2 1 1 1 2 1 2 3 2 2 ...
## $ q15d : Factor w/ 3 levels "Approve","Disapprove",..: 2 1 1 1 1 1 2 2 2 2 ...
## $ q15e : Factor w/ 3 levels "Approve","Disapprove",..: 2 2 1 1 3 1 3 2 2 2 ...
## $ q16 : Factor w/ 4 levels "Too tough","Not tough enough",..: 2 3 3 3 2 2 2 2 2 4 ...
## $ q20 : Factor w/ 5 levels "A lot","Some",..: 2 4 4 1 1 2 2 1 1 5 ...
## $ q22a : Factor w/ 4 levels "Interesting",..: 1 2 2 1 3 2 2 1 1 1 ...
## $ q22b : Factor w/ 4 levels "Too negative",..: 4 2 1 1 1 1 2 2 2 2 ...
## $ q22c : Factor w/ 4 levels "Informative",..: 1 2 2 2 2 2 2 1 2 4 ...
## $ q22d : Factor w/ 4 levels "Too long","Not too long",..: 1 2 2 1 1 1 1 1 2 1 ...
## $ q22e : Factor w/ 4 levels "Focused on important policy debates",..: 1 1 2 2 2 2 2 1 2 2 ...
## $ q23 : Factor w/ 3 levels "Yes","No","Don't know (VOL.)": 1 1 1 1 1 2 2 1 1 1 ...
## $ q24 : Factor w/ 3 levels "Yes","No","Don't know (VOL.)": 1 2 1 1 2 NA NA 3 3 1 ...
## $ q25 : Factor w/ 3 levels "Yes","No","Don't know (VOL.)": 3 2 2 2 2 NA NA 1 2 1 ...
## $ q26 : Factor w/ 5 levels "Very well","Fairly well",..: 3 2 2 3 4 1 4 4 4 4 ...
## $ q27 : Factor w/ 5 levels "That they have gone too far in restricting the average person's civil liberties",..: 1 1 5 2 2 2 2 2 3 5 ...
## $ q28a : Factor w/ 4 levels "Too much","Not enough",..: 2 3 3 2 2 3 1 2 3 4 ...
## $ q28b : Factor w/ 4 levels "Too much","Not enough",..: 4 1 3 2 2 3 1 3 2 4 ...
## $ q28c : Factor w/ 4 levels "Too much","Not enough",..: 4 3 1 2 1 1 3 1 3 4 ...
## $ q28d : Factor w/ 4 levels "Too much","Not enough",..: 4 1 2 2 2 2 1 1 1 4 ...
## $ q28e : Factor w/ 4 levels "Too much","Not enough",..: 3 3 3 2 2 3 1 2 1 4 ...
## $ q30a : Factor w/ 4 levels "Statement #1 ",..: 2 1 2 2 1 2 1 3 1 1 ...
## $ q30b : Factor w/ 4 levels "Statement #1 ",..: 2 1 4 2 2 2 2 2 2 1 ...
## $ q30c : Factor w/ 4 levels "Statement #1 ",..: 1 2 2 2 1 1 1 1 1 4 ...
## $ q30d : Factor w/ 4 levels "Statement #1 ",..: 2 1 1 1 1 1 1 2 1 2 ...
## $ q30e : Factor w/ 4 levels "Statement #1 ",..: 2 1 2 1 1 2 2 2 1 2 ...
## $ q31 : Factor w/ 3 levels "Muslims living in the U.S. should be subject to more scrutiny than people in other religious groups [OR]",..: 3 2 2 2 1 2 1 1 2 1 ...
## $ q40 : Factor w/ 5 levels "Excellent","Good",..: 4 3 2 2 4 2 4 3 4 3 ...
## $ q41 : Factor w/ 4 levels "Better","Worse",..: 2 3 2 3 2 3 2 3 2 3 ...
## $ q42 : Factor w/ 5 levels "Excellent shape",..: 4 3 3 1 3 2 2 2 2 2 ...
## $ q43 : Factor w/ 6 levels "Improve a lot",..: 6 2 1 2 5 2 4 2 3 5 ...
## $ q44a : Factor w/ 5 levels "Republican Party",..: 1 2 2 2 5 1 1 1 1 1 ...
## $ q44b : Factor w/ 5 levels "Republican Party",..: 1 2 2 1 4 1 1 1 1 4 ...
## $ q44c : Factor w/ 5 levels "Republican Party",..: 1 1 2 2 5 1 1 1 1 4 ...
## $ q44d : Factor w/ 5 levels "Republican Party",..: 1 2 2 2 5 1 1 1 1 1 ...
## $ q44ef1 : Factor w/ 5 levels "Republican Party",..: NA NA NA NA NA 1 1 2 NA NA ...
## $ q44ff2 : Factor w/ 5 levels "Republican Party",..: 1 1 2 2 5 NA NA NA 1 4 ...
## $ q45 : Factor w/ 3 levels "Favor","Oppose",..: 1 2 1 1 1 2 2 1 2 1 ...
## $ q45a : Factor w/ 9 levels "Less than $10.00/hour",..: 2 NA 1 2 2 NA NA 1 NA 1 ...
## $ q45z : Factor w/ 4 levels "The Islamic religion is more likely than others to encourage violence among its believers [OR]",..: 1 2 2 2 2 1 1 2 1 1 ...
## $ q46f1 : Factor w/ 4 levels "Lack of effort",..: NA NA NA NA NA 2 2 1 NA NA ...
## $ q47f2 : Factor w/ 4 levels "Because he or she worked harder than most other people [OR]",..: 4 1 2 1 3 NA NA NA 1 3 ...
## $ q48a : Factor w/ 4 levels "Yes, need ","No, do not need",..: 1 2 2 1 1 2 2 2 2 4 ...
## $ q48b : Factor w/ 4 levels "Yes, need ","No, do not need",..: 1 2 2 1 1 2 2 1 1 1 ...
## $ q48c : Factor w/ 4 levels "Yes, need ","No, do not need",..: 2 2 2 1 1 2 2 2 2 2 ...
## $ q48hf1 : Factor w/ 4 levels "Yes, need ","No, do not need",..: NA NA NA NA NA 1 1 1 NA NA ...
## $ q48if2 : Factor w/ 4 levels "Yes, need ","No, do not need",..: 1 2 2 1 1 NA NA NA 2 1 ...
## $ q51a : Factor w/ 4 levels "Major threat",..: 1 3 3 3 4 2 1 1 1 3 ...
## $ q51b : Factor w/ 4 levels "Major threat",..: 4 2 2 3 2 2 3 1 2 2 ...
## $ q51c : Factor w/ 4 levels "Major threat",..: 1 2 3 2 1 3 1 1 1 3 ...
## $ q51d : Factor w/ 4 levels "Major threat",..: 1 2 2 3 1 3 1 1 1 4 ...
## $ q51e : Factor w/ 4 levels "Major threat",..: 2 1 2 1 1 3 4 2 3 3 ...
## $ q51f : Factor w/ 4 levels "Major threat",..: 1 3 2 3 3 1 1 2 1 3 ...
## $ q51g : Factor w/ 4 levels "Major threat",..: 1 2 2 2 1 2 1 1 1 1 ...
## $ q59f1 : Factor w/ 4 levels "Plenty of jobs available ",..: NA NA NA NA NA 2 1 1 NA NA ...
## $ q60f2 : Factor w/ 4 levels "Plenty of GOOD jobs available",..: 4 1 2 1 1 NA NA NA 1 4 ...
## $ q61 : Factor w/ 4 levels "Going up faster",..: 3 2 2 2 2 3 3 2 3 2 ...
## $ q62 : Factor w/ 5 levels "Favors the rich",..: 5 1 1 1 5 2 2 2 2 4 ...
## $ q63 : Factor w/ 5 levels "Favors the rich",..: 1 2 3 2 5 1 1 2 3 5 ...
## $ q69f1 : Factor w/ 5 levels "Very concerned",..: NA NA NA NA NA 2 1 1 NA NA ...
## $ q70f2 : Factor w/ 5 levels "Very concerned",..: 1 4 4 3 1 NA NA NA 1 1 ...
## $ qem2 : Factor w/ 4 levels "Yes, full-time student",..: 3 3 3 3 3 3 3 3 3 3 ...
## $ qem1 : Factor w/ 5 levels "Yes ","Yes, semi-retired or 'still do some type of work' (VOL.)",..: 1 3 3 1 3 1 3 1 3 3 ...
## $ qem3 : Factor w/ 4 levels "Full-time","Part-time",..: 3 1 3 3 3 3 1 3 1 1 ...
## $ q71 : Factor w/ 5 levels "Very satisfied",..: NA 2 NA NA NA NA 1 NA 1 2 ...
## $ q81 : Factor w/ 3 levels "Approve","Disapprove",..: 1 2 3 1 1 1 2 1 1 3 ...
## [list output truncated]
## - attr(*, "variable.labels")= Named chr "Unique ID" "" "Interview date" "Language of interview" ...
## ..- attr(*, "names")= chr "psraid" "sample" "int_date" "ilang" ...
## - attr(*, "codepage")= int 1252
#Para ver la cantidad que conforma nuestra muestra, utlizamos la funcion length de cualquier variable*.
length(data$llitext0) #1,500 ciudadanos de US.
## [1] 1500
levels(data$llitext0)
## [1] "Youngest Male First" "Youngest Female First"
“Youngest Male First” “Youngest Female First” , es una descripcion generalizada del sujeto entrevistado en la llamada.
Ver los titulos de mi data, sin contar las preguntas que lo conforman
titulo <- data[,1:20]
Obervamos que hay una variable en especifico que indica el genero de cada sujeto.
Averiguar, la frecuencia de mis datos es decir cuantos de ellos pertenecen al sexo masculino y femenino. Para ello instalamos el paquete y libreria plyr
frencuenciasexo <- count(data, "igender")
#Son 481 hombres y 1019 mujeres.
#Con operadores matematicos, lo expreso en porcentaje.
(481*100) / 1500 #32.06667 % son hombres
## [1] 32.06667
(1019*100) / 1500 #67.93333 % son mujeres
## [1] 67.93333
Para votar, deben ser ciudadanos de 18 años en adelante.
Averiguaremos, de la variable sample la cual nos dice si eran de Linea Fja, o de celular. Para tener en mas detalle la muestra analizada.
count(data, "sample")
## # A tibble: 1 x 2
## "sample" n
## <chr> <int>
## 1 sample 1500
#LLWEIGHT analysis de landline, son 525
##CELLWEIGHT analysis of the cell, son 975
#Y de elos para filtrar aun más la data, vemos en que idioma se trevisto al individuo.
count(data, "ilang")
## # A tibble: 1 x 2
## "ilang" n
## <chr> <int>
## 1 ilang 1500
#Ingles 1450, español a 50
Es importante saber que rango de edad, fue el que se entrevistó con mas incidencia, para ellos es util sacar la moda. No hay una funcion en especifico que me muestre la moda. Podemos a primera instancia genrear una tabla con la freciencia de la edad para corrobar nuestras respuestas al crear una función que me devuelva la moda de cualquier variable que se especifique.
vec <- count(data, "age")
attach(data)
moda<-function(age){
frec.var<-table(age)
valor<-which(frec.var==max(frec.var)) # Elementos con el valor
names(valor)
}
moda(age)
## [1] "55" "63"
class(data$age) #numerica, me dice la edad de los entrevistados.
## [1] "numeric"
#RANGO
rango <- range(data$age)
#18 es la edad minima, y 99 años la edad mayor
#Maximo y Minimo
max(data$age)-min(data$age) #81 es la diferencia, entre la edad maxima y minima de la columna age.
## [1] 81
#MEDIA
mean(data$age) #52.532
## [1] 52.532
#Mediana
median(data$age) #54 años, es la edad que es el dato que aparece en medio de nuestro grupo.
## [1] 54
quantile(data$age,.25) #38 años
## 25%
## 38
quantile(data$age,.50) #54 años
## 50%
## 54
quantile(data$age,.75) #67 años
## 75%
## 67
summary(data$age)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 18.00 38.00 54.00 52.53 67.00 99.00
#Observaremos y se corrobora la información que el maximo es de 99 años y el minimo de 18 años, y el Q1 de 38 años, Q2 de 54 años, Q3 de 67 años.
#Grafico de raiz y hojas.
stem(data$age)
##
## The decimal point is 1 digit(s) to the right of the |
##
## 1 | 88888888888888888999999999999999999999
## 2 | 00000000000000001111111111111111111122222222222222222222233333333333+6
## 2 | 55555555555555555555566666666666777777777777777777888888888888888999+8
## 3 | 00000000000000000000000111111111111111111111222222222222222222233333+20
## 3 | 55555555555555555556666666666666666666666667777777777778888888888888+6
## 4 | 00000000000000000001111111111111111111111122222222222222222222333333+22
## 4 | 55555555555555555555555555566666666666666666777777777777777777777777+49
## 5 | 00000000000000000000000000000111111111111111111111122222222222222222+58
## 5 | 55555555555555555555555555555555555555666666666666666666666666667777+66
## 6 | 00000000000000000000000000011111111111111111111111111111111122222222+73
## 6 | 55555555555555555555555555556666666666666666666666666667777777777777+72
## 7 | 00000000000000000000000000000011111111111111111111111222222222222222+43
## 7 | 55555555555555555555566666666666666777777777777888888888888889999999
## 8 | 000000000000001111112222222223333334444444
## 8 | 55555555556666677777888899
## 9 | 00011233
## 9 | 999999999999999
#InterQuartile Range
IQR(data$age) #diferencia entre el tercer y el primer cuartil, la cual es 29.
## [1] 29
#STANDARD DEVIATION
#Muestra la dispersión de datos. Mientras mayor es la ds, mayor es la dispersión de la población. La desviación estándar es un promedio de las desviaciones individuales de cada observación con respecto a la media de una distribución.
desviacionst <- sd(data$age) #18.38839 es el grado de dispersión o variabilidad en la edad de los entrevistados.
#VARIANZA, es la desviacion estandar al cuadrado.
#varianza es cada numero del data menos el mean todo eso al cuadrado es como decir que tan lejos esta cada dato del prom y eso al cuadrado. Divido el numero de datos que le restamos el prom. y el resultado sera la medida de dispersion.
varianza <- 18.38839^2 #338.1329
#VARIABLE 2, NUMERICA RELEVANTE
#WEIGHT
weight <- data$weight
#Guardamos una variable en donde se me muestre solo la oclumna de weight de nuestro data para mayor facilidad al utlizarla. Y abrimos para analizarla
#Observamos que hay muchos valores NA, entonces procedemos a eliminarlos para mejor comprension
weightna <- weight[!is.na(weight)]
#Asi procedemos con los dos tipos de linea que existen para las llamadas.
weightll <- data$llweight
weightcell <- data$cellweight
weightllna <- weightll[!is.na(weightll)]
weightcellna <- weightcell[!is.na(weightcell)]
#RANGO
rango <- range(weightna)
#vemos que el intervalo donde oscila este valor
#1 - 8.37037
rangoll <- range(weightllna)
#1.00000- 34.85714
rangocell <- range(weightcellna)
#1.000000 - 4.607843
#Maximo y Minimo
max(weightna)-min(weightna) #7.37037
## [1] 7.37037
max(weightllna)-min(weightllna) #33.85714
## [1] 33.85714
#Cuartiles, y minimo maximo tambien pueden ser observados en el summary
#Variable weight
summary(weightna)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.000 1.852 3.093 3.553 4.778 8.370
#Q1, 1.852
#Q2 3.553
#Q3 4.778
#Corroboramos
quantile(weightna,.25) #1.851852
## 25%
## 1.851852
quantile(weightna,.50) #3.092593
## 50%
## 3.092593
quantile(weightna,.75) #4.777778
## 75%
## 4.777778
summary(weightllna)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.000 2.714 6.286 10.480 15.430 34.860
quantile(weightllna,.25) #2.714286
## 25%
## 2.714286
quantile(weightllna,.50) #6.285714
## 50%
## 6.285714
quantile(weightllna,.75) #15.42857
## 75%
## 15.42857
#Promedio
mean(weightllna) #10.48272
## [1] 10.48272
mean(weightna) #3.55279
## [1] 3.55279
#Mediana
median(weightllna) #6.285714
## [1] 6.285714
summary(weightcellna)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.000 1.435 2.056 2.320 2.968 4.608
quantile(weightcellna,.25) #1.43472
## 25%
## 1.43472
quantile(weightcellna,.50) #2.056432
## 50%
## 2.056432
quantile(weightcellna,.75) #2.967958
## 75%
## 2.967958
median(weightcellna) #2.056432
## [1] 2.056432
mean(weightcellna) #2.319721
## [1] 2.319721
max(weightcellna)-min(weightcellna) #3.607843
## [1] 3.607843
#STANDARD DEVIATION
sd(weightna) #2.088094
## [1] 2.088094
sd(weightcellna) #1.075258
## [1] 1.075258
sd(weightllna) #10.26299
## [1] 10.26299
#VARIANZA
varweight <- 2.088094^2 #4.360137
varweightll <- 1.075258^2 #1.15618
varweightcell <- 10.26299^2 #105.329
#INTERQUARTILE
IQR(weightna) #2.925926
## [1] 2.925926
IQR(weightcellna) #1.533238
## [1] 1.533238
IQR(weightllna) #12.71429
## [1] 12.71429
## (3) Grafique las variables numericas creando histogramas de frecuencias
#Box and Whisttle plots.
#AGE boxplot
boxplot(data$age) #the height of the box is the interquartile range
#Cada linea horizontal represena los diferentes cuartiles de la data espcificamente de la columna de edad. Y las lineas horizontales que estan alejdas representan los datos mayores y menores.
#AGE histogram
#Podemos observarlo a travez de un histograma.
hist(data$age, xlab="Edad de los votantes", main="")
#Weight histograms
hist(weightna, xlab="Peso", main="")
hist(weightcellna, xlab="Peso lineas moviles", main="")
hist(weightllna, xlab="Peso de lineas fijas", main="")
#Weight boxplots
boxplot(weightna)
boxplot(weightcellna)
boxplot(weightllna)
#Defina las caracteristicas del dataset que son categoria, y haga sus reportes sumarios de cada uno
Ilang
Es una variable relevante, ya que puede que el idioma en el cual respondieron a esta encuesta no lo dominen bien las personas, por ejemplo, alguien que su idioma materno es el español que no domine bien el ingles solo con el hecho de mencionar a Trump, puede que digan que no sin siquiera saber la pregunta.
Urs
Determina el tipo de comunida, puede que no todas las personas no esten enteradas de todo lo que esta pasando con las elecciones dependiendo del tipo de comunidad en la que viven, pues no tienen el mismo estilo de vida, por lo mismo pueden tener distintas opinions.
Cregion / state ??? Son variables relevantes y complementarias ya que dependiendo de cada estado y region pueden tener distintas opiniones (dependen de su entorno)
Igender / Ilitext0 Es una variable relevante, ya que los hombres y las mujeres piensan de manera distinta, es mas nadie piensa igual que otra persona, pueden tener pensamientos y opinions ismilares, como tambien opuestas.
Irace La que la raza afecta el criterio de las personas, pues con ciertas personas de distinto tipo de raza pueden tener mas dificultades, pues se comenten mas injusticias.
Form
Indica que tipo de encuesta se paso y pues seria relevante para comparer las formas y las respuestas que se obtuvieron de cada una.
Qnumero Son las respuestas de los que fueron entrevistados y las preguntas que se plantearon a los etrevistados.
#Codigo para sacar los summaries
summary(data)
## psraid sample int_date ilang
## Min. :100006 LL :525 Min. :120815 English:1450
## 1st Qu.:101654 cell:975 1st Qu.:120915 Spanish: 50
## Median :201599 Median :121015
## Mean :167511 Mean :121039
## 3rd Qu.:203890 3rd Qu.:121115
## Max. :206638 Max. :121315
##
## usr cregion state density
## Rural :246 Northeast:266 California:142 Min. :1.000
## Suburban:780 Midwest :339 Texas :100 1st Qu.:2.000
## Urban :474 South :573 Florida : 85 Median :3.000
## West :322 New York : 85 Mean :2.922
## Illinois : 57 3rd Qu.:4.000
## Ohio : 57 Max. :5.000
## (Other) :974
## scregion sstate susr igender
## Northeast:259 California:156 :975 Male : 481
## Midwest :345 Texas : 96 R:102 Female :1019
## South :568 Florida : 81 S:272 Unidentified: 0
## West :328 New York : 81 U:151
## Illinois : 59
## Ohio : 56
## (Other) :971
## irace attempt fcall
## White :403 Min. : 1.000 Min. :151208
## Black or African-American:725 1st Qu.: 1.000 1st Qu.:151208
## Hispanic :219 Median : 2.000 Median :151209
## Asian or Asian-American : 93 Mean : 2.235 Mean :151209
## Some other race : 60 3rd Qu.: 3.000 3rd Qu.:151210
## Don't know/Refused (VOL.): 0 Max. :10.000 Max. :151211
##
## refusal treatment form llitext0
## No :1311 Offer 1:498 Form 1:731 Youngest Male First :258
## Yes: 189 Offer 2:477 Form 2:769 Youngest Female First:267
## NA's :525 NA's :975
##
##
##
##
## offer2 qs1
## Reimbursement :498 Under 18 : 0
## Token of appreciation:477 18 or older :975
## NA's :525 Don't know/Refused: 0
## NA's :525
##
##
##
## q1 q2
## Approve :641 Satisfied : 361
## Disapprove :794 Dissatisfied :1101
## Don't know/Refused (VOL.): 65 Don't know/Refused (VOL.): 38
##
##
##
##
## q7
## Answer given <U+0096> RECORD UP TO THREE RESPONSES:839
## None/No problem : 2
## Don't know/No answer : 29
## NA's :630
##
##
##
## q7vb
## :661
## TERRORISM : 37
## ISIS : 16
## NATIONAL SECURITY : 10
## SECURITY : 9
## IMMIGRATION : 6
## (Other) :761
## Q7VB0
## :1499
## OT OF CONCERN, BUT THERE ARE SO MANYHOMELESS PEOPLE IN OUR COUNTRY, AND PEOPLE GOING TO BED HUNGRY. : 1
##
##
##
##
##
## q7_oe1
## Terrorism :126
## Economy (unsp) : 73
## Defense issues/national and homeland security/military & defense spending: 64
## Other : 57
## Immigration/illegal immigration/immigration situation/foreigners : 48
## (Other) :488
## NA's :644
## q7_oe2
## Terrorism : 31
## Unemployment/lack of jobs/ Job cuts : 26
## Immigration/illegal immigration/immigration situation/foreigners : 17
## Defense issues/national and homeland security/military & defense spending: 14
## Economy (unsp) : 13
## (Other) : 121
## NA's :1278
## q7_oe3
## Inflation/difference between wages/costs/prices : 5
## Economy (unsp) : 4
## Terrorism : 4
## Unemployment/lack of jobs/ Job cuts : 3
## Partisanship/the parties/gridlock/division in country (unsp): 3
## (Other) : 23
## NA's :1458
## q11a q11b
## Very satisfied :1134 Very satisfied :998
## Somewhat satisfied : 233 Somewhat satisfied :325
## Somewhat dissatisfied : 59 Somewhat dissatisfied : 93
## Very dissatisfied : 35 Very dissatisfied : 62
## Don't know/Refused (VOL.): 39 Don't know/Refused (VOL.): 22
##
##
## q11c q15a
## Very satisfied :952 Approve :632
## Somewhat satisfied :341 Disapprove :756
## Somewhat dissatisfied :111 Don't know/Refused (VOL.):112
## Very dissatisfied : 60
## Don't know/Refused (VOL.): 36
##
##
## q15b q15c
## Approve :529 Approve :521
## Disapprove :895 Disapprove :884
## Don't know/Refused (VOL.): 76 Don't know/Refused (VOL.): 95
##
##
##
##
## q15d q15e
## Approve :624 Approve :650
## Disapprove :804 Disapprove :637
## Don't know/Refused (VOL.): 72 Don't know/Refused (VOL.):213
##
##
##
##
## q16
## Too tough : 26
## Not tough enough :903
## About right :484
## Don't know/Refused (VOL.): 87
##
##
##
## q20
## A lot :825
## Some :375
## Not much :147
## None at all :137
## [VOL <U+0096> DO NOT READ] Don't know/Refused: 16
##
##
## q22a q22b
## Interesting :1050 Too negative :789
## Dull : 341 Not too negative :601
## Neither applies (VOL.) : 65 Neither applies (VOL.) : 41
## Don't know/Refused (VOL.): 44 Don't know/Refused (VOL.): 69
##
##
##
## q22c q22d
## Informative :727 Too long :819
## Not informative :703 Not too long :587
## Neither applies (VOL.) : 25 Neither applies (VOL.) : 31
## Don't know/Refused (VOL.): 45 Don't know/Refused (VOL.): 63
##
##
##
## q22e q23
## Focused on important policy debates :500 Yes :1088
## Not focused on important policy debates:869 No : 410
## Neither applies (VOL.) : 39 Don't know (VOL.): 2
## Don't know/Refused (VOL.) : 92
##
##
##
## q24 q25
## Yes :704 Yes :548
## No :367 No :507
## Don't know (VOL.): 17 Don't know (VOL.): 33
## NA's :412 NA's :412
##
##
##
## q26
## Very well :130
## Fairly well :540
## Not too well [OR] :400
## Not at all well :403
## [VOL. DO NOT READ] Don't know/Refused: 27
##
##
## q27
## That they have gone too far in restricting the average person's civil liberties:388
## That they have not gone far enough to adequately protect the country :859
## [VOL. DO NOT READ] Both : 79
## [VOL. DO NOT READ] Neither / Approve of policies :100
## [VOL. DO NOT READ] Don't know/Refused : 74
##
##
## q28a q28b
## Too much : 52 Too much :120
## Not enough :943 Not enough :857
## About the right amount :463 About the right amount :463
## Don't know/Refused (VOL.): 42 Don't know/Refused (VOL.): 60
##
##
##
## q28c q28d
## Too much :905 Too much :279
## Not enough :128 Not enough :817
## About the right amount :382 About the right amount :346
## Don't know/Refused (VOL.): 85 Don't know/Refused (VOL.): 58
##
##
##
## q28e q30a
## Too much : 92 Statement #1 :660
## Not enough :932 Statement #2 :723
## About the right amount :439 Neither/Both equally (VOL.): 72
## Don't know/Refused (VOL.): 37 Don't know/Refused (VOL.) : 45
##
##
##
## q30b q30c
## Statement #1 :531 Statement #1 :706
## Statement #2 :860 Statement #2 :660
## Neither/Both equally (VOL.): 55 Neither/Both equally (VOL.): 69
## Don't know/Refused (VOL.) : 54 Don't know/Refused (VOL.) : 65
##
##
##
## q30d q30e
## Statement #1 :934 Statement #1 :939
## Statement #2 :529 Statement #2 :551
## Neither/Both equally (VOL.): 26 Neither/Both equally (VOL.): 6
## Don't know/Refused (VOL.) : 11 Don't know/Refused (VOL.) : 4
##
##
##
## q31
## Muslims living in the U.S. should be subject to more scrutiny than people in other religious groups [OR]:525
## Muslims living in the U.S. should NOT be subject to additional scrutiny solely because of their religion:874
## [VOL. DO NOT READ] Don<U+0092>t know/Refused :101
##
##
##
##
## q40 q41
## Excellent : 38 Better :264
## Good :379 Worse :330
## Only fair :671 Same :846
## Poor :406 Don't know/Refused (VOL.): 60
## Don't know/Refused (VOL.): 6
##
##
## q42 q43
## Excellent shape :147 Improve a lot :103
## Good shape :594 Improve some :762
## Only fair shape :545 Get a little worse :269
## Poor shape :201 Get a lot worse : 79
## Don't know/Refused (VOL.): 13 Stay the same (VOL.) :256
## Don't know/Refused (VOL.): 31
##
## q44a q44b
## Republican Party :688 Republican Party :737
## Democratic Party :537 Democratic Party :489
## Both equally (VOL.) : 61 Both equally (VOL.) : 54
## Neither (VOL.) :121 Neither (VOL.) :128
## Don't know/Refused (VOL.): 93 Don't know/Refused (VOL.): 92
##
##
## q44c q44d
## Republican Party :679 Republican Party :685
## Democratic Party :565 Democratic Party :547
## Both equally (VOL.) : 39 Both equally (VOL.) : 36
## Neither (VOL.) :125 Neither (VOL.) :109
## Don't know/Refused (VOL.): 92 Don't know/Refused (VOL.):123
##
##
## q44ef1 q44ff2
## Republican Party :242 Republican Party :252
## Democratic Party :375 Democratic Party :352
## Both equally (VOL.) : 30 Both equally (VOL.) : 18
## Neither (VOL.) : 38 Neither (VOL.) : 64
## Don't know/Refused (VOL.): 46 Don't know/Refused (VOL.): 83
## NA's :769 NA's :731
##
## q45 q45a
## Favor :1064 $10.00-$10.99/hour :366
## Oppose : 400 Less than $10.00/hour :264
## Don<U+0092>t know/Refused (VOL.): 36 $15.00-$15.99/hour :148
## $12.00-$12.99 an hour :137
## Don<U+0092>t know/Refused (VOL.): 52
## (Other) : 97
## NA's :436
## q45z
## The Islamic religion is more likely than others to encourage violence among its believers [OR]:723
## The Islamic religion does not encourage violence more than others :645
## [VOL. DO NOT READ] Neither/both equally : 33
## [VOL. DO NOT READ] Don<U+0092>t know/Refused : 99
##
##
##
## q46f1
## Lack of effort :266
## Circumstances beyond control:355
## Both (VOL.) : 89
## Don't know/Refused (VOL.) : 21
## NA's :769
##
##
## q47f2
## Because he or she worked harder than most other people [OR] :313
## Because he or she had more advantages in life than most other people:353
## [VOL. DO NOT READ] Both : 73
## [VOL. DO NOT READ] Don't know/Refused : 30
## NA's :731
##
##
## q48a q48b q48c
## Yes, need :601 Yes, need :1327 Yes, need : 421
## No, do not need:879 No, do not need: 155 No, do not need:1066
## Not sure (VOL.): 11 Not sure (VOL.): 11 Not sure (VOL.): 12
## Refused (VOL.) : 9 Refused (VOL.) : 7 Refused (VOL.) : 1
##
##
##
## q48hf1 q48if2
## Yes, need :631 Yes, need :342
## No, do not need: 80 No, do not need:407
## Not sure (VOL.): 10 Not sure (VOL.): 13
## Refused (VOL.) : 10 Refused (VOL.) : 7
## NA's :769 NA's :731
##
##
## q51a q51b
## Major threat :747 Major threat :658
## Minor threat :504 Minor threat :591
## Not a threat :196 Not a threat :141
## Don't know/Refused (VOL.): 53 Don't know/Refused (VOL.):110
##
##
##
## q51c q51d
## Major threat :888 Major threat :944
## Minor threat :440 Minor threat :400
## Not a threat :129 Not a threat :113
## Don't know/Refused (VOL.): 43 Don't know/Refused (VOL.): 43
##
##
##
## q51e q51f
## Major threat :695 Major threat :664
## Minor threat :471 Minor threat :577
## Not a threat :285 Not a threat :196
## Don't know/Refused (VOL.): 49 Don't know/Refused (VOL.): 63
##
##
##
## q51g
## Major threat :1254
## Minor threat : 187
## Not a threat : 37
## Don't know/Refused (VOL.): 22
##
##
##
## q59f1
## Plenty of jobs available :313
## Jobs are difficult to find :365
## Lots of some jobs, few of others (VOL.): 22
## Don't know/Refused (VOL.) : 31
## NA's :769
##
##
## q60f2
## Plenty of GOOD jobs available :264
## GOOD jobs are difficult to find :463
## Lots of some jobs, few of others (VOL.): 11
## Don't know/Refused (VOL.) : 31
## NA's :731
##
##
## q61 q62
## Going up faster :119 Favors the rich :898
## Staying about even :636 Favors the middle class :427
## Falling behind :723 Favors the poor : 27
## Don't know/Refused (VOL.): 22 Favors none/all equally (VOL.): 77
## Don't know/Refused (VOL.) : 71
##
##
## q63 q69f1
## Favors the rich :382 Very concerned :477
## Favors the middle class :456 Somewhat concerned :185
## Favors the poor :492 Not too concerned : 37
## Favors none/all equally (VOL.): 81 Not at all concerned : 26
## Don't know/Refused (VOL.) : 89 Don't know/Refused (VOL.): 6
## NA's :769
##
## q70f2 qem2
## Very concerned :399 Yes, full-time student : 100
## Somewhat concerned :223 Yes, part-time : 60
## Not too concerned : 79 No :1338
## Not at all concerned : 56 Don't know/Refused (VOL.): 2
## Don't know/Refused (VOL.): 12
## NA's :731
##
## qem1
## Yes :483
## Yes, semi-retired or 'still do some type of work' (VOL.): 41
## No :948
## Disabled : 24
## Don't know/Refused (VOL.) : 4
##
##
## qem3
## Full-time :665
## Part-time :257
## Not employed :573
## Don't know/Refused (VOL.): 5
##
##
##
## q71
## Very satisfied :487
## Somewhat satisfied :339
## Somewhat dissatisfied : 64
## Very dissatisfied : 26
## [VOL. DO NOT READ] Don't know/Refused: 6
## NA's :578
##
## q81
## Approve :963
## Disapprove :420
## Don't know/Refused (VOL.):117
##
##
##
##
## q82
## Very well : 78
## Fairly well :401
## Not too well [OR] :616
## Not at all well :302
## [VOL. DO NOT READ] Don't know/Refused :103
##
##
## q83
## That the U.S. will go too far in getting involved in the situation [OR]:585
## That the U.S. will not go far enough in stopping the Islamic militants :794
## [VOL. DO NOT READ] Both : 23
## [VOL. DO NOT READ] Neither : 33
## [VOL. DO NOT READ] Don't know/Refused : 65
##
##
## q84
## Favor :726
## Oppose :687
## Don't know/Refused (VOL.): 87
##
##
##
##
## q85 sex age
## Definitely succeed :231 Male :825 Min. :18.00
## Probably succeed :722 Female:675 1st Qu.:38.00
## Probably fail [OR] :344 Median :54.00
## Definitely fail : 79 Mean :52.53
## [VOL. DO NOT READ] Don't know/Refused:124 3rd Qu.:67.00
## Max. :99.00
##
## educ2
## High school graduate (Grade 12 with diploma or GED certificate) :354
## Four year college or university degree/Bachelor's degree (e.g., BS, BA, AB) :341
## Postgraduate or professional degree, including master's, doctorate, medical or law degree:274
## Some college, no degree (includes some community college) :251
## Two year associate degree from a college or university :146
## High school incomplete (Grades 9-11 or Grade 12 with NO diploma) : 56
## (Other) : 78
## hisp
## Yes : 146
## No :1346
## Don't know/Refused (VOL.): 8
##
##
##
##
## race3m1
## White (e.g., Caucasian, European, Irish, Italian, Arab, Middle Eastern) :1171
## Black or African-American (e.g., Negro, Kenyan, Nigerian, Haitian) : 152
## Hispanic/Latino (VOL.) (e.g., Mexican, Puerto Rican, Cuban) : 72
## Asian or Asian-American (e.g., Asian Indian, Chinese, Filipino, Vietnamese or other Asian origin groups): 51
## Native American/American Indian/Alaska Native (VOL.) : 26
## Refused (e.g., non-race answers like American, Human, purple) (VOL.) : 16
## (Other) : 12
## race3m2
## Native American/American Indian/Alaska Native (VOL.) : 16
## Black or African-American (e.g., Negro, Kenyan, Nigerian, Haitian) : 13
## White (e.g., Caucasian, European, Irish, Italian, Arab, Middle Eastern) : 4
## Asian or Asian-American (e.g., Asian Indian, Chinese, Filipino, Vietnamese or other Asian origin groups): 3
## Some other race (SPECIFY) : 0
## (Other) : 0
## NA's :1464
## race3m3
## White (e.g., Caucasian, European, Irish, Italian, Arab, Middle Eastern) : 1
## Native American/American Indian/Alaska Native (VOL.) : 1
## Black or African-American (e.g., Negro, Kenyan, Nigerian, Haitian) : 0
## Asian or Asian-American (e.g., Asian Indian, Chinese, Filipino, Vietnamese or other Asian origin groups): 0
## Some other race (SPECIFY) : 0
## (Other) : 0
## NA's :1498
## race3m4
## White (e.g., Caucasian, European, Irish, Italian, Arab, Middle Eastern) : 0
## Black or African-American (e.g., Negro, Kenyan, Nigerian, Haitian) : 0
## Asian or Asian-American (e.g., Asian Indian, Chinese, Filipino, Vietnamese or other Asian origin groups): 0
## Some other race (SPECIFY) : 0
## Native American/American Indian/Alaska Native (VOL.) : 0
## (Other) : 0
## NA's :1500
## birth_hisp racecmb
## U.S. : 62 White :1143
## Puerto Rico : 6 Black : 149
## Another country : 75 Asian : 51
## Don't know/Refused (VOL.): 3 Mixed Race : 38
## NA's :1354 Some other race : 94
## Don't know/Refused (VOL.): 25
##
## racethn q90
## White, non-Hisp:1085 Upper class : 35
## Black, non-Hisp: 139 Upper-middle class :259
## Hispanic : 146 Middle class :668
## Other : 106 Lower-middle class :392
## NA's : 24 Lower class :126
## Don't know/Refused (VOL.): 20
##
## q91
## Very likely :859
## Somewhat likely :377
## Not too likely :144
## Not at all likely : 71
## [VOL. DO NOT READ] Don't know/Refused: 29
## NA's : 20
##
## q92
## Lower class [OR] :170
## Upper class :293
## [VOL. DO NOT READ] Don't know/Refused: 61
## NA's :976
##
##
##
## relig
## Protestant (Baptist, Methodist, Non-denominational, Lutheran, Presbyterian, Pentecostal, Episcopalian, Reformed, etc.):560
## Roman Catholic (Catholic) :280
## Nothing in particular :238
## Christian (VOL.) :147
## Agnostic (not sure if there is a God) : 60
## Atheist (do not believe in God) : 59
## (Other) :156
## chr born
## Yes : 47 Yes, would :442
## No : 26 No, would not :571
## Don't know/Refused (VOL.): 5 Don't know/Refused (VOL.): 32
## NA's :1422 NA's :455
##
##
##
## attend income
## More than once a week :173 50 to under $75,000 :224
## Once a week :341 100 to under $150,000:175
## Once or twice a month :190 75 to under $100,000 :166
## A few times a year :299 $150,000 or more :157
## Seldom :257 20 to under $30,000 :149
## Never :231 30 to under $40,000 :146
## Don't know/Refused (VOL.): 9 (Other) :483
## reg
## Are you ABSOLUTELY CERTAIN that you are registered to vote at your current address:1157
## Are you PROBABLY registered, but there is a chance your registration has lapsed : 80
## Are you NOT registered to vote at your current address : 255
## Don't know/Refused (VOL.) : 8
##
##
##
## party partyln
## Republican :416 Republican :268
## Democrat :446 Democrat :210
## Independent :557 Other/Don't know/Refused (VOL.):160
## No preference (VOL.) : 48 NA's :862
## Other party (VOL.) : 9
## Don't know/Refused (VOL.): 24
##
## ideo hh1 hh3
## Very conservative :114 Min. :1.000 Min. :1.000
## Conservative :449 1st Qu.:2.000 1st Qu.:2.000
## Moderate :515 Median :2.000 Median :2.000
## Liberal :252 Mean :2.761 Mean :2.439
## Very liberal :117 3rd Qu.:4.000 3rd Qu.:3.000
## Don't know/Refused (VOL.): 53 Max. :9.000 Max. :9.000
## NA's :287
## ql1
## Yes, have cell phone :466
## No, do not : 58
## Don't know/Refused (VOL.): 1
## NA's :975
##
##
##
## ql1a
## Yes, someone in household has cell phone: 19
## No : 15
## Don't know/Refused (VOL.) : 1
## NA's :1465
##
##
##
## qc1
## Yes, home telephone :393
## No, no home telephone :579
## Don't know/Refused (VOL.): 3
## NA's :525
##
##
##
## cellmin
## Worried about minutes this month : 51
## Not worried about minutes this month:899
## Have unlimited minutes (VOL.) : 19
## Don't know/refused (VOL.) : 6
## NA's :525
##
##
## money2
## Answer given : 124
## (VOL.) Respondent does not want the money: 374
## NA's :1002
##
##
##
##
## money2token
## Answer given : 185
## (VOL.) Respondent does not want the money: 292
## NA's :1023
##
##
##
##
## OFFER2_FINAL phoneuse2
## Wants money/Offered as reimbursement :124 LLO : 58
## Wants money/Offered as token of appreciation:185 Dual:860
## Respondent doesn't want money :666 CPO :582
## NA's :525
##
##
##
## phoneuse llweight cellweight weight
## LLO HH : 39 Min. : 1.000 Min. :1.000 Min. :1.000
## Dual HH:879 1st Qu.: 2.714 1st Qu.:1.435 1st Qu.:1.852
## CPO HH :582 Median : 6.286 Median :2.056 Median :3.093
## Mean :10.483 Mean :2.320 Mean :3.553
## 3rd Qu.:15.429 3rd Qu.:2.968 3rd Qu.:4.778
## Max. :34.857 Max. :4.608 Max. :8.370
## NA's :975 NA's :525
En columnas se enlista los cuartiles, el minimo maximo de los datos
ds1 <- read.csv("2016-general-election-trump-vs-clinton.csv")
names(ds1)
## [1] "Pollster" "Start.Date"
## [3] "End.Date" "Entry.Date.Time..ET."
## [5] "Number.of.Observations" "Population"
## [7] "Mode" "Trump"
## [9] "Clinton" "Other"
## [11] "Undecided" "Pollster.URL"
## [13] "Source.URL" "Partisan"
## [15] "Affiliation" "Question.Text"
## [17] "Question.Iteration"
+Pollster : entrevistadores diferentes +Start Date : fecha de inicio de la entrevista +End Date : fecha de fin de la entrevista +Entry Date/Time (ET) : fecha y hora de registro de la entrevista al sistema +Number of Observations : cantidad de entrevistados +Population : caracteristicas del entrevistado +Mode : método por el cual se realizo la entrevista +Trump : cantidad de respuestas de los entrevistados que votarían por Trump +Clinton : cantidad de respuestas de los entrevistados que votarían por Clinton +Other : cantidad de respuestas de los entrevistados que preferirían a un candidato diferente +Undecided : cantidad de entrevistados que están indecisos con su votación +Pollster URL : pagina web de la ubicacion de las entrevistas +Source URL : pagina web de donde se consiguieron las entrevistas +Partisan : categoría de ser partidista en la poliítica +Affiliation : categoría de los partidos políticos a los cuales pertenecen los entrevistados +Question Text : contiene el texto de las preguntas +Question Iteration : numero de veces que se tuvo que realizar la pregunta
tipos <- function(x){
i <- 1
t <- ncol(x)
while (i <= t ){
pal <- class(x[1,i])
s <- paste(names(x)[i] , pal , sep = ' : ')
print(s)
i <- i + 1
}
}
tipos(ds1)
## [1] "Pollster : factor"
## [1] "Start.Date : factor"
## [1] "End.Date : factor"
## [1] "Entry.Date.Time..ET. : factor"
## [1] "Number.of.Observations : integer"
## [1] "Population : factor"
## [1] "Mode : factor"
## [1] "Trump : numeric"
## [1] "Clinton : numeric"
## [1] "Other : numeric"
## [1] "Undecided : numeric"
## [1] "Pollster.URL : factor"
## [1] "Source.URL : factor"
## [1] "Partisan : factor"
## [1] "Affiliation : factor"
## [1] "Question.Text : factor"
## [1] "Question.Iteration : integer"
sapply(ds1[1,], class)
## Pollster Start.Date End.Date
## "factor" "factor" "factor"
## Entry.Date.Time..ET. Number.of.Observations Population
## "factor" "integer" "factor"
## Mode Trump Clinton
## "factor" "numeric" "numeric"
## Other Undecided Pollster.URL
## "numeric" "numeric" "factor"
## Source.URL Partisan Affiliation
## "factor" "factor" "factor"
## Question.Text Question.Iteration
## "factor" "integer"
dim(ds1)
## [1] 1246 17
Filas: 1310 Columnas: 17
El grupo objetivo en esta encuesta se puede dividir en dos. Por un lado tenemos a los entrevistadores, por el otro a los entrevistados. Canales de televisión, periódicos y organizaciones forman parte del grupo de entrevistadores. En cambio los entrevistados son ciudadanos con alta probabilidad de votar en las elecciones presidenciales de noviembre de 2016.
Variables numéricas:
a <- sapply(ds1[1,], class)
numericas <- a[a == "numeric"]
numericas
## Trump Clinton Other Undecided
## "numeric" "numeric" "numeric" "numeric"
Variables categóricas:
a <- sapply(ds1[1,], class)
f <- a[a == "factor"]
f
## Pollster Start.Date End.Date
## "factor" "factor" "factor"
## Entry.Date.Time..ET. Population Mode
## "factor" "factor" "factor"
## Pollster.URL Source.URL Partisan
## "factor" "factor" "factor"
## Affiliation Question.Text
## "factor" "factor"
str(ds1)
## 'data.frame': 1246 obs. of 17 variables:
## $ Pollster : Factor w/ 43 levels "ABC/Post","AP-GfK (web)",..: 29 29 29 29 29 29 29 29 18 18 ...
## $ Start.Date : Factor w/ 230 levels "2015-05-19","2015-06-20",..: 230 230 230 230 230 230 230 230 230 230 ...
## $ End.Date : Factor w/ 209 levels "2015-05-26","2015-06-22",..: 209 209 209 209 209 209 209 209 209 209 ...
## $ Entry.Date.Time..ET. : Factor w/ 346 levels "2015-05-28T21:52:59Z",..: 345 345 345 345 345 345 345 345 343 343 ...
## $ Number.of.Observations: int 933 NA NA NA 933 NA NA NA 1336 NA ...
## $ Population : Factor w/ 9 levels "Adults","Likely Voters",..: 2 3 5 4 2 3 5 4 2 3 ...
## $ Mode : Factor w/ 5 levels "Automated Phone",..: 3 3 3 3 3 3 3 3 2 2 ...
## $ Trump : num 40 11 82 32 45 12 89 40 38 5 ...
## $ Clinton : num 44 78 8 36 49 85 9 44 42 81 ...
## $ Other : num 3 2 2 3 NA NA NA NA 8 6 ...
## $ Undecided : num 6 5 3 14 6 4 3 17 12 8 ...
## $ Pollster.URL : Factor w/ 346 levels "http://elections.huffingtonpost.com/pollster/polls/abc-post-22720",..: 254 254 254 254 254 254 254 254 127 127 ...
## $ Source.URL : Factor w/ 318 levels " https://today.yougov.com/news/2016/06/29/yougoveconomist-poll-june-24-27-2016/",..: 188 188 188 188 188 188 188 188 23 23 ...
## $ Partisan : Factor w/ 3 levels "Nonpartisan",..: 2 2 2 2 2 2 2 2 1 1 ...
## $ Affiliation : Factor w/ 4 levels "Dem","None","Other",..: 1 1 1 1 1 1 1 1 2 2 ...
## $ Question.Text : Factor w/ 56 levels "","And if the election for President was held today and the candidates were Democrat Hillary Clinton,\nRepublican Donald Trump, Li"| __truncated__,..: 54 54 54 54 46 46 46 46 13 13 ...
## $ Question.Iteration : int 1 1 1 1 2 2 2 2 1 1 ...
tabla <- function(x) {
cbind(frec = table(x),
porcentaje = round(prop.table(table(x))*100, 2))
}
tabla(ds1$Pollster)
## frec porcentaje
## ABC/Post 14 1.12
## AP-GfK (web) 3 0.24
## ARG 17 1.36
## Bloomberg/Selzer 7 0.56
## CBS 28 2.25
## CBS/Times 18 1.44
## CNBC 1 0.08
## CNN 84 6.74
## Emerson College Polling Society 4 0.32
## FOX 70 5.62
## Franklin Pierce/RKM/Boston Herald 12 0.96
## GQR (D-Democracy Corps) 3 0.24
## GQR (D-Democracy Corps/Women's Voices Women Vote) 1 0.08
## Gravis Marketing/OANN 10 0.80
## GWU/Battleground 5 0.40
## IBD/TIPP 48 3.85
## ICITIZEN 6 0.48
## Ipsos/Reuters 152 12.20
## McClatchy/Marist 36 2.89
## McLaughlin (R) 8 0.64
## Monmouth University 21 1.69
## Morning Consult 266 21.35
## MSNBC/Telemundo/Marist 8 0.64
## NBC/SurveyMonkey 42 3.37
## NBC/WSJ 16 1.28
## Normington, Petts & Associates (D-End Citizens United) 2 0.16
## Penn Schoen Berland 12 0.96
## Pew 4 0.32
## PPP (D) 68 5.46
## PSRAI 1 0.08
## Public Religion Research Institute 1 0.08
## Quinnipiac 80 6.42
## Raba Research 2 0.16
## RABA Research 1 0.08
## Rasmussen 49 3.93
## Saint Leo University 3 0.24
## Schoen (D) 1 0.08
## Suffolk/USA Today 32 2.57
## SurveyUSA 1 0.08
## University of Delaware/PSRAI 4 0.32
## UPI/CVOTER 9 0.72
## YouGov/Economist 92 7.38
## Zogby (Internet) 4 0.32
tabla(ds1$Mode)
## frec porcentaje
## Automated Phone 14 1.12
## Internet 600 48.15
## IVR/Online 117 9.39
## Live Phone 514 41.25
## Mixed 1 0.08
tabla(ds1$Population)
## frec porcentaje
## Adults 3 0.24
## Likely Voters 159 12.76
## Likely Voters - Democrat 86 6.90
## Likely Voters - independent 87 6.98
## Likely Voters - Republican 86 6.90
## Registered Voters 289 23.19
## Registered Voters - Democrat 179 14.37
## Registered Voters - independent 178 14.29
## Registered Voters - Republican 179 14.37
+Pollster: ya que se puede reconocer quien está entrevistando +Mode: se conoce el medio por el cual se llevó a cabo la entrevista +Population: conocemos quienes estan contestando las entrevistas
¿Influye la edad en la disposición de estar afiliado a cierto partido político?
¿El sexo del candidato influye en la decisión de los votantes?
¿Cuál es la importancia de la religión en la decisión de los votantes?
¿Cuál es el porcentaje de los votantes para cada partido en los votos preliminares?
¿Qué partido satisface más las necesidades de los ciudadanos (según opinión)?
¿Con cuál partido se identifican más los votantes ?
¿La raza es un factor relevante en la inclinación hacia cierto candidato?
¿El interés por ciertas preguntas está ligado con los temas de las situación actual?
¿Quién sería un mejor presidente (según presidente)?
¿Cómo cambia la inclinación de Dic2015 a Enero2016?
library(readr)
data <- read.csv("primary_results.csv")
library(foreign)
data3 <- read.spss("Dec15 public.sav", to.data.frame=TRUE)
## Warning in read.spss("Dec15 public.sav", to.data.frame = TRUE): Dec15
## public.sav: Unrecognized record type 7, subtype 14 encountered in system
## file
## Warning in read.spss("Dec15 public.sav", to.data.frame = TRUE): Dec15
## public.sav: Unrecognized record type 7, subtype 18 encountered in system
## file
## Warning in read.spss("Dec15 public.sav", to.data.frame = TRUE): Dec15
## public.sav: Unrecognized record type 7, subtype 24 encountered in system
## file
dim(data3)
## [1] 1500 140
# 3D Exploded Pie Chart GENDER
library(plotrix)
slices <- c(481, 1019)
lbls <- c("Male", "Female")
pct <- round(slices/sum(slices)*100)
lbls <- paste(lbls, pct)
lbls <- paste(lbls,"%",sep="")
pie3D(slices,labels=lbls,explode=0.1,
main="Pie Chart of Gender")
data3$age
## [1] 85 25 29 73 36 76 61 66 67 60 79 82 45 66 73 40 68 67 50 22 64 60 70
## [24] 36 72 72 59 99 68 55 30 80 47 76 64 68 63 59 43 90 55 53 83 69 40 58
## [47] 70 92 64 28 66 56 53 76 99 60 57 73 58 86 50 60 24 49 86 72 67 68 62
## [70] 39 87 99 72 21 83 56 80 75 53 93 77 67 38 50 35 64 51 80 72 72 70 71
## [93] 58 57 86 69 52 81 57 71 59 62 67 29 63 75 53 87 85 45 81 63 75 44 69
## [116] 47 32 50 59 62 75 75 72 73 30 68 63 80 48 70 65 74 57 54 72 52 70 70
## [139] 73 45 53 51 67 46 51 87 45 52 66 50 70 87 48 76 71 63 68 73 72 54 72
## [162] 87 56 70 69 30 99 72 80 47 49 52 63 51 63 46 65 38 54 76 51 57 66 63
## [185] 73 67 89 82 61 47 30 79 75 54 85 89 52 62 61 69 75 59 61 59 53 65 69
## [208] 19 64 47 76 46 72 61 90 65 36 60 50 60 54 64 49 58 57 86 85 76 64 84
## [231] 45 80 45 68 60 47 82 27 75 80 75 48 80 79 51 75 42 63 39 59 79 85 23
## [254] 65 78 60 46 42 79 40 59 38 43 59 75 65 46 44 50 55 90 18 74 60 49 72
## [277] 35 55 55 68 64 85 70 66 43 37 54 69 74 31 70 54 51 71 51 54 49 45 55
## [300] 70 55 51 58 49 45 88 72 64 71 78 88 80 63 61 88 77 69 84 63 62 62 47
## [323] 61 57 63 55 52 56 44 73 68 21 55 64 67 60 66 50 66 65 71 43 61 62 71
## [346] 74 72 65 73 73 84 67 63 62 47 72 93 62 54 74 63 69 73 58 67 65 62 55
## [369] 84 66 43 80 88 78 77 64 64 53 69 31 41 47 57 49 67 18 61 66 63 71 74
## [392] 77 71 57 76 60 69 55 59 83 51 70 75 40 80 51 73 41 69 65 55 48 84 67
## [415] 35 62 68 75 67 63 73 66 99 79 66 65 67 58 69 59 62 66 76 69 54 61 69
## [438] 74 56 73 75 56 64 35 76 21 77 91 55 66 53 68 60 69 60 63 41 59 53 35
## [461] 79 65 57 58 66 27 70 40 85 80 69 74 59 65 56 58 69 50 41 48 54 70 50
## [484] 70 52 60 49 65 52 42 82 52 78 59 45 57 56 72 68 53 68 67 73 72 54 70
## [507] 68 19 31 64 50 71 58 50 68 64 66 71 44 49 54 49 58 73 61 48 61 44 49
## [530] 72 83 29 82 18 81 73 22 35 70 47 55 61 57 53 22 77 59 34 29 20 50 37
## [553] 65 69 41 63 60 58 44 36 33 65 23 54 36 18 49 66 64 36 44 56 58 58 36
## [576] 25 84 78 23 75 31 72 69 62 25 33 40 33 58 43 61 19 47 34 82 58 35 65
## [599] 65 29 46 22 72 66 49 38 39 24 64 62 48 65 67 31 71 42 29 63 40 81 67
## [622] 84 34 68 48 58 29 25 33 99 61 58 70 62 23 65 64 47 56 43 67 29 68 18
## [645] 80 31 53 55 50 45 58 24 49 43 29 77 30 29 25 71 53 56 47 82 36 73 73
## [668] 48 33 32 47 76 99 69 22 66 42 78 48 42 58 30 45 28 34 70 20 21 57 25
## [691] 67 39 23 50 46 58 23 49 62 49 58 31 37 32 68 25 45 30 55 31 49 34 37
## [714] 37 19 52 22 46 67 60 43 19 63 34 19 49 67 30 18 70 38 57 70 78 40 22
## [737] 53 21 61 24 32 71 33 63 61 43 36 71 41 20 22 68 72 63 68 49 45 42 29
## [760] 74 35 49 58 67 47 61 34 40 67 48 33 65 44 36 55 66 40 72 53 46 43 68
## [783] 29 48 30 38 44 47 37 47 54 68 54 54 57 64 59 32 70 54 19 50 28 75 64
## [806] 46 78 38 48 23 85 51 18 67 18 49 42 19 60 54 32 55 71 25 55 68 54 41
## [829] 63 55 61 64 22 56 43 41 59 56 28 21 56 47 18 21 56 60 55 39 41 19 58
## [852] 64 46 51 60 21 28 39 62 58 44 38 69 30 27 20 50 49 33 45 33 72 23 59
## [875] 26 46 30 46 27 44 54 41 99 24 25 31 53 48 24 32 70 31 20 51 19 82 33
## [898] 27 22 61 56 58 52 41 66 53 26 35 61 75 34 33 22 41 31 69 83 32 49 69
## [921] 50 33 33 69 61 32 37 32 81 63 70 62 31 68 41 40 47 99 42 28 66 55 46
## [944] 32 29 20 21 43 18 23 37 47 68 69 76 28 63 64 78 26 43 28 26 45 59 30
## [967] 66 21 44 23 36 18 34 41 53 44 24 37 39 25 61 28 19 60 28 49 99 77 80
## [990] 69 59 51 45 27 71 47 51 20 21 55 36 99 27 20 54 54 47 21 36 40 22 63
## [1013] 54 38 54 68 70 45 65 41 76 36 18 65 61 18 85 53 49 47 61 55 26 48 36
## [1036] 40 19 42 33 61 62 28 40 50 32 19 55 55 19 54 45 31 24 32 58 62 62 47
## [1059] 34 19 71 42 50 72 33 21 86 73 71 73 30 31 27 72 49 32 58 64 36 30 37
## [1082] 63 62 74 81 39 29 63 69 82 59 70 62 69 67 59 57 63 99 21 31 61 25 21
## [1105] 25 20 54 52 52 30 41 53 35 65 30 36 51 27 30 55 49 60 19 48 52 42 21
## [1128] 68 46 32 63 29 75 63 66 72 48 51 63 50 19 30 56 40 42 67 35 77 77 60
## [1151] 53 69 45 65 68 48 18 48 50 67 25 32 30 54 43 66 69 22 45 47 55 62 27
## [1174] 55 72 46 29 99 35 49 38 25 30 77 20 69 52 65 67 57 71 45 27 29 56 56
## [1197] 64 78 68 43 43 29 56 65 21 35 58 28 26 41 34 58 22 34 72 48 32 39 56
## [1220] 52 83 67 24 44 32 19 45 72 50 75 23 50 23 74 34 27 43 28 59 53 68 35
## [1243] 68 73 60 18 22 61 38 61 36 62 54 45 85 71 69 76 63 77 34 52 24 70 29
## [1266] 49 59 58 27 73 25 55 52 58 56 36 26 54 25 70 20 55 74 54 60 56 52 23
## [1289] 36 39 61 65 31 57 53 52 33 27 34 30 56 19 31 70 40 41 21 18 24 22 47
## [1312] 52 26 44 36 31 25 61 44 55 33 44 52 74 33 78 78 75 47 62 42 54 71 45
## [1335] 48 58 31 61 42 28 18 34 35 63 54 19 29 48 31 61 27 38 59 48 55 49 42
## [1358] 67 27 26 53 60 60 75 48 54 71 51 42 35 73 55 37 78 42 28 73 62 42 36
## [1381] 22 22 62 40 24 59 39 41 51 46 19 39 66 51 91 20 52 34 48 22 62 20 25
## [1404] 99 25 45 49 41 35 53 50 99 39 24 78 30 62 33 36 55 74 52 70 52 38 72
## [1427] 39 44 21 21 43 50 53 44 50 38 57 48 47 29 67 50 40 39 63 68 58 32 22
## [1450] 29 43 35 26 42 44 26 56 41 58 38 56 31 41 23 27 30 33 38 20 63 20 45
## [1473] 40 22 63 27 29 55 37 66 63 67 41 25 55 55 35 36 20 57 24 45 52 23 58
## [1496] 25 50 51 60 54
## attr(,"value.labels")
## Don't know/Refused (VOL.) 97 or older
## 99 97
age_count <- count(data3, "age")
attach(data3)
## The following object is masked _by_ .GlobalEnv:
##
## weight
## The following objects are masked from data:
##
## age, attempt, attend, birth_hisp, born, cellmin, cellweight,
## chr, cregion, density, educ2, fcall, form, hh1, hh3, hisp,
## ideo, igender, ilang, income, int_date, irace, llitext0,
## llweight, money2, money2token, offer2, OFFER2_FINAL, party,
## partyln, phoneuse, phoneuse2, psraid, q1, q11a, q11b, q11c,
## q15a, q15b, q15c, q15d, q15e, q16, q2, q20, q22a, q22b, q22c,
## q22d, q22e, q23, q24, q25, q26, q27, q28a, q28b, q28c, q28d,
## q28e, q30a, q30b, q30c, q30d, q30e, q31, q40, q41, q42, q43,
## q44a, q44b, q44c, q44d, q44ef1, q44ff2, q45, q45a, q45z,
## q46f1, q47f2, q48a, q48b, q48c, q48hf1, q48if2, q51a, q51b,
## q51c, q51d, q51e, q51f, q51g, q59f1, q60f2, q61, q62, q63,
## q69f1, q7, q7_oe1, q7_oe2, q7_oe3, q70f2, q71, q7vb, Q7VB0,
## q81, q82, q83, q84, q85, q90, q91, q92, qc1, qem1, qem2, qem3,
## ql1, ql1a, qs1, race3m1, race3m2, race3m3, race3m4, racecmb,
## racethn, refusal, reg, relig, sample, scregion, sex, sstate,
## state, susr, treatment, usr, weight
age_count
## # A tibble: 1 x 2
## "age" n
## <chr> <int>
## 1 age 1500
moda<-function(age){
frec.var<-table(age)
valor<-which(frec.var==max(frec.var)) # Elementos con el valor
names(valor)
}
#edades
slices <- c(145, 382, 567, 406)
lbls <- c("Jovenes", "Adultos", "Adultos Mayores", "3ra Edad")
pct <- round(slices/sum(slices)*100)
lbls <- paste(lbls, pct)
lbls <- paste(lbls,"%",sep="")
pie3D(slices,labels=lbls,explode=0.1,
main="Pie Chart of Age")
### jovenes = 18 - 25 , adultos de 26 - 45, adultos mayores 46 - 65, 3ra edad 66 - 99 ###
ages1 <- count(data3, "age")
ages1
## # A tibble: 1 x 2
## "age" n
## <chr> <int>
## 1 age 1500
pregunta_44 <- count(data3, "q44a")
pregunta_44_age <- count(data3, "q44a", "age")
age_count
## # A tibble: 1 x 2
## "age" n
## <chr> <int>
## 1 age 1500
filtrado_q44a <- data3[data3$q44a == 'Republican Party', 'Democratic Party', ]
filtrado_q44a
## NULL
data3[data3$q44a == 'Republican Party', data3$q44a == 'Democratic Party']
## data frame with 0 columns and 688 rows
choice <- count(data3, "partyln")
ages <- table(age)
attach(data3)
## The following object is masked _by_ .GlobalEnv:
##
## weight
## The following objects are masked from data3 (pos = 3):
##
## age, attempt, attend, birth_hisp, born, cellmin, cellweight,
## chr, cregion, density, educ2, fcall, form, hh1, hh3, hisp,
## ideo, igender, ilang, income, int_date, irace, llitext0,
## llweight, money2, money2token, offer2, OFFER2_FINAL, party,
## partyln, phoneuse, phoneuse2, psraid, q1, q11a, q11b, q11c,
## q15a, q15b, q15c, q15d, q15e, q16, q2, q20, q22a, q22b, q22c,
## q22d, q22e, q23, q24, q25, q26, q27, q28a, q28b, q28c, q28d,
## q28e, q30a, q30b, q30c, q30d, q30e, q31, q40, q41, q42, q43,
## q44a, q44b, q44c, q44d, q44ef1, q44ff2, q45, q45a, q45z,
## q46f1, q47f2, q48a, q48b, q48c, q48hf1, q48if2, q51a, q51b,
## q51c, q51d, q51e, q51f, q51g, q59f1, q60f2, q61, q62, q63,
## q69f1, q7, q7_oe1, q7_oe2, q7_oe3, q70f2, q71, q7vb, Q7VB0,
## q81, q82, q83, q84, q85, q90, q91, q92, qc1, qem1, qem2, qem3,
## ql1, ql1a, qs1, race3m1, race3m2, race3m3, race3m4, racecmb,
## racethn, refusal, reg, relig, sample, scregion, sex, sstate,
## state, susr, treatment, usr, weight
## The following objects are masked from data:
##
## age, attempt, attend, birth_hisp, born, cellmin, cellweight,
## chr, cregion, density, educ2, fcall, form, hh1, hh3, hisp,
## ideo, igender, ilang, income, int_date, irace, llitext0,
## llweight, money2, money2token, offer2, OFFER2_FINAL, party,
## partyln, phoneuse, phoneuse2, psraid, q1, q11a, q11b, q11c,
## q15a, q15b, q15c, q15d, q15e, q16, q2, q20, q22a, q22b, q22c,
## q22d, q22e, q23, q24, q25, q26, q27, q28a, q28b, q28c, q28d,
## q28e, q30a, q30b, q30c, q30d, q30e, q31, q40, q41, q42, q43,
## q44a, q44b, q44c, q44d, q44ef1, q44ff2, q45, q45a, q45z,
## q46f1, q47f2, q48a, q48b, q48c, q48hf1, q48if2, q51a, q51b,
## q51c, q51d, q51e, q51f, q51g, q59f1, q60f2, q61, q62, q63,
## q69f1, q7, q7_oe1, q7_oe2, q7_oe3, q70f2, q71, q7vb, Q7VB0,
## q81, q82, q83, q84, q85, q90, q91, q92, qc1, qem1, qem2, qem3,
## ql1, ql1a, qs1, race3m1, race3m2, race3m3, race3m4, racecmb,
## racethn, refusal, reg, relig, sample, scregion, sex, sstate,
## state, susr, treatment, usr, weight
party_ln <- table(partyln)
party_ln
## partyln
## Republican Democrat
## 268 210
## Other/Don't know/Refused (VOL.)
## 160
x <- ages[1:3]
y <- party_ln[1:3]
as.numeric(party_ln)
## [1] 268 210 160
as.numeric(ages)
## [1] 17 21 16 20 21 15 14 21 11 18 15 23 23 21 19 20 17 19 24 12 16 15 19
## [24] 23 20 20 20 27 17 28 26 31 29 22 26 26 35 38 26 20 36 26 27 33 30 38
## [47] 25 28 27 32 32 33 30 23 31 25 14 21 14 12 14 7 14 6 9 6 7 10 5
## [70] 5 4 2 3 2 1 2 15
cor(x,y)
## [1] 0.1468519
filtrado_rep<- filter(data3, partyln == 'Republican')
filtrado_dem <- filter(data3, partyln == 'Democrat')
filtrado_rep_dem <- rbind(filtrado_rep,filtrado_dem)
test <- group_by(filtrado_rep_dem, age, partyln) %>% summarise(n())
filtrado_rep<- filter(data3, partyln == 'Republican')
filtrado_dem <- filter(data3, partyln == 'Democrat')
filtrado_rep_dem <- rbind(filtrado_rep,filtrado_dem)
test2 <- group_by(filtrado_rep_dem, cut(age,breaks = seq(18,25,by = 7)), partyln) %>% summarise(numero_veces = n())
test2
## Source: local data frame [4 x 3]
## Groups: cut(age, breaks = seq(18, 25, by = 7)) [?]
##
## cut(age, breaks = seq(18, 25, by = 7)) partyln numero_veces
## <fctr> <fctr> <int>
## 1 (18,25] Republican 22
## 2 (18,25] Democrat 29
## 3 NA Republican 246
## 4 NA Democrat 181
test3 <- group_by(filtrado_rep_dem, cut(age,breaks = seq(26, 45,by = 19)), partyln) %>% summarise(numero_veces = n())
test3
## Source: local data frame [4 x 3]
## Groups: cut(age, breaks = seq(26, 45, by = 19)) [?]
##
## cut(age, breaks = seq(26, 45, by = 19)) partyln numero_veces
## <fctr> <fctr> <int>
## 1 (26,45] Republican 58
## 2 (26,45] Democrat 60
## 3 NA Republican 210
## 4 NA Democrat 150
test4 <- group_by(filtrado_rep_dem, cut(age,breaks = seq(46, 65,by = 19)), partyln) %>% summarise(numero_veces = n())
test4
## Source: local data frame [4 x 3]
## Groups: cut(age, breaks = seq(46, 65, by = 19)) [?]
##
## cut(age, breaks = seq(46, 65, by = 19)) partyln numero_veces
## <fctr> <fctr> <int>
## 1 (46,65] Republican 95
## 2 (46,65] Democrat 72
## 3 NA Republican 173
## 4 NA Democrat 138
test5 <- group_by(filtrado_rep_dem, cut(age,breaks = seq(66, 99,by = 33)), partyln) %>% summarise(numero_veces = n())
test5
## Source: local data frame [4 x 3]
## Groups: cut(age, breaks = seq(66, 99, by = 33)) [?]
##
## cut(age, breaks = seq(66, 99, by = 33)) partyln numero_veces
## <fctr> <fctr> <int>
## 1 (66,99] Republican 84
## 2 (66,99] Democrat 33
## 3 NA Republican 184
## 4 NA Democrat 177
trial <- group_by(filtrado_rep_dem, igender, partyln) %>% summarise(n())
trial
## Source: local data frame [4 x 3]
## Groups: igender [?]
##
## igender partyln n()
## <fctr> <fctr> <int>
## 1 Male Republican 83
## 2 Male Democrat 67
## 3 Female Republican 185
## 4 Female Democrat 143
counts <- table(data3$partyln, data3$age)
barplot(counts, main="POLITICAL PARTY AND AGE",
xlab="Age", col=c("deeppink","darkturquoise","darkviolet"),
legend = rownames(counts), beside=TRUE)
counts <- table(data3$igender, data3$partyln)
barplot(counts, main="POLITICAL PARTY AND AGE",
xlab="Age", col=c("darkturquoise","deeppink"),
legend = rownames(counts), beside=TRUE)
# Simple Plot
counts <- table(data3$trial)
slices <- c(67, 83, 143, 185)
lbls <- c("Male Democrat", "Male Republican","Female Democrat", "Female Republican")
pct <- round(slices/sum(slices)*100)
lbls <- paste(lbls, pct)
lbls <- paste(lbls,"%",sep="")
pie3D(slices,labels=lbls,explode=0.1,
main="Pie Chart Gender and Political Party")
#### Pregunta 1 ###
¿Influye la edad en la disposición de estar afiliado a cierto partido pol�tico? Para contestar la pregunta, en R compare los partidos politicos con las edades de los entrevistados, las separe por rangos: los jovenes edades de 18 a 25 años, los adulos edades de 26 a 45 años, los adultos mayores edades de 46 a 65 años y por ultimo los de la tercera edad edades de 66 a 99 años. Los jovenes representa una pequeña cantidad de votos para ambos partidos, y los votos estan muy cerca unos de otro ya que 22 jovenes votaron por el partido republicano y 29 por el partido democratico. Los adultos tambien representan una pequeña parte de la data acerca de que partido politico prefieren y ambos estan cerca uno del otro, ya que 58 adultos votaron por el partido republicano y 60 por el partido democratico. Los adultos mayores son un grupo fuerte que aporta mucha informacion a la data ya que son el grupo que contiene mas encuestados, por ende 95 personas prefieren el partido republicano y 72 el partido democrata, si pbservamos estas dos respuestas estan mas alejadas una de la otra. Por ultimo los de la tercera edad que son el segundo grupo mas fuerte, quienes respondieron que 84 estan a favor del partido republicano y 33 a favor del partido democrata. Estos valores de la data tambien se encuentran alejados unos de otros. En conclusion la edad si puede llegar a afectar la opinion de los votantes, ya que claramente se puede ver que de las edades de 46 hasta 99 años, los cuales han tenido mas experiencia en votaciones y conocen mas acerca de la politica que los jovenes que empiezan a integrarse a ellos, pues tienen una clara preferencia por el partido republicano.
#### termina pregunta 1 ####
#### Pregunta 2 ####
¿El sexo del candidato influye en la decisión de los votantes?
El sexo del candidato no influye en la decision ya que se comparo los encuestados masculinos y las encuestadas femeninas y se obtuvo data de por quien tienen preferencia los encuestados. En ambos sexos el partido republicano es quien domina, ya que obtuvo un total de 83 hombres y 185 mujeres, mientras el partido democratico obtuvo un total de 67 hombres y 143 mujeres. Los representantes politicos de hoy son Hillary Clinton (Democratic Party) y Donald Trump (Republican Party), en conclusion la mayoria de hombres y mujeres estan a favor de Donal Trump, por lo que esto demuestra que el sexo no influye en la desision de los votantes.
#### Termina pregunta 2 ####
q25 = Do you think there has been too much, too little or the right amount of expression of religious faith and prayer by political leaders?
q26 = At the present time, do you think religion as a whole is increasing its influence on American life or losing its influence?
q27 = All in all, do you think this is a good thing or a bad thing?
q28 = How important is it to you that a president shares your religious beliefs? Is it [READ IN ORDER]?
library(ggplot2)#librerías necesarias
dt <- read.spss('Jan16 public.sav', to.data.frame=TRUE) #carga el dataset
## Warning in read.spss("Jan16 public.sav", to.data.frame = TRUE): Jan16
## public.sav: Unrecognized record type 7, subtype 14 encountered in system
## file
## Warning in read.spss("Jan16 public.sav", to.data.frame = TRUE): Jan16
## public.sav: Unrecognized record type 7, subtype 18 encountered in system
## file
## Warning in read.spss("Jan16 public.sav", to.data.frame = TRUE): Jan16
## public.sav: Unrecognized record type 7, subtype 24 encountered in system
## file
reinfluence <- dt %>% group_by(q26,party) %>%
filter(q26 == "Increasing influence") %>%
summarise(frec = n())
rething <- dt %>% group_by(q27,party) %>%
filter(q27 == "Bad thing") %>%
summarise(frec = n())
reimpor <- dt %>% group_by(q28,party) %>%
filter(q28 == "Very important") %>%
summarise(frec = n())
resomimpor <- dt %>% group_by(q28,party) %>%
filter(q28 == "Somewhat important") %>%
summarise(frec = n())
a <- ggplot(dt, aes(q25))
a + geom_bar(fill= 'deeppink2', colour='deeppink3')
b <- ggplot(dt, aes(q26))
b+ geom_bar(fill= 'cyan3', colour='cyan4')
c <- ggplot(dt, aes(q27))
c+ geom_bar(fill= 'seagreen1', colour='seagreen3')
d <- ggplot(dt, aes(q28))
d+ geom_bar(fill= 'lightseagreen', colour='cyan4')
rel <- dt %>% group_by(relig) %>%
summarise(frec = n())
rel #religion y su frecuencia
## # A tibble: 15 x 2
## relig
## <fctr>
## 1 Protestant (Baptist, Methodist, Non-denominational, Lutheran, Presbyterian,
## 2 Roman Catholic (Catholic)
## 3 Mormon (Church of Jesus Christ of Latter-day Saints/LDS)
## 4 Orthodox (Greek, Russian, or some other orthodox church)
## 5 Jewish (Judaism)
## 6 Muslim (Islam)
## 7 Buddhist
## 8 Hindu
## 9 Atheist (do not believe in God)
## 10 Agnostic (not sure if there is a God)
## 11 Something else (SPECIFY)
## 12 Nothing in particular
## 13 (VOL) Christian
## 14 (VOL) Unitarian (Universalist)
## 15 (VOL) Don't know/Refused
## # ... with 1 more variables: frec <int>
relde <- dt %>% group_by(relig,party) %>%
filter(party == "Democrat") %>%
summarise(frec = n())
relde #incidencia entre religión y los que son democráticos
## Source: local data frame [14 x 3]
## Groups: relig [?]
##
## relig
## <fctr>
## 1 Protestant (Baptist, Methodist, Non-denominational, Lutheran, Presbyterian,
## 2 Roman Catholic (Catholic)
## 3 Mormon (Church of Jesus Christ of Latter-day Saints/LDS)
## 4 Jewish (Judaism)
## 5 Muslim (Islam)
## 6 Buddhist
## 7 Hindu
## 8 Atheist (do not believe in God)
## 9 Agnostic (not sure if there is a God)
## 10 Something else (SPECIFY)
## 11 Nothing in particular
## 12 (VOL) Christian
## 13 (VOL) Unitarian (Universalist)
## 14 (VOL) Don't know/Refused
## # ... with 2 more variables: party <fctr>, frec <int>
relrep <- dt %>% group_by(relig,party) %>%
filter(party == "Republican") %>%
summarise(frec = n())
relrep #religion vrs republicanos
## Source: local data frame [14 x 3]
## Groups: relig [?]
##
## relig
## <fctr>
## 1 Protestant (Baptist, Methodist, Non-denominational, Lutheran, Presbyterian,
## 2 Roman Catholic (Catholic)
## 3 Mormon (Church of Jesus Christ of Latter-day Saints/LDS)
## 4 Orthodox (Greek, Russian, or some other orthodox church)
## 5 Jewish (Judaism)
## 6 Muslim (Islam)
## 7 Buddhist
## 8 Hindu
## 9 Atheist (do not believe in God)
## 10 Agnostic (not sure if there is a God)
## 11 Something else (SPECIFY)
## 12 Nothing in particular
## 13 (VOL) Christian
## 14 (VOL) Don't know/Refused
## # ... with 2 more variables: party <fctr>, frec <int>
relindep<- dt %>% group_by(relig,party) %>%
filter(party == "Independent") %>%
summarise(frec = n())
relindep #religion vrs independientes
## Source: local data frame [15 x 3]
## Groups: relig [?]
##
## relig
## <fctr>
## 1 Protestant (Baptist, Methodist, Non-denominational, Lutheran, Presbyterian,
## 2 Roman Catholic (Catholic)
## 3 Mormon (Church of Jesus Christ of Latter-day Saints/LDS)
## 4 Orthodox (Greek, Russian, or some other orthodox church)
## 5 Jewish (Judaism)
## 6 Muslim (Islam)
## 7 Buddhist
## 8 Hindu
## 9 Atheist (do not believe in God)
## 10 Agnostic (not sure if there is a God)
## 11 Something else (SPECIFY)
## 12 Nothing in particular
## 13 (VOL) Christian
## 14 (VOL) Unitarian (Universalist)
## 15 (VOL) Don't know/Refused
## # ... with 2 more variables: party <fctr>, frec <int>
print(summary(rel$frec))
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 8.0 18.0 40.0 133.9 152.5 696.0
sd(rel$frec)
## [1] 198.8368
print(summary(relde$frec))
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.00 5.25 17.50 42.36 55.00 181.00
sd(relde$frec)
## [1] 55.02392
print(summary(relindep$frec))
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 4.00 10.00 13.00 49.53 64.00 202.00
sd(relindep$frec)
## [1] 63.95966
print(summary(relrep$frec))
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.00 3.25 6.50 38.43 25.25 273.00
sd(relrep$frec)
## [1] 75.38793
print(summary(reinfluence$frec))
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 5.0 11.0 58.5 85.0 160.8 198.0
sd(reinfluence$frec)
## [1] 88.17709
print(summary(rething$frec))
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 11.00 27.25 189.50 211.30 389.20 449.00
sd(rething$frec)
## [1] 205.0314
print(summary(reimpor$frec))
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.00 13.00 70.50 81.83 140.80 190.00
sd(reimpor$frec)
## [1] 80.35774
print(summary(resomimpor$frec))
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.00 11.00 67.00 81.17 155.20 174.00
sd(resomimpor$frec)
## [1] 80.6856
ree <- dnorm(resomimpor$frec)
plot(ree)
h <- ggplot(dt, aes(factor(party)))
h + geom_bar(fill= 'cyan3', colour='cyan4')
hh <- dt %>% group_by(party) %>%
summarise(frec = n())
print(summary(hh$frec))
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 14.00 48.25 311.50 334.80 579.20 743.00
sd(hh$frec)
## [1] 325.3241
plot(hh)
y si los queremos ver con porcentajes…
slices <- c(1, 2)
lbls <- c('Republican', 'Democrat')
pct <- round(slices/sum(slices)*100)
lbls<- paste(lbls, pct)
lbls <- paste(lbls, '%', sep='')
pie(slices, labels=lbls, col=rainbow(length(lbls)), radius = 1, labelcex=0.7,
main='Pie Chart of Party by %')
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : "labelcex" is not a graphical parameter
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : "labelcex" is not a graphical parameter
## Warning in title(main = main, ...): "labelcex" is not a graphical parameter
y de las 5 variables: relig, party, q27, state, attempt
boxplot(rel$frec)
boxplot(as.numeric(dt$party))
boxplot(as.numeric(dt$q27))
boxplot(as.numeric(dt$state))
boxplot(dt$attempt)
Si está sujeta a la ley de los grandes números. En los análisis de religión por partido político notamos que entre más delimitada esté la religión, más se dispersan los datos.
5, 6, 9 y 11: Andrea
ds2 <- read.spss("Dec15 public.sav", to.data.frame = TRUE)
## Warning in read.spss("Dec15 public.sav", to.data.frame = TRUE): Dec15
## public.sav: Unrecognized record type 7, subtype 14 encountered in system
## file
## Warning in read.spss("Dec15 public.sav", to.data.frame = TRUE): Dec15
## public.sav: Unrecognized record type 7, subtype 18 encountered in system
## file
## Warning in read.spss("Dec15 public.sav", to.data.frame = TRUE): Dec15
## public.sav: Unrecognized record type 7, subtype 24 encountered in system
## file
estadisticas <- function(x){ library(dplyr)
a <- ds2 %>% group_by(racecmb,party) %>%
filter(q20 == "A lot") %>%
summarise(frec = n())
#asignacion de variables descriptivas:
print(paste("Minimo: ", min(a$frec)))
print(paste("Cuartil No. 1: ", quantile(a$frec,na.rm = TRUE)[2]))
print(paste("Mediana: ", median(a$frec)))
print(paste("Promedio: " , mean(a$frec)))
print(paste("Cuartil No.3: ",quantile(a$frec,na.rm = TRUE)[3]))
print(paste("Rango: ", range(a$frec)))
print(paste("Intercuartil: ", IQR(a$frec)))
print(paste("Desviacion estandar: ", sd(a$frec, na.rm = TRUE)))
print(paste("Varianza: ", (sd(a$frec,na.rm = TRUE))^2))
print(paste("El porcentaje de ciudadnos que tengan una raza y esten afiliados a un partido politico arribe de la cantidad de 120 es: " , pnorm(120, mean = 28.44, sd = 66.53, lower.tail = FALSE)*100))
#recorrido para conocer que partido y raza son:
i <- 1
while(i <= nrow(a)){
if(a$frec[i] == max(a$frec)){
print(paste("Maximo: ", a$racecmb[i], a$party[i], max(a$frec)))
}
i <- i + 1
}
}
ds2 %>% group_by(racecmb,party) %>%
filter(q20 == "A lot") %>%
summarise(frec = n())
## Source: local data frame [29 x 3]
## Groups: racecmb [?]
##
## racecmb party frec
## <fctr> <fctr> <int>
## 1 White Republican 249
## 2 White Democrat 181
## 3 White Independent 224
## 4 White No preference (VOL.) 8
## 5 White Other party (VOL.) 5
## 6 White Don't know/Refused (VOL.) 5
## 7 Black Republican 8
## 8 Black Democrat 35
## 9 Black Independent 18
## 10 Black No preference (VOL.) 1
## # ... with 19 more rows
estadisticas(ds2)
## [1] "Minimo: 1"
## [1] "Cuartil No. 1: 1"
## [1] "Mediana: 5"
## [1] "Promedio: 28.448275862069"
## [1] "Cuartil No.3: 5"
## [1] "Rango: 1" "Rango: 249"
## [1] "Intercuartil: 11"
## [1] "Desviacion estandar: 66.5301146672352"
## [1] "Varianza: 4426.25615763547"
## [1] "El porcentaje de ciudadnos que tengan una raza y esten afiliados a un partido politico arribe de la cantidad de 120 es: 8.43765719731594"
## [1] "Maximo: White Republican 249"
slices <- c(67, 83, 143, 185)
lbls <- c("Male Democrat", "Male Republican","Female Democrat", "Female Republican")
pct <- round(slices/sum(slices)*100)
lbls <- paste(lbls, pct)
lbls <- paste(lbls,"%",sep="")
pie3D(slices,labels=lbls,explode=0.1,
main="Pie Chart Gender and Political Party")
slices <- c(1, 2)
lbls <- c('Republican', 'Democrat')
pct <- round(slices/sum(slices)*100)
lbls<- paste(lbls, pct)
lbls <- paste(lbls, '%', sep='')
pie(slices, labels=lbls, col=rainbow(length(lbls)), radius = 1, labelcex=0.7,
main='Pie Chart of Party by %')
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : "labelcex" is not a graphical parameter
## Warning in text.default(1.1 * P$x, 1.1 * P$y, labels[i], xpd = TRUE, adj =
## ifelse(P$x < : "labelcex" is not a graphical parameter
## Warning in title(main = main, ...): "labelcex" is not a graphical parameter