PROBLEMA 1

En el ejemplo los instructores se centran en el efecto de sus diferentes programas de educación nutricional, que son los tratamientos; no están preocupados por el efecto de una ciudad específica u otra per se, pero quieren tener en cuenta las diferencias debidas a las diferentes ciudades.

Instructor: bloque fijo Town: factor aleatorio

df<-read.csv("https://raw.githubusercontent.com/PedroGonzalezBeermann2020/DExperimental2021/main/Problema1.csv")
df
##       Instructor          Town Sodium
## 1   BrendonSmall Squiggleville   1200
## 2   BrendonSmall Squiggleville   1400
## 3   BrendonSmall Squiggleville   1350
## 4   BrendonSmall Metalocalypse    950
## 5   BrendonSmall Squiggleville   1400
## 6   BrendonSmall Squiggleville   1150
## 7   BrendonSmall Squiggleville   1300
## 8   BrendonSmall Metalocalypse   1325
## 9   BrendonSmall Metalocalypse   1425
## 10  BrendonSmall Squiggleville   1500
## 11  BrendonSmall Squiggleville   1250
## 12  BrendonSmall Metalocalypse   1150
## 13  BrendonSmall Metalocalypse    950
## 14  BrendonSmall Squiggleville   1150
## 15  BrendonSmall Metalocalypse   1600
## 16  BrendonSmall Metalocalypse   1300
## 17  BrendonSmall Metalocalypse   1050
## 18  BrendonSmall Metalocalypse   1300
## 19  BrendonSmall Squiggleville   1700
## 20  BrendonSmall Squiggleville   1300
## 21  CoachMcGuirk Squiggleville   1100
## 22  CoachMcGuirk Squiggleville   1200
## 23  CoachMcGuirk Squiggleville   1250
## 24  CoachMcGuirk Metalocalypse   1050
## 25  CoachMcGuirk Metalocalypse   1200
## 26  CoachMcGuirk Metalocalypse   1250
## 27  CoachMcGuirk Squiggleville   1350
## 28  CoachMcGuirk Squiggleville   1350
## 29  CoachMcGuirk Squiggleville   1325
## 30  CoachMcGuirk Squiggleville   1525
## 31  CoachMcGuirk Squiggleville   1225
## 32  CoachMcGuirk Squiggleville   1125
## 33  CoachMcGuirk Metalocalypse   1000
## 34  CoachMcGuirk Metalocalypse   1125
## 35  CoachMcGuirk Squiggleville   1400
## 36  CoachMcGuirk Metalocalypse   1200
## 37  CoachMcGuirk Squiggleville   1150
## 38  CoachMcGuirk Squiggleville   1400
## 39  CoachMcGuirk Squiggleville   1500
## 40  CoachMcGuirk Squiggleville   1200
## 41 MelissaRobins Metalocalypse    900
## 42 MelissaRobins Metalocalypse   1100
## 43 MelissaRobins Metalocalypse   1150
## 44 MelissaRobins Metalocalypse    950
## 45 MelissaRobins Metalocalypse   1100
## 46 MelissaRobins Metalocalypse   1150
## 47 MelissaRobins Squiggleville   1250
## 48 MelissaRobins Squiggleville   1250
## 49 MelissaRobins Squiggleville   1225
## 50 MelissaRobins Squiggleville   1325
## 51 MelissaRobins Metalocalypse   1125
## 52 MelissaRobins Metalocalypse   1025
## 53 MelissaRobins Metalocalypse    950
## 54 MelissaRobins Metalocalypse    925
## 55 MelissaRobins Squiggleville   1200
## 56 MelissaRobins Metalocalypse   1100
## 57 MelissaRobins Metalocalypse    950
## 58 MelissaRobins Metalocalypse   1300
## 59 MelissaRobins Squiggleville   1400
## 60 MelissaRobins Metalocalypse   1100
df$Instructor<-factor(df$Instructor)
df$Town<-factor(df$Town)
df$Sodium<-as.numeric(df$Sodium)
df
##       Instructor          Town Sodium
## 1   BrendonSmall Squiggleville   1200
## 2   BrendonSmall Squiggleville   1400
## 3   BrendonSmall Squiggleville   1350
## 4   BrendonSmall Metalocalypse    950
## 5   BrendonSmall Squiggleville   1400
## 6   BrendonSmall Squiggleville   1150
## 7   BrendonSmall Squiggleville   1300
## 8   BrendonSmall Metalocalypse   1325
## 9   BrendonSmall Metalocalypse   1425
## 10  BrendonSmall Squiggleville   1500
## 11  BrendonSmall Squiggleville   1250
## 12  BrendonSmall Metalocalypse   1150
## 13  BrendonSmall Metalocalypse    950
## 14  BrendonSmall Squiggleville   1150
## 15  BrendonSmall Metalocalypse   1600
## 16  BrendonSmall Metalocalypse   1300
## 17  BrendonSmall Metalocalypse   1050
## 18  BrendonSmall Metalocalypse   1300
## 19  BrendonSmall Squiggleville   1700
## 20  BrendonSmall Squiggleville   1300
## 21  CoachMcGuirk Squiggleville   1100
## 22  CoachMcGuirk Squiggleville   1200
## 23  CoachMcGuirk Squiggleville   1250
## 24  CoachMcGuirk Metalocalypse   1050
## 25  CoachMcGuirk Metalocalypse   1200
## 26  CoachMcGuirk Metalocalypse   1250
## 27  CoachMcGuirk Squiggleville   1350
## 28  CoachMcGuirk Squiggleville   1350
## 29  CoachMcGuirk Squiggleville   1325
## 30  CoachMcGuirk Squiggleville   1525
## 31  CoachMcGuirk Squiggleville   1225
## 32  CoachMcGuirk Squiggleville   1125
## 33  CoachMcGuirk Metalocalypse   1000
## 34  CoachMcGuirk Metalocalypse   1125
## 35  CoachMcGuirk Squiggleville   1400
## 36  CoachMcGuirk Metalocalypse   1200
## 37  CoachMcGuirk Squiggleville   1150
## 38  CoachMcGuirk Squiggleville   1400
## 39  CoachMcGuirk Squiggleville   1500
## 40  CoachMcGuirk Squiggleville   1200
## 41 MelissaRobins Metalocalypse    900
## 42 MelissaRobins Metalocalypse   1100
## 43 MelissaRobins Metalocalypse   1150
## 44 MelissaRobins Metalocalypse    950
## 45 MelissaRobins Metalocalypse   1100
## 46 MelissaRobins Metalocalypse   1150
## 47 MelissaRobins Squiggleville   1250
## 48 MelissaRobins Squiggleville   1250
## 49 MelissaRobins Squiggleville   1225
## 50 MelissaRobins Squiggleville   1325
## 51 MelissaRobins Metalocalypse   1125
## 52 MelissaRobins Metalocalypse   1025
## 53 MelissaRobins Metalocalypse    950
## 54 MelissaRobins Metalocalypse    925
## 55 MelissaRobins Squiggleville   1200
## 56 MelissaRobins Metalocalypse   1100
## 57 MelissaRobins Metalocalypse    950
## 58 MelissaRobins Metalocalypse   1300
## 59 MelissaRobins Squiggleville   1400
## 60 MelissaRobins Metalocalypse   1100

