Creaciòn de datos. Markdown

# Generaciòn de datos 
set.seed(1234)
d <- runif(n=240, min=4, max=6)
d
##   [1] 4.227407 5.244599 5.218549 5.246759 5.721831 5.280621 4.018992 4.465101
##   [9] 5.332168 5.028502 5.387183 5.089950 4.565467 5.846867 4.584632 5.674591
##  [17] 4.572447 4.533642 4.373446 4.464452 4.633225 4.605387 4.318092 4.079992
##  [25] 4.437599 5.621197 5.051395 5.829316 5.662690 4.091541 4.912183 4.530373
##  [33] 4.609344 5.014614 4.362192 5.519341 4.402496 4.517620 5.984301 5.614705
##  [41] 5.106667 5.292812 4.623649 5.243638 4.659540 5.003995 5.354189 4.969982
##  [49] 4.487858 5.530920 4.147560 4.619373 5.434543 5.009092 4.305998 5.007867
##  [57] 4.987922 5.502400 4.349300 5.696785 5.729668 4.083715 4.634364 4.027500
##  [65] 4.478051 5.412989 4.616190 5.017095 4.103293 5.129140 4.242960 5.785673
##  [73] 4.029255 5.566242 4.179923 5.038380 4.768533 4.140105 4.641289 5.336991
##  [81] 5.852801 4.943819 4.285231 5.088540 4.392349 5.797161 4.779000 4.621742
##  [89] 4.320057 5.792372 4.332788 5.800849 4.268156 4.263228 4.210575 5.023167
##  [97] 4.600398 4.053434 4.619295 5.484239 4.070913 5.130152 4.560516 4.408393
## [105] 4.267478 4.651364 4.310124 4.259924 4.871062 4.077285 5.426603 4.201538
## [113] 5.900610 4.243636 4.439313 5.826176 5.891706 4.558312 4.246942 5.594321
## [121] 5.488554 5.831948 5.989196 5.884721 4.972271 4.566919 4.503091 5.006510
## [129] 4.993932 4.636892 5.924446 5.268199 4.254867 4.846094 5.828634 4.935585
## [137] 5.816338 5.195487 5.263486 5.738317 5.005500 5.967270 4.648772 4.962750
## [145] 4.713974 5.254955 5.483200 5.131934 5.961573 5.153625 4.878084 4.457199
## [153] 4.164316 5.700530 4.469323 5.976335 5.203795 5.997482 4.751199 5.110253
## [161] 4.858888 5.151756 4.865015 4.449692 4.169969 5.274597 4.862033 4.145432
## [169] 5.604804 4.650557 5.514578 5.168543 5.417679 4.853952 4.687145 5.518240
## [177] 4.848060 5.121775 4.232272 4.606044 4.957605 4.689661 5.201428 4.152167
## [185] 5.911985 4.044414 5.683421 5.264885 4.620188 5.485139 5.277823 5.985032
## [193] 4.256540 5.766479 5.620167 5.643702 5.669405 5.465464 5.966088 5.278409
## [201] 5.321509 5.056719 4.634988 5.535711 5.052617 5.464604 4.615331 4.808347
## [209] 4.408805 5.971266 5.132622 4.560750 4.370111 5.516123 5.133563 5.864347
## [217] 5.277387 5.401496 4.958445 5.700624 4.844661 4.062784 4.516293 4.669689
## [225] 4.267099 4.999093 5.604271 4.674306 5.017841 4.988877 5.594106 5.133918
## [233] 4.213394 5.615297 5.134224 4.424482 5.499159 4.614437 4.979037 5.979420
d <-round(d,2) #Para redondear a dos decimales de un datos

orient <- gl(n=2, k=120, length=240, labels=c("ecuatorial", "longitudinal"))
df <-data.frame(orient,d) 
head(df)
##       orient    d
## 1 ecuatorial 4.23
## 2 ecuatorial 5.24
## 3 ecuatorial 5.22
## 4 ecuatorial 5.25
## 5 ecuatorial 5.72
## 6 ecuatorial 5.28
tail(df)
##           orient    d
## 235 longitudinal 5.13
## 236 longitudinal 4.42
## 237 longitudinal 5.50
## 238 longitudinal 4.61
## 239 longitudinal 4.98
## 240 longitudinal 5.98

Resumen estadìstico descriptivo

## Boxplot o diagrama de cajas

boxplot(d~orient, horizontal = T, col=c("lightgreen", "lightblue"))

## Agregando promedios a las cajas

med <- tapply(d,orient,mean)  ## funciona sobre tabalas 

## boxplot mas medias 

boxplot(d~orient, horizontal = T, col=c("lightgreen", "lightblue"), xlab="Diametro (cm)", ylab="Orientaciòn")
points(y=1:2, x=med, pch=16, col="red")
rug(d, lwd=2)

hist(d,breaks = 10)

library(ggplot2)

#Densidad 
# Densidad 
set.seed(1234)
# Generación de datos 
d = runif(n = 240,min = 4,max = 6)
orient = gl(n = 2,k = 120,length = 240,labels = c("ecuatorial","longitudinal"))
# Grafico de histogramas
ggplot(df,aes(x=d,fill=orient))+
  geom_histogram(alpha=0.4)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Investigar como realizar un bi histograma

# Grafico de cajas o boxplot
ggplot(df,aes(x=d,fill=orient))+
  geom_boxplot(alpha=0.4)

# Grafico de violines
ggplot(df,aes(x=d,fill=orient,y=orient))+
  geom_violin(alpha=0.4)

# Usando ggplot2 
# Grafico de densidades
ggplot(df,aes(x=d,fill=orient))+
  geom_density(alpha=0.4)

df2=split(d,orient)
df2 = data.frame(ecuatorial=df2$ecuatorial,
                 longitudinal = df2$longitudinal)
ggplot(df2,aes(x=ecuatorial,
               y=longitudinal))+  geom_point(size=2)

# Dist. exponencial 

d2 = rexp(n = 24,rate = 1/4)

Campo de ecuacion \(\Latex\)

\[t=\frac{\bar x-\mu}{s\sqrt{n}}\]

La ecuaciòn anterior representa un estadistico de prueba t-student

Resumen descriptivo numèrico

library(psych)
## 
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
psych::describe(d)
##    vars   n mean   sd median trimmed mad  min max range skew kurtosis   se
## X1    1 240 4.98 0.57   4.99    4.97 0.7 4.02   6  1.98 0.11    -1.14 0.04
describe.by(d, group = orient)
## Warning: describe.by is deprecated.  Please use the describeBy function
## 
##  Descriptive statistics by group 
## group: ecuatorial
##    vars   n mean   sd median trimmed mad  min  max range skew kurtosis   se
## X1    1 120 4.85 0.57   4.65    4.83 0.6 4.02 5.98  1.97 0.34    -1.18 0.05
## ------------------------------------------------------------ 
## group: longitudinal
##    vars   n mean   sd median trimmed  mad  min max range  skew kurtosis   se
## X1    1 120  5.1 0.53   5.13    5.11 0.65 4.04   6  1.95 -0.05    -0.96 0.05

La curtosis denota la distribuciòn de los datos