Está en la página 1de 17

UNIVERISIDAD DEL MAGDALENA

FACULTAD DE INGENIERIA

FINAL WORK
ESTADISTICA 1

AUTOR
WILLIAM DAVID CAMPO LÓPEZ - 2021216103
DAYANA MISHELL NARVAEZ PATIÑO - 2021216100
KEVIN TELLO MORALES - 2021216021
JUAN DAVID VANEGAS CARO - 2021216116
JUAN SEBASTIÁN BUSTAMANTE MANJARRES - 2021216015

DOCENTE
CARLOS MIGUEL RODRÍGUEZ MORENO

GRUPO 5

SANTA MARTA-COLOMBIA 11/06/2022


FINAL WORK
Instructions
The final work should be delivered in the previously formed groups.
Load a PDF file and the R script support on Campus Virtual, if one of these requirements
are missing, the final work will not be received.

Deadline: 11/06/2022 at 11:59 p.m.

Load the packages LSD, plyr, psych, ggplot2, MASS, plotrix and Publish on R.

1. Use the rnorm command, run a sample of 10000 numbers for two variables X and
Y, the X variable with mean 8 and standard deviation 10, and the Y variable with
mean 3 and standard deviation 7:

x <- rnorm(10000, mean = 8, sd = 10)


y <- rnorm(10000, mean = 3, sd = 7)

2. Draw histograms for X and Y. Conclude.


Como se puede observar en los histogramas de la variable x y la variable y, en ambos los datos tienen
un comportamiento de campana de Gauss, por lo que se puede inferir que tanto x como y tienen una
distribución normal.

3. Draw the next scatter plots and conclude,


a) Scatterplot with the command plot(x,y,main=”10000 points scatterplot”)

En este grafico se puede observar que la mayor parte de los datos están concentrados, por lo que hay
poca dispersión.
b) HeatScatter with the command heatscatter(x,y)
En el gráfico de dispersión de calor se puede observar de mejor forma, como los datos están
concentrados la mayoría en el centro del gráfico, muy cerca uno del otro, lo que indica baja dispersión
c) SmoothScatter with the command smoothScatter(x,y)

Al igual que con el gráfico anterior, con el gráfico de dispersión suave podemos observar que hay
una alta concentración de los datos, pero además se puede ver los datos atípicos de las áreas con las
densidades regionales menores.
4. Draw Boxplots for each variable, conclude.

En el gráfico de caja de la variable x se puede observar que los datos siguen los parámetros iniciales
de media 8 y desviación estándar 10, además nos muestra que los datos atípicos se encuentran
cercanos a valores de 40 y -20.

En el gráfico de caja de la variable x se puede observar que los datos siguen los parámetros iniciales
de media 3 y desviación estándar 7, además nos muestra que los datos atípicos se encuentran
cercanos a valores de 25 y -15.
Load the sleep dataframe from the package datasets.
5. What the dataset parameters represent?

Datos que muestran el efecto de dos fármacos soporíferos (aumento de las horas de sueño respecto al
control) en 10 pacientes.

Un marco de datos con 20 observaciones sobre 3 variables.

[, 1] extra numérico aumento de horas de sueño


[, 2] grupo factor medicamento administrado
[, 3] IDENTIFICACIÓN factor ID del paciente

6. Draw boxplots and 90% confidence intervals (with the command error.bars (psych
package)) of the extra variable in function of the independent variable group. Use
the ddply function (plry package) for the confidence intervals and its parameters.
Conclude.
error.bars(sleep, alpha = 0.1)

ddply(sleep, .(extra, group))


extra group ID
1 -1.6 1 2
2 -1.2 1 4
3 -0.2 1 3
4 -0.1 1 5
5 -0.1 2 5
6 0.0 1 9
7 0.1 2 4
8 0.7 1 1
9 0.8 1 8
10 0.8 2 2
11 1.1 2 3
12 1.6 2 8
13 1.9 2 1
14 2.0 1 10
15 3.4 1 6
16 3.4 2 10
17 3.7 1 7
18 4.4 2 6
19 4.6 2 9
20 5.5 2 7

7. Draw a coplot or ggplot with the ggplot2 library, relate the extra variable (response)
with its two independent variables. Interpret the graphics, a relation between the
variables can be inferred.
Con la información visual que nos proporcionan los gráficos, se puede inferir que hay relación entre
las variables extra y group.

