Shapiro Wilk LM

x1=0.3620
x2=0.5030
x3=0.6170
LM1=c(0.3537, 0.3654, 0.3592,0.3617, 0.3649, 0.3631, 0.3626, 0.3608, 0.3496,0.3554, 0.3612, 0.3721, 0.3578, 0.3556, 0.3602, 0.3619, 0.36541, 0.3614, 0.36612, 0.35356, 0.3487, 0.3668, 0.3686, 0.3597, 0.3444, 0.3689, 0.3633)
length(LM1)
## [1] 27
shapiro.test(LM1)
## 
##  Shapiro-Wilk normality test
## 
## data:  LM1
## W = 0.96447, p-value = 0.4643
qqnorm(LM1)
qqline(LM1)

round(mean(LM1),4)
## [1] 0.3604
outliers=boxplot(LM1, outline = FALSE)

t.test(LM1, mu=x1)
## 
##  One Sample t-test
## 
## data:  LM1
## t = -1.2374, df = 26, p-value = 0.227
## alternative hypothesis: true mean is not equal to 0.362
## 95 percent confidence interval:
##  0.3578693 0.3630262
## sample estimates:
## mean of x 
## 0.3604478
#t.test(x=LM1, conf.level=0.95)$conf.int
LM2=c(0.5253,0.5147,0.4923,0.5253,0.5253,0.5148,0.4919,0.5031, 0.4923, 0.5196, 0.5180, 0.4855, 0.5134, 0.4991, 0.5029,0.4975,0.5087, 0.5118, 0.4877, 0.4922, 0.4830, 0.5035, 0.5067, 0.5055, 0.5253, 0.5148, 0.4918, 0.5030, 0.4923, 0.5198)
length(LM2)
## [1] 30
shapiro.test(LM2)
## 
##  Shapiro-Wilk normality test
## 
## data:  LM2
## W = 0.94243, p-value = 0.1057
qqnorm(LM2)
qqline(LM2)

round(mean(LM2),4)
## [1] 0.5056
outliers=boxplot(LM2, outline = FALSE)

t.test(LM2, mu=x2)
## 
##  One Sample t-test
## 
## data:  LM2
## t = 1.0805, df = 29, p-value = 0.2888
## alternative hypothesis: true mean is not equal to 0.503
## 95 percent confidence interval:
##  0.5007053 0.5104347
## sample estimates:
## mean of x 
##   0.50557
#t.test(x=LM2, conf.level=0.95)$conf.int
LM3=c(0.6180, 0.6164, 0.6175, 0.6174, 0.6194, 0.61765, 0.61765, 0.6198, 0.61598, 0.6177, 0.6186, 0.6167, 0.61946, 0.6157, 0.61944, 0.61945, 0.6168, 0.6154, 0.61875, 0.61693, 0.6176, 0.6175, 0.61549, 0.6165, 0.61789, 0.61732)
length(LM3)
## [1] 26
shapiro.test(LM3)
## 
##  Shapiro-Wilk normality test
## 
## data:  LM3
## W = 0.95224, p-value = 0.2615
qqnorm(LM3)
qqline(LM3)

round(mean(LM3),4)
## [1] 0.6176
outliers=boxplot(LM3,outline = FALSE)
t.test(LM3, mu=x3)
## 
##  One Sample t-test
## 
## data:  LM3
## t = 2.295, df = 25, p-value = 0.0304
## alternative hypothesis: true mean is not equal to 0.617
## 95 percent confidence interval:
##  0.6170592 0.6180954
## sample estimates:
## mean of x 
## 0.6175773
#t.test(x=LM3, conf.level=0.95)$conf.int
boxplot(LM3)

Shapiro Wilk PSO

PSO1=c(0.356412485491213, 0.365951561095138,0.354539278562117,0.469450629183275,0.363081000048275,0.311652618031356,0.316747590369505,0.342811671397088,0.362881461726439,0.351563243402502,0.352473382410973,0.354960830517897,0.358431943933808,0.361155673370972,0.362274157260340,0.362837082821384,0.363075132155066,0.363215304632010,0.361723561002302,0.362996629930564,0.363033432658196,0.360932541003263,0.361895000000000,0.362000000000000,0.363452111102021,0.361230012135447,0.359235100023100,0.361110235543620,0.360231473001245,0.361522014426870,0.361420032045071,0.362100123473000,0.361500065214721,0.360236498663210,0.361265467222037,0.362172103630012,0.361100230563400,0.362001423634458,0.360352421726531,0.361103635424525,0.359000123425472,0.366501232431321,0.364231052130121,0.363014447236540,0.361723203598462,0.361423365001243,0.360001423001410,0.361623013001412,0.355913531353135,0.362895823391509)
length(PSO1)
## [1] 50
shapiro.test(PSO1)
## 
##  Shapiro-Wilk normality test
## 
## data:  PSO1
## W = 0.43513, p-value = 1.334e-12
qqnorm(PSO1)
qqline(PSO1)

