You are on page 1of 3

Beer goggles

Data
library(WRS2)

## Warning: package 'WRS2' was built under R version 4.1.2


data("goggles")

head(goggles)

## gender alcohol attractiveness


## 1 Female None 65
## 2 Female None 70
## 3 Female None 60
## 4 Female None 60
## 5 Female None 60
## 6 Female None 55

Estimación MCO
bary..=mean(goggles$attractiveness)
bary..

## [1] 58.33333
baryi.=aggregate(attractiveness~alcohol, data=goggles, FUN = mean)
baryi.

## alcohol attractiveness
## 1 None 63.7500
## 2 2 Pints 64.6875
## 3 4 Pints 46.5625
goggles2=merge(goggles,baryi.,by=c("alcohol"))
ECM=sum((goggles2$attractiveness.x-goggles2$attractiveness.y)ˆ2)/(nrow(goggles)-nrow(baryi.))
ECM

## [1] 125.2083

Intervalos de 95% de confianza para µi


model0=lm(attractiveness~alcohol-1, data=goggles)
summary(model0)

##
## Call:
## lm(formula = attractiveness ~ alcohol - 1, data = goggles)
##
## Residuals:

1
## Min 1Q Median 3Q Max
## -26.5625 -5.1562 0.3125 6.7969 23.4375
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## alcoholNone 63.750 2.797 22.79 <2e-16 ***
## alcohol2 Pints 64.688 2.797 23.12 <2e-16 ***
## alcohol4 Pints 46.562 2.797 16.64 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 11.19 on 45 degrees of freedom
## Multiple R-squared: 0.9673, Adjusted R-squared: 0.9651
## F-statistic: 443.7 on 3 and 45 DF, p-value: < 2.2e-16
confint(model0)

## 2.5 % 97.5 %
## alcoholNone 58.11572 69.38428
## alcohol2 Pints 59.05322 70.32178
## alcohol4 Pints 40.92822 52.19678

ANOVA
attract.fit<-aov(attractiveness~alcohol, data=goggles)
summary(attract.fit)

## Df Sum Sq Mean Sq F value Pr(>F)


## alcohol 2 3332 1666.1 13.31 2.88e-05 ***
## Residuals 45 5634 125.2
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
MSE=sigma(attract.fit)ˆ2

Pruebas Múltiples
#Diferencias de pares

Ds=c(baryi.[2,2]-baryi.[1,2],baryi.[3,2]-baryi.[1,2],baryi.[3,2]-baryi.[2,2])

Duncan

N=nrow(goggles)
n=16

Sbaryi=sqrt(MSE/n)
df=N-3
rpf=c(2.86,3.01)
R=rpf*Sbaryi

abs(Ds[3])>R[2]

## [1] TRUE

2
abs(Ds[1])>R[1]

## [1] FALSE
abs(Ds[2])>R[1]

## [1] TRUE
# Diferencias 4 Pints-2 Pints y 4 Pints-None

Tukey

# manualmente
(abs(Ds)/sqrt(MSE/n)) > qtukey(0.05, 3, df, lower.tail = F)

## [1] FALSE TRUE TRUE


#p-value
ptukey((abs(Ds)/sqrt(MSE/n)), 3, df, lower.tail = F)

## [1] 0.9695380643 0.0002282686 0.0001067043


#intervalos de confianza 95%
t(rbind(Ds-qtukey(0.05, 3, df, lower.tail = F) * sqrt(MSE/n),
Ds+qtukey(0.05, 3, df, lower.tail = F) * sqrt(MSE/n)))

## [,1] [,2]
## [1,] -8.650654 10.525654
## [2,] -26.775654 -7.599346
## [3,] -27.713154 -8.536846
#función implementada
TukeyHSD(attract.fit)

## Tukey multiple comparisons of means


## 95% family-wise confidence level
##
## Fit: aov(formula = attractiveness ~ alcohol, data = goggles)
##
## $alcohol
## diff lwr upr p adj
## 2 Pints-None 0.9375 -8.650654 10.525654 0.9695381
## 4 Pints-None -17.1875 -26.775654 -7.599346 0.0002283
## 4 Pints-2 Pints -18.1250 -27.713154 -8.536846 0.0001067

Bonferroni

#intervalos de confianza 95%


t(rbind(Ds- qt((0.05/(2*3)),df, lower.tail = F) * sqrt((2*MSE)/n),
Ds+ qt((0.05/(2*3)),df, lower.tail = F) * sqrt((2*MSE)/n)))

## [,1] [,2]
## [1,] -8.900551 10.775551
## [2,] -27.025551 -7.349449
## [3,] -27.963051 -8.286949

You might also like