library(readxl)
dtPFA <- read_excel("C:/Users/PC/Downloads/DATOS INFORME 2 ANIDADOS.xlsx",
sheet = "EjPFA")
head(dtPFA)
## # A tibble: 6 × 3
## ExposicionPFA Superficie CAntimicrobiano
## <chr> <chr> <dbl>
## 1 Indirecto PVC 13.3
## 2 Indirecto PVC 13.0
## 3 Indirecto PVC 13.5
## 4 Indirecto AC 22.9
## 5 Indirecto AC 13.4
## 6 Indirecto AC 17.6
library(lme4)
## Cargando paquete requerido: Matrix
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.2.1 ✔ readr 2.2.0
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ ggplot2 4.0.3 ✔ tibble 3.3.1
## ✔ lubridate 1.9.5 ✔ tidyr 1.3.2
## ✔ purrr 1.2.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ tidyr::expand() masks Matrix::expand()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ✖ tidyr::pack() masks Matrix::pack()
## ✖ tidyr::unpack() masks Matrix::unpack()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(lmerTest)
##
## Adjuntando el paquete: 'lmerTest'
##
## The following object is masked from 'package:lme4':
##
## lmer
##
## The following object is masked from 'package:stats':
##
## step
library(ggplot2)
library(agricolae)
##Indicar variables como factor
dtPFA$ExposicionPFA <- as.factor(dtPFA$ExposicionPFA)
dtPFA$Superficie <- as.factor(dtPFA$Superficie)
head(dtPFA)
## # A tibble: 6 × 3
## ExposicionPFA Superficie CAntimicrobiano
## <fct> <fct> <dbl>
## 1 Indirecto PVC 13.3
## 2 Indirecto PVC 13.0
## 3 Indirecto PVC 13.5
## 4 Indirecto AC 22.9
## 5 Indirecto AC 13.4
## 6 Indirecto AC 17.6
##Grafica BOXPLOT caja y bigote
ggplot(dtPFA, aes(x = Superficie, y = CAntimicrobiano, fill = ExposicionPFA)) +
geom_boxplot(alpha = 0.7) +
facet_wrap(~ ExposicionPFA) +
scale_fill_manual(
name = "ExposicionPFA",
values = c(
"Directo" = "#FFA07A", # rosa pastel
"Indirecto" = "#A7C7E7" # azul pastel
),
labels = c(
"1" = "Directo",
"2" = "Indirecto"
)
) +
labs(
x = "Superficie",
y = "Capacidad antimicrobiana ( % )"
) +
theme_minimal() +
theme(
legend.position = "right"
)
#LMER. Donde: A Factor fijo = operador y un B factor aleatorio=pieza anidado a operador
anovaPFA <- lmer(CAntimicrobiano ~ ExposicionPFA + (1 | ExposicionPFA:Superficie),
data = dtPFA)
summary(anovaPFA)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: CAntimicrobiano ~ ExposicionPFA + (1 | ExposicionPFA:Superficie)
## Data: dtPFA
##
## REML criterion at convergence: 89.8
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -1.79788 -0.26556 -0.03621 0.37370 2.08831
##
## Random effects:
## Groups Name Variance Std.Dev.
## ExposicionPFA:Superficie (Intercept) 32.146 5.670
## Residual 5.988 2.447
## Number of obs: 18, groups: ExposicionPFA:Superficie, 6
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 33.338 3.374 4.000 9.882 0.000588 ***
## ExposicionPFAIndirecto -18.761 4.771 4.000 -3.932 0.017069 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr)
## ExpscnPFAIn -0.707
#AOV PARA FIJO
aovPFA <- aov(CAntimicrobiano ~ ExposicionPFA/Superficie,
data=dtPFA)
summary(aovPFA)
## Df Sum Sq Mean Sq F value Pr(>F)
## ExposicionPFA 1 1583.9 1583.9 264.5 1.54e-09 ***
## ExposicionPFA:Superficie 4 409.7 102.4 17.1 6.74e-05 ***
## Residuals 12 71.9 6.0
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#Calculo % de componentes
total <- 32.146+5.988
total
## [1] 38.134
P_superficie <- 32.146/total*100
P_superficie
## [1] 84.29748
P_Residuos <- 5.988/total*100
P_Residuos
## [1] 15.70252
##SUPUESTOS #NORMALIDAD - SHAPIRO WILK
library (dplyr)
library (ggplot2)
resid <- residuals(anovaPFA)
shapiro.test(resid)
##
## Shapiro-Wilk normality test
##
## data: resid
## W = 0.94578, p-value = 0.3627
qqnorm(resid)
#HOMOGENEIDAD DE VARIANZA - TEST DE LEVENE
library(car)
## Cargando paquete requerido: carData
## Registered S3 method overwritten by 'car':
## method from
## na.action.merMod lme4
##
## Adjuntando el paquete: 'car'
## The following object is masked from 'package:dplyr':
##
## recode
## The following object is masked from 'package:purrr':
##
## some
dtPFA$Grupo <- interaction(dtPFA$ExposicionPFA, dtPFA$Superficie)
leveneTest(CAntimicrobiano ~ Grupo, data = dtPFA)
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 5 1.5708 0.2413
## 12