round(mean(PSO1),4)
## [1] 0.3608
round(sd(PSO1),4)
## [1] 0.0186
t.test(PSO1, mu=x1)
## 
##  One Sample t-test
## 
## data:  PSO1
## t = -0.43813, df = 49, p-value = 0.6632
## alternative hypothesis: true mean is not equal to 0.362
## 95 percent confidence interval:
##  0.3555704 0.3661278
## sample estimates:
## mean of x 
## 0.3608491
#t.test(x=PSO1, conf.level=0.95)$conf.int
boxplot(PSO1)

index_outliers=which(PSO1 %in% c(boxplot.stats(PSO1)$out))
PSO1.sin=PSO1[-c(index_outliers)]
shapiro.test(PSO1.sin)
## 
##  Shapiro-Wilk normality test
## 
## data:  PSO1.sin
## W = 0.9341, p-value = 0.01786
t.test(PSO1.sin, mu=x1)
## 
##  One Sample t-test
## 
## data:  PSO1.sin
## t = -1.2154, df = 41, p-value = 0.2312
## alternative hypothesis: true mean is not equal to 0.362
## 95 percent confidence interval:
##  0.3610023 0.3622480
## sample estimates:
## mean of x 
## 0.3616252
boxplot(PSO1.sin)

index_outliers=which(PSO1.sin %in% c(boxplot.stats(PSO1.sin)$out))
PSO1.sin2=PSO1.sin[-c(index_outliers)]
shapiro.test(PSO1.sin2)
## 
##  Shapiro-Wilk normality test
## 
## data:  PSO1.sin2
## W = 0.96628, p-value = 0.3015
t.test(PSO1.sin2, mu=x1)
## 
##  One Sample t-test
## 
## data:  PSO1.sin2
## t = -1.5767, df = 37, p-value = 0.1234
## alternative hypothesis: true mean is not equal to 0.362
## 95 percent confidence interval:
##  0.3612470 0.3620939
## sample estimates:
## mean of x 
## 0.3616705
boxplot(PSO1.sin2)

qqnorm(PSO1.sin2)
qqline(PSO1.sin2)

PSO2=c(0.509344286450887, 0.523544229288537, 0.525646598634415, 0.515087698750667, 0.524994106557399, 0.514726650719034, 0.497335023075988, 0.496945816344679, 0.502663585819541, 0.514259220299041, 0.514189288367904, 0.514012109468094, 0.514167359613498, 0.514117635752837, 0.514274373279146, 0.504076185342937, 0.503687154540000, 0.507325641389321, 0.511536844441000, 0.502654179312436, 0.505897634173324, 0.504094636554512, 0.503709408461124, 0.503587481454628, 0.502789134512160, 0.502577142398200, 0.503092544666250, 0.503987512426212, 0.503472156221150, 0.501634578247000, 0.503124622001414, 0.502513400416600, 0.503412000041210, 0.509145257333200, 0.502754261348110, 0.502128756432011, 0.502537469814700, 0.504321780001422, 0.503571114026521, 0.502762621318921, 0.504318222105004, 0.514094949898866, 0.501530214506714, 0.502350159014165, 0.502941732652145, 0.511359321121205, 0.505123634215300, 0.502812006341725, 0.502310015123011, 0.503215468721262)
length(PSO2)
## [1] 50
shapiro.test(PSO2)
## 
##  Shapiro-Wilk normality test
## 
## data:  PSO2
## W = 0.82219, p-value = 2.961e-06
qqnorm(PSO2)
qqline(PSO2)

round(mean(PSO2),4)
## [1] 0.5069
round(sd(PSO2),4)
## [1] 0.0066
t.test(PSO2, mu=x2)
## 
##  One Sample t-test
## 
## data:  PSO2
## t = 4.1848, df = 49, p-value = 0.000118
## alternative hypothesis: true mean is not equal to 0.503
## 95 percent confidence interval:
##  0.5050351 0.5087952
## sample estimates:
## mean of x 
## 0.5069151
boxplot(PSO2)

boxplot(PSO2, outline = FALSE)