8. Draw a histogram for the response variable extra, conclude.


Con el grafico del histograma se puede observar que los datos de la variable extra tienen un
comportamiento de campana de Gauss, pero con una dispersión elevada.

9. For each variable, calculate the mean, median, standard deviation, variance, min,
max, range.

Para la variable extra:


> mean(extra)
[1] 1.54
> median(extra)
[1] 0.95
> sd(extra)
[1] 2.01792
> var(extra)
[1] 4.072
> min(extra)
[1] -1.6
> max(extra)
[1] 5.5
> max(extra)-min(extra)
[1] 7.1
> range(extra)
[1] -1.6 5.5

Para la variable group:


> mean(group)
[1] 1.5
> median(group)
[1] 1.5
> sd(group)
[1] 0.5129892
> var(group)
[1] 0.2631579
> min(group)
[1] 1
> max(group)
[1] 2
> max(group)-min(group)
[1] 1
> range(group)
[1] 1 2

Para la variable ID:


> mean(ID)
[1] 5.5
> median(ID)
[1] 5.5
> sd(ID)
[1] 2.946898
> var(ID)
[1] 8.684211
> min(ID)
[1] 1
> max(ID)
[1] 10
> max(ID)-min(ID)
[1] 9
> range(ID)
[1] 1 10

The next database refers to the differents variables of the San Andrés homes in poverty
(2016 year):

10. The file “hogares_2016.txt” contains the database necessary for the next
questions, download it in your working directory and read it with the command
read.delim(“hogares_2016.txt”,header=T)

datos = read.delim("hogares_2016.txt", header=T)

11. Interpret the read dataframe, how many observations have? how many variables?

El dataframe contiene información de los hogares de alguna población en el año 2016, este tiene
3326 observaciones y 21 variables.

12. Identify the class of the variables 5 and 6, are those string or numbers?

Las variables 5 y 6 son p5010 y p5090 respectivamente. Ambas variables son de tipo numérico.

Based on what was previously applied, present a descriptive report on the official results
of the parliamentary elections in Colombia for the year 2022.

Resultados de votaciones parlamentarias 2022:

Pacto Histórico (1)- 2.692.999


Partido Conservador (2) - 2.201.183
Partido Liberal (3)- 2.078.858
Coalición Alianza Verde y Centro Esperanza (4) - 1.906.021
Centro Democrático (5) - 1.874.762
Cambio Radical (6) - 1.586.284
Partido de la U (7) - 1.494.098
Coalición MIRA - Colombia Justa Libres (8) - 564.737
Fuerza Ciudadana (9) - 417.300
Nuevo Liberalismo (10) - 352.704
Estamos Listas (11) - 108.657
Movimiento Nacional Sector Organizado de la Salud (12) - 55.046
Movimiento Gente Nueva (13) - 36.346
Movimiento de Salvación Nacional (14)- 30.066
Partido Comunes (15) - 24.862
Movimiento Unitario Metapolítico (16)- 11.915

Votos en blanco (17) - 1.052.395


Votos nulos (18) - 732.003
Votos no marcados (19) - 524.982

Tabulamos los datos:

partido votos
1 2692999
2 2201183
3 2078858
4 1906021
5 1874762
6 1586284
7 1494098
8 564737
9 417300
10 352704
11 108657
12 55046
13 36346
14 30066
15 24862
16 11915
17 1052395
18 732003
19 524982

Cargamos los datos en r:

datos_v = read.delim("votaciones_2022.txt")

Asignamos el conjunto de datos a cada variable:

y1 = with(datos_v, partido)
x1 = with(datos_v, votos)

Se dibujan los histogramas:


Calculamos los datos de las variables:

Para y1:
> mean(y1)
[1] 10
> median(y1)
[1] 10
> sd(y1)
[1] 5.627314
> var(y1)
[1] 31.66667
> min(y1)
[1] 1
> max(y1)
[1] 19
> max(y1)-min(y1)
[1] 18
> range(y1)
[1] 1 19

Para x1:
> mean(x1)
[1] 933958.8
> median(x1)
[1] 564737
> sd(x1)
[1] 891201.8
> var(x1)
[1] 794240578337
> min(x1)
[1] 11915
> max(x1)
[1] 2692999
> max(x1)-min(x1)
[1] 2681084
> range(x1)
[1] 11915 2692999

Graficas:

También podría gustarte