Modelo 1

modelo<-lm(Sodium~Instructor*Town,data = df)
anova<-aov(modelo)
summary(anova)
##                 Df  Sum Sq Mean Sq F value   Pr(>F)    
## Instructor       2  290146  145073   6.920 0.002110 ** 
## Town             1  329551  329551  15.721 0.000218 ***
## Instructor:Town  2   26269   13135   0.627 0.538263    
## Residuals       54 1131992   20963                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Modelo 2

library(lme4)
## Loading required package: Matrix
modelo2<-lmer(Sodium~(1|Instructor)+(1|Town),data=df)
summary(modelo2)
## Linear mixed model fit by REML ['lmerMod']
## Formula: Sodium ~ (1 | Instructor) + (1 | Town)
##    Data: df
## 
## REML criterion at convergence: 763.3
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.64670 -0.72097  0.03089  0.45329  2.87607 
## 
## Random effects:
##  Groups     Name        Variance Std.Dev.
##  Instructor (Intercept)  2954     54.35  
##  Town       (Intercept) 12500    111.81  
##  Residual               20655    143.72  
## Number of obs: 60, groups:  Instructor, 3; Town, 2
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  1216.61      87.06   13.97

PORCENTAJE DE CONTRIBUCIÓN DE LA VARIANZA

PorcentajeInstructor<-(2954/(2954+12500+20655))*100
PorcentajeTown<-(12500/(2954+12500+20655))*100
PorcentajeInstructor
## [1] 8.180786
PorcentajeTown
## [1] 34.61741

PROBLEMA 2

Se miden la mano izquierda y la derecha de varios individuos, las medidas se emparejan dentro de cada individuo. Es decir, queremos hacer coincidir estadísticamente la mano izquierda del individuo A con la mano derecha del individuo A, ya que suponemos que alguien con una mano izquierda grande tendrá una mano derecha grande. Por tanto, la variable Individuo se incluirá en el modelo como variable aleatoria. Se podría pensar que cada individuo tiene un bloque que incluye una medida para la mano izquierda y una medida para la mano derecha.

df<-read.csv("https://raw.githubusercontent.com/PedroGonzalezBeermann2020/DExperimental2021/main/Problema2.csv")
df
##    IndividuO  Mano Largo
## 1          A  Left  17.5
## 2          B  Left  18.4
## 3          C  Left  16.2
## 4          D  Left  14.5
## 5          E  Left  13.5
## 6          F  Left  18.9
## 7          G  Left  19.5
## 8          H  Left  21.1
## 9          I  Left  17.8
## 10         J  Left  16.8
## 11         K  Left  18.4
## 12         L  Left  17.3
## 13         M  Left  18.9
## 14         N  Left  16.4
## 15         O  Left  17.5
## 16         P  Left  15.0
## 17         A Right  17.6
## 18         B Right  18.5
## 19         C Right  15.9
## 20         D Right  14.9
## 21         E Right  13.7
## 22         F Right  18.9
## 23         G Right  19.5
## 24         H Right  21.5
## 25         I Right  18.5
## 26         J Right  17.1
## 27         K Right  18.9
## 28         L Right  17.5
## 29         M Right  19.5
## 30         N Right  16.5
## 31         O Right  17.4
## 32         P Right  15.6