index_outliers=which(PSO2 %in% c(boxplot.stats(PSO2)$out))
PSO2.sin=PSO2[-c(index_outliers)]
shapiro.test(PSO2.sin)
## 
##  Shapiro-Wilk normality test
## 
## data:  PSO2.sin
## W = 0.83554, p-value = 9.183e-06
t.test(PSO2.sin, mu=x2)
## 
##  One Sample t-test
## 
## data:  PSO2.sin
## t = 3.9426, df = 47, p-value = 0.0002668
## alternative hypothesis: true mean is not equal to 0.503
## 95 percent confidence interval:
##  0.5045418 0.5077547
## sample estimates:
## mean of x 
## 0.5061483
boxplot(PSO2.sin)

#t.test(x=PSO2, conf.level=0.95)$conf.int
index_outliers=which(PSO2.sin %in% c(boxplot.stats(PSO2.sin)$out))
PSO2.sin2=PSO2.sin[-c(index_outliers)]
shapiro.test(PSO2.sin2)
## 
##  Shapiro-Wilk normality test
## 
## data:  PSO2.sin2
## W = 0.82401, p-value = 5.733e-06
t.test(PSO2.sin2, mu=x1)
## 
##  One Sample t-test
## 
## data:  PSO2.sin2
## t = 198.92, df = 46, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0.362
## 95 percent confidence interval:
##  0.5043233 0.5072330
## sample estimates:
## mean of x 
## 0.5057781
boxplot(PSO2.sin2)

qqnorm(PSO2.sin2)
qqline(PSO2.sin2)

PSO3=c(0.628307882996585,0.618624859628706,0.686358534447869,0.697215744826354, 0.616558789521087, 0.607950977677828, 0.607585323004150, 0.610827630794170, 0.614017698288981, 0.616351620392581, 0.617285189234020, 0.617285596659413, 0.617064470401321, 0.616866569921256, 0.616647619281783, 0.616517505620958, 0.616432087905951, 0.616347458492585, 0.612457832200102, 0.609364521456782, 0.615324721524000, 0.612476328802628, 0.625104120336525, 0.619232340071452, 0.616346896593044, 0.615320149753613, 0.617200013214586, 0.609753165400125, 0.593645317345853, 0.600631478931420, 0.611023003204201, 0.616351516677466, 0.621215415548216, 0.600032541210413, 0.612223054200121, 0.618897841354000, 0.616548351654687, 0.601056423132541, 0.603165419846157, 0.616546519865655, 0.611213415643542, 0.616344616441100, 0.611032224253079, 0.609322145310312, 0.612368924100310, 0.615301201142301, 0.614210336310421, 0.617344231651561, 0.614516986165400, 0.616120216516185)
length(PSO3)
## [1] 50
shapiro.test(PSO3)
## 
##  Shapiro-Wilk normality test
## 
## data:  PSO3
## W = 0.53162, p-value = 2.13e-11
qqnorm(PSO3)
qqline(PSO3)

round(mean(PSO3),4)
## [1] 0.6168
round(sd(PSO3),4)
## [1] 0.0167
t.test(PSO3, mu=x3)
## 
##  One Sample t-test
## 
## data:  PSO3
## t = -0.08537, df = 49, p-value = 0.9323
## alternative hypothesis: true mean is not equal to 0.617
## 95 percent confidence interval:
##  0.6120611 0.6215364
## sample estimates:
## mean of x 
## 0.6167987
boxplot(PSO3)

boxplot(PSO3, outline = FALSE)

index_outliers=which(PSO3 %in% c(boxplot.stats(PSO3)$out))
PSO3.sin=PSO3[-c(index_outliers)]
shapiro.test(PSO3.sin)
## 
##  Shapiro-Wilk normality test
## 
## data:  PSO3.sin
## W = 0.94251, p-value = 0.03193
t.test(PSO3.sin, mu=x3)
## 
##  One Sample t-test
## 
## data:  PSO3.sin
## t = -3.7656, df = 42, p-value = 0.0005106
## alternative hypothesis: true mean is not equal to 0.617
## 95 percent confidence interval:
##  0.6134884 0.6159390
## sample estimates:
## mean of x 
## 0.6147137
boxplot(PSO3.sin)

summary(PSO3.sin)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.6032  0.6123  0.6163  0.6147  0.6168  0.6251
index_outliers=which(PSO3.sin %in% c(boxplot.stats(PSO3.sin)$out))
PSO3.sin2=PSO3.sin[-c(index_outliers)]
shapiro.test(PSO3.sin2)
## 
##  Shapiro-Wilk normality test
## 
## data:  PSO3.sin2
## W = 0.92872, p-value = 0.01309
t.test(PSO3.sin2, mu=x3)
## 
##  One Sample t-test
## 
## data:  PSO3.sin2
## t = -4.4389, df = 40, p-value = 6.936e-05
## alternative hypothesis: true mean is not equal to 0.617
## 95 percent confidence interval:
##  0.6137138 0.6157701
## sample estimates:
## mean of x 
## 0.6147419
boxplot(log(PSO3.sin2))

