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
library(lme4)
## Loading required package: Matrix
modelo<-lmer(Sodium~(1|Instructor)+(1|Town), data=df)
#modelo<-lm(Sodium~Instructor*Town, data = df)
summary(modelo)
## 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
with(df, interaction.plot(x.factor = Instructor, trace.factor = Town, response = Sodium))
with(df, interaction.plot(x.factor = Town, trace.factor = Instructor, response = Sodium))
modelo1<-lm(Sodium~Instructor*Town, data=df)
anova<-aov(modelo1)
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
A= Instructor B= Town AB= Interacción
F°A= CMA/CMAB F°A= 145073/13135 F°A= 11.04477
F°B= CMB/CMAB F°B= 329551/13135 F°B= 25.08953
F°AB= CMAB/CME F°AB= 13135/20963 F°AB= 0.6265802
1-pf(11.04477,2,2)Para Instructor 0.08302359
1-pf(> 1-pf(25.08953,1,2) Para Town 0.03762235
1-pf(0.665802,2,54) Para Interacción 0.5180283
A= (2954/36109*100) A= 8.180786
B= (12500/36109*100) B= 34.61741
AB= (20655/36109*100) AB= 57.20181
Basándonos en los valores P>0.05 para las variables A, B e interacción, podemos que existe diferencia entre ellas, sin embargo los porcentajes de variabilidad nos podrían acercar a que el efecto mayoritario proviene de la interacción entre las variables A y B, lo que indica que el tratamiento junto con la ciudad va a inferir en la respuesta de dicho tratamiento. Con 95% de confianza. EN los graficos de interacción vemos que el efecto de la ciudad es más importante ya que las lines no son paralelas entre sí, lo que indica una interacción entre el tratamiento y la ciudad. En cambio en el gráfico de interacción de tratamientos las lineas son mas cercanas entre sí, por lo que no existe interacción o si existe es mínima. con 95% de confianza.