summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
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
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("green","orange","red","blue"))
plot(modelo)
shapiro.test(modelo$residuals)
##
## Shapiro-Wilk normality test
##
## data: modelo$residuals
## W = 0.88326, p-value = 0.00967
Note that theecho = FALSE` parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.
hist(modelo$residuals,breaks=5)
TukeyHSD(modelo)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = desgaste ~ tipoCuero, data = datos)
##
## $tipoCuero
## diff lwr upr p adj
## B-A -46.166667 -62.552998 -29.780336 0.0000008
## C-A -25.833333 -42.219664 -9.447002 0.0014117
## D-A -35.500000 -51.886331 -19.113669 0.0000349
## C-B 20.333333 3.947002 36.719664 0.0118160
## D-B 10.666667 -5.719664 27.052998 0.2926431
## D-C -9.666667 -26.052998 6.719664 0.3742863
##Regresion Lineal
x1<-seq(0,10,0.5)
y<-0.8+2.3*x1
plot(x1,y)
x1<-seq(0,10,lenght=10)
## Warning: In seq.default(0, 10, lenght = 10) :
## extra argument 'lenght' will be disregarded
y<-0.8+2.3*x1
y<-y+rnorm(10,0,1.5)
## Warning in y + rnorm(10, 0, 1.5): longitud de objeto mayor no es mĂșltiplo de la
## longitud de uno menor
plot(x1,y)
modelo<-lm(y~x1)
summary(modelo)
##
## Call:
## lm(formula = y ~ x1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.8306 -1.0975 -0.3511 1.0105 3.0256
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.5228 0.9072 -0.576 0.579
## x1 2.5373 0.1533 16.546 4.8e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.608 on 9 degrees of freedom
## Multiple R-squared: 0.9682, Adjusted R-squared: 0.9646
## F-statistic: 273.8 on 1 and 9 DF, p-value: 4.798e-08
yajustado<-modelo$fitted.values
plot(x1,y)
lines(x1,yajustado,col="red",lwd=2)