qqnorm(PSO3.sin2)
qqline(PSO3.sin2)

summary(PSO3.sin2)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.6076  0.6124  0.6163  0.6147  0.6166  0.6212
#t.test(x=PSO3, conf.level=0.95)$conf.int
cor.test(LM1, PSO1.sin2[1:27], method = "pearson")
## 
##  Pearson's product-moment correlation
## 
## data:  LM1 and PSO1.sin2[1:27]
## t = -0.34089, df = 25, p-value = 0.736
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.4367441  0.3202733
## sample estimates:
##         cor 
## -0.06801921
cor.test(LM2, PSO3.sin[1:30], method = "pearson")
## 
##  Pearson's product-moment correlation
## 
## data:  LM2 and PSO3.sin[1:30]
## t = -1.3315, df = 28, p-value = 0.1938
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.5554638  0.1274449
## sample estimates:
##        cor 
## -0.2440287
cor.test(LM3, PSO3.sin2[1:26], method = "pearson")
## 
##  Pearson's product-moment correlation
## 
## data:  LM3 and PSO3.sin2[1:26]
## t = -0.39033, df = 24, p-value = 0.6997
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.4528441  0.3177021
## sample estimates:
##        cor 
## -0.0794239
library(ggplot2)
metodo_A=LM3
metodo_B=PSO3.sin[1:26]
diferencia <- LM3 - PSO3.sin[1:26]
media <- (LM3 - PSO3.sin[1:26]) / 2
porcentaje <- ((diferencia / media) * 100)
datos <- data.frame(metodo_A, metodo_B, diferencia, media, porcentaje)
summary(datos)
##     metodo_A         metodo_B        diferencia            media          
##  Min.   :0.6154   Min.   :0.6076   Min.   :-0.008174   Min.   :-0.004087  
##  1st Qu.:0.6167   1st Qu.:0.6125   1st Qu.:-0.000106   1st Qu.:-0.000053  
##  Median :0.6176   Median :0.6163   Median : 0.001516   Median : 0.000758  
##  Mean   :0.6176   Mean   :0.6150   Mean   : 0.002579   Mean   : 0.001289  
##  3rd Qu.:0.6185   3rd Qu.:0.6170   3rd Qu.: 0.006291   3rd Qu.: 0.003146  
##  Max.   :0.6198   Max.   :0.6251   Max.   : 0.009815   Max.   : 0.004907  
##    porcentaje 
##  Min.   :200  
##  1st Qu.:200  
##  Median :200  
##  Mean   :200  
##  3rd Qu.:200  
##  Max.   :200
BA_plot <- ggplot(data = datos, aes(x = media, y = diferencia)) +
             geom_point(pch = 1, size = 1.5, col = "black") +
             labs(title = "Bland-Altman plot", x = "media método A y B", 
                  y = "método A - método B") +
             ylim(mean(datos$diferencia) - 4 * sd(datos$diferencia), 
                  mean(datos$diferencia) + 4 * sd(diferencia)) +
             # Línea de bias
             geom_hline(yintercept = mean(datos$diferencia), lwd = 1) +
             # Línea en y=0
             geom_hline(yintercept = 0, lty = 3, col = "grey30") +
             # Limits of Agreement
             geom_hline(yintercept = mean(datos$diferencia) + 
                        1.96 * sd(datos$diferencia), 
                        lty = 2, col = "firebrick") +
             geom_hline(yintercept = mean(datos$diferencia) - 
                        1.96 * sd(datos$diferencia), 
                        lty = 2, col = "firebrick") +
             theme(panel.grid.major = element_blank(), 
                   panel.grid.minor = element_blank()) +
             geom_text(label = "Bias", x = 0.005, y = 0, size = 3, 
                       colour = "black") +
             geom_text(label = "+1.96SD", x = 0.005, y = 0.015, size = 3, 
                       colour = "firebrick") +
             geom_text(label = "-1.96SD", x = 0.005, y = -0.017, size = 3, 
                       colour = "firebrick") +
             theme_bw() + theme(plot.title = element_text(hjust = 0.5))
BA_plot

BA_plot + geom_smooth(method = "lm", se = TRUE, fill = "lightgrey", lwd = 0.1, lty = 5)
## `geom_smooth()` using formula 'y ~ x'

sd <- sd(datos$diferencia)
bias <- mean(datos$diferencia)
LoA_superior <- bias + 1.96 * sd
LoA_inferior <- bias - 1.96 * sd
# Porcentaje de error tomando como referencia el método A
error <- (LoA_superior - LoA_inferior)/mean(metodo_A) * 100
error
## [1] 2.705932