###Problema 1####

mujer<-c(75,77,78,79,77,73,78,79,78,80)
hombre<-c(74,72,77,76,76,73,75,73,74,75)
sexo<-c(rep("mujer",10),rep("hombre",10))
temp<-c(mujer,hombre)
datos<-data.frame(sexo=sexo, T=temp)
temperatura<-c(mujer,hombre)
datos
##      sexo  T
## 1   mujer 75
## 2   mujer 77
## 3   mujer 78
## 4   mujer 79
## 5   mujer 77
## 6   mujer 73
## 7   mujer 78
## 8   mujer 79
## 9   mujer 78
## 10  mujer 80
## 11 hombre 74
## 12 hombre 72
## 13 hombre 77
## 14 hombre 76
## 15 hombre 76
## 16 hombre 73
## 17 hombre 75
## 18 hombre 73
## 19 hombre 74
## 20 hombre 75
resultado <- t.test(mujer, hombre,
                    alternative = "two.sided",
                    var.equal = FALSE)
print(resultado)
## 
##  Welch Two Sample t-test
## 
## data:  mujer and hombre
## t = 3.5254, df = 16.851, p-value = 0.002626
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  1.163304 4.636696
## sample estimates:
## mean of x mean of y 
##      77.4      74.5
datos$sexo<-factor(datos$sexo)
boxplot(T~sexo,data=datos,col=c("orange","green"))

library(car)
## Cargando paquete requerido: carData
leveneTest(T~sexo,data=datos,center=mean)
## Levene's Test for Homogeneity of Variance (center = mean)
##       Df F value Pr(>F)
## group  1  0.2085 0.6534
##       18

##Problema2####

actual<-c(1.88,1.84,1.83,1.90,2.19,1.89,2.27,2.03,1.96,1.98,2.00,1.92,1.83,1.94,1.94,1.95,1.93,2.01)
nuevo <-c(1.87,1.90,1.85,1.88,2.18,1.87,2.23,1.97,2.00,1.98,1.99,1.89,1.78,1.92,2.02,2.00,1.95,2.05)

resultado <- t.test(actual, nuevo,
                    alternative = "two.sided",paired=TRUE,
                    var.equal = FALSE)

print(resultado)
## 
##  Paired t-test
## 
## data:  actual and nuevo
## t = -0.23874, df = 17, p-value = 0.8142
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -0.02186024  0.01741580
## sample estimates:
## mean difference 
##    -0.002222222
desgaste<-c(264, 260, 258, 241, 262, 255,208, 220, 216, 200, 213, 206,220, 263, 219, 225, 230, 228,217, 226, 215, 227, 220, 222)
tipocuero<-c(rep("A",6),rep("B",6),rep("C",6), rep("D",6))
datos<-data.frame(tipocuero=tipocuero,desgaste=desgaste)
datos
##    tipocuero desgaste
## 1          A      264
## 2          A      260
## 3          A      258
## 4          A      241
## 5          A      262
## 6          A      255
## 7          B      208
## 8          B      220
## 9          B      216
## 10         B      200
## 11         B      213
## 12         B      206
## 13         C      220
## 14         C      263
## 15         C      219
## 16         C      225
## 17         C      230
## 18         C      228
## 19         D      217
## 20         D      226
## 21         D      215
## 22         D      227
## 23         D      220
## 24         D      222
datos$tipocuero<-factor(datos$tipocuero)
modelo<-aov(desgaste~tipocuero,data=datos)
summary(modelo)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## tipocuero    3   7019  2339.8   22.75 1.18e-06 ***
## Residuals   20   2056   102.8                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
boxplot(desgaste~tipocuero,data=datos,col=c("orange","red","yellow","green"))

plot(modelo)

###Regresión lineal###

x1<-seq(0,10,length=10)
y<-0.8+2.3*x1
y<-y+rnorm(1,0,1.5)
plot(x1,y)

modelo<-lm(y~x1)
summary(modelo)
## Warning in summary.lm(modelo): essentially perfect fit: summary may be
## unreliable
## 
## Call:
## lm(formula = y ~ x1)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -1.985e-15 -1.614e-15 -2.227e-16  9.741e-16  3.136e-15 
## 
## Coefficients:
##               Estimate Std. Error    t value Pr(>|t|)    
## (Intercept) -5.588e-01  1.143e-15 -4.887e+14   <2e-16 ***
## x1           2.300e+00  1.928e-16  1.193e+16   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.945e-15 on 8 degrees of freedom
## Multiple R-squared:      1,  Adjusted R-squared:      1 
## F-statistic: 1.424e+32 on 1 and 8 DF,  p-value: < 2.2e-16
plot(modelo)

yajustado<-modelo$fitted.values
plot(x1,y)
lines(x1,yajustado,col="red",lwd=2)