Professional Documents
Culture Documents
Programación en R
Probabilidad y Estadı́stica Fundamental
Docente: Martı́n Macı́as
Agosto 2018
ls ()
class ( x )
sex <- c ( " M " ," M " ," M " ," M " ," H " ," H " )
esc <- c ( rep ( " Primaria " ,3) , " Secundaria " , rep ( " Universitario " ,2))
height <- c (1.75 , 1.80 , 1.65 , 1.90 , 1.74 , 1.91) ; height ; class ( height )
bmi <- weight / height ^2; bmi ; class ( bmi )
1
# === Distribuciones de frecuencias ( tabular y grafica )
table ( sex )
prop . table ( table ( esc ))
pie ( table ( esc ))
stem ( weight )
stem ( height )
hist ( height )
boxplot ( height )
mean ( weight )
median ( weight )
quantile ( weight , probs = c (0.25 ,0.5 ,0.75))
# === Dispersion
IQR . weight <- quantile ( weight , probs = c (0.75)) - quantile ( weight , probs = c (0.25))
range ( weight )
var ( weight )
sd ( weight )
cv <- sd ( weight ) / xbar
IQR ( weight )
# === Forma
install . packages ( " e1071 " , dependencies = T ) ; library ( e1071 )
skewness ( weight , type =1)
kurtosis ( weight , type =1)
2
# === Datos de ejemplo
sex <- c ( " M " ," M " ," M " ," H " ," H " ," M " ," M " ," M " ," H " ," H " )
esc <- c ( rep ( " Primaria " ,4) , " Secundaria " , rep ( " Universitario " ,2) , rep ( " Secundaria " ,3))
datos = data . frame ( Peso = weight , Estatura = height , IMC = bmi , Sexo = sex , Escolaridad = esc )
# Cualitativa - cualitativa
barplot ( table ( sex , esc ) , col = terrain . colors (2) , beside = TRUE ,
main = " Escolaridad vs Sexo al nacer " , legend . text = TRUE ,
xlab = " Escolaridad " , ylab = " Frecuencia Absoluta " )
# Cualitativa - cuantitativa
boxplot ( IMC ~ Sexo , data = datos , main = " IMC vs Sexo al nacer " ,
ylab = " IMC " , xlab = " Sexo " )
boxplot ( IMC ~ Escolaridad , data = datos , main = " Escolaridad vs Sexo al nacer " ,
ylab = " IMC " , xlab = " Escolaridad " )
# Cuantitativa - cuantitativa
plot ( Peso ~ Estatura , data = datos , main = " Peso vs Estatura " )
datos . cuanti <- datos [ , c ( " Peso " ," Estatura " ," IMC " )]
plot ( datos . cuanti , main = " Matriz de dispersion " )
# Cualitativa - cualitativa
# Cualitativa - cuantitativa
# Cuantitativa - cuantitativa
cov ( datos . cuanti )
cor ( datos . cuanti )