library(readxl)
library(ggplot2)
library(CGPfunctions)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(lmtest)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
#Definir directorio
setwd("G:/TRABAJO/CONSULTORIAS/TRABAJOS VARIOS/JORGE CHAVARRIA/analisis3")
data1 = read_excel("Bicuspid3.xlsx")
head(data1,5)

ANALISIS ELLIPTICITY

#Relacion entre Maximum Sinus Diameter Indexed vs Ellipticity
g1=ggplot(data=data1,mapping=
            aes(x=MaxSinAnnDcalc,y=Ellipticity,))+geom_point()+theme_bw()+
            geom_smooth(method = "lm") 

g1 +  labs(title = "Ellipticity vs Maximum Sinus Diameter Indexed",
           x = "Maximum Sinus Diameter Indexed",
           y= "Ellipticity") 
## `geom_smooth()` using formula 'y ~ x'

correlation_test1 <- cor.test(data1$MaxSinAnnDcalc, data1$Ellipticity)
print(correlation_test1)
## 
##  Pearson's product-moment correlation
## 
## data:  data1$MaxSinAnnDcalc and data1$Ellipticity
## t = -0.057885, df = 99, p-value = 0.954
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.2010283  0.1898375
## sample estimates:
##          cor 
## -0.005817578

Podemos observar que la correlacion es nula entre estas variables

#Relacion entre Minimun Sinus Diameter Indexed vs Ellipticity
g2=ggplot(data=data1,mapping=
            aes(x=MinSinusAnnDcalc,y=Ellipticity,))+geom_point()+theme_bw()+
            geom_smooth(method = "lm") 

g2 +  labs(title = "Ellipticity vs Minimun Sinus Diameter Indexed",
           x = "Minimun Sinus Diameter Indexed",
           y= "Ellipticity") 
## `geom_smooth()` using formula 'y ~ x'

correlation_test2 <- cor.test(data1$MinSinusAnnDcalc, data1$Ellipticity)
print(correlation_test2)
## 
##  Pearson's product-moment correlation
## 
## data:  data1$MinSinusAnnDcalc and data1$Ellipticity
## t = 0.55201, df = 99, p-value = 0.5822
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1415783  0.2481465
## sample estimates:
##        cor 
## 0.05539371

Tampoco existe correlacion entre estas variables

#Relacion entre Postdilatation vs Ellipticity
boxplot(data1$Ellipticity~data1$Postdilation,
        xlab = 'Postdilation',
        ylab = 'Ellipticity',
        title=('Postdilatation vs Ellipticity'),
          col= 'bisque')

t_test1 <- t.test(data1$Ellipticity ~ as.factor(data1$Postdilation))
print(t_test1)
## 
##  Welch Two Sample t-test
## 
## data:  data1$Ellipticity by as.factor(data1$Postdilation)
## t = 0.96675, df = 27.929, p-value = 0.342
## alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
## 95 percent confidence interval:
##  -0.01214411  0.03384722
## sample estimates:
## mean in group 0 mean in group 1 
##        1.097215        1.086364

No se evidencia una diferencia significativa en la Ellipticity en funcion de la Postdilatation

ggplot(data = data1) + geom_density(aes(x=Ellipticity,fill=factor(Postdilation)),
                                    bins=10, position = "identity",alpha = 0.5)
## Warning: Ignoring unknown parameters: bins

#Relacion entre Predilatation vs Ellipticity
boxplot(data1$Ellipticity~data1$Predilatation,
        xlab = 'Predilatation',
        ylab = 'Ellipticity',
        title=('Predilatation vs Ellipticity'),
          col= 'bisque')

t_test2 <- t.test(data1$Ellipticity ~ as.factor(data1$Predilatation))
print(t_test2)
## 
##  Welch Two Sample t-test
## 
## data:  data1$Ellipticity by as.factor(data1$Predilatation)
## t = -0.27122, df = 55.541, p-value = 0.7872
## alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
## 95 percent confidence interval:
##  -0.02047131  0.01558984
## sample estimates:
## mean in group 0 mean in group 1 
##        1.094030        1.096471

No existe una diferencia significativa de Ellipticity en función de la Predilatation

ggplot(data = data1) + geom_density(aes(x=Ellipticity,fill=factor(Predilatation)),
                                    bins=10, position = "identity",alpha = 0.5)
## Warning: Ignoring unknown parameters: bins

#Relacion entre Raphe Calcification vs Ellipticity
boxplot(data1$Ellipticity~data1$Raphaecalcification,
        xlab = 'Raphae Calcification',
        ylab = 'Ellipticity',
        title=('Raphae Calcification vs Ellipticity'),
          col= 'ivory')

ggplot(data = data1) + geom_density(aes(x=Ellipticity,fill=factor(Raphaecalcification)),
                                    bins=10, position = "identity",alpha = 0.5)
## Warning: Ignoring unknown parameters: bins

t_test3 <- t.test(data1$Ellipticity ~ as.factor(data1$Raphaecalcification))
print(t_test3)
## 
##  Welch Two Sample t-test
## 
## data:  data1$Ellipticity by as.factor(data1$Raphaecalcification)
## t = -2.3619, df = 89.115, p-value = 0.02036
## alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
## 95 percent confidence interval:
##  -0.03294470 -0.00284077
## sample estimates:
## mean in group 0 mean in group 1 
##        1.083514        1.101406

Existe diferencia significativa de Ellipticity en función del Raphaecalcification

#Relacion entre AVAi vs Ellipticity
g4=ggplot(data=data1,mapping=
            aes(x=AVAi,y=Ellipticity,))+geom_point()+theme_bw()+
            geom_smooth(method = "lm") 

g4 +  labs(title = "Ellipticity vs AVAi",
           x = "AVAi",
           y= "Ellipticity") 
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 26 rows containing non-finite values (stat_smooth).
## Warning: Removed 26 rows containing missing values (geom_point).

correlation_test3 <- cor.test(data1$AVAi, data1$Ellipticity)
print(correlation_test3)
## 
##  Pearson's product-moment correlation
## 
## data:  data1$AVAi and data1$Ellipticity
## t = -1.0448, df = 73, p-value = 0.2996
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.3390060  0.1085693
## sample estimates:
##        cor 
## -0.1213836

No existe correlacion significativa

#Relacion entre Mean Gradient (mmHg) vs Ellipticity
g5=ggplot(data=data1,mapping=
            aes(x=MeanGradientmmHg,y=Ellipticity,))+geom_point()+theme_bw()+
            geom_smooth(method = "lm") 

g5 +  labs(title = "Ellipticity vs Mean Gradient (mmHg)",
           x = "Mean Gradient (mmHg)",
           y= "Ellipticity") 
## `geom_smooth()` using formula 'y ~ x'

correlation_test4 <- cor.test(data1$MeanGradientmmHg, data1$Ellipticity)
print(correlation_test4)
## 
##  Pearson's product-moment correlation
## 
## data:  data1$MeanGradientmmHg and data1$Ellipticity
## t = 1.7932, df = 99, p-value = 0.076
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.01872337  0.36031423
## sample estimates:
##       cor 
## 0.1773649

la correlacion entre MeanGradientmmHg y RelativeStentExpansion es positiva y significativa

#Relacion entre ICD4mm vs Ellipticity
g6=ggplot(data=data1,mapping=
            aes(x=ICD4mm,y=Ellipticity,))+geom_point()+theme_bw()+
            geom_smooth(method = "lm") 

g6 +  labs(title = "Ellipticity vs Intercomisural Diameter at 4 mm Indexed",
           x = "Intercomisural Diameter at 4 mm Indexed",
           y= "Ellipticity") 
## `geom_smooth()` using formula 'y ~ x'

correlation_test5 <- cor.test(data1$ICD4mm, data1$Ellipticity)
print(correlation_test5)
## 
##  Pearson's product-moment correlation
## 
## data:  data1$ICD4mm and data1$Ellipticity
## t = 0.11945, df = 99, p-value = 0.9052
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1838663  0.2069580
## sample estimates:
##        cor 
## 0.01200432

No existe correlacion significativa entre ICD4mm y Ellipticity

#Relacion entre CCV vs Ellipticity
g7=ggplot(data=data1,mapping=
            aes(x=CCV,y=Ellipticity,))+geom_point()+theme_bw()+
            geom_smooth(method = "lm") 

g7 +  labs(title = "Ellipticity vs Calcium contrast volume",
           x = "Calcium contrast volume",
           y= "Ellipticity") 
## `geom_smooth()` using formula 'y ~ x'

correlation_test6 <- cor.test(data1$CCV, data1$Ellipticity)
print(correlation_test6)
## 
##  Pearson's product-moment correlation
## 
## data:  data1$CCV and data1$Ellipticity
## t = 1.0437, df = 99, p-value = 0.2992
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.09301167  0.29377352
## sample estimates:
##      cor 
## 0.104324

La correlacion entre CCV y Ellipticity no es significativa.

#Relacion entre CCV vs Ellipticitycalc
boxplot(data1$CCV~data1$Ellipticitycalc,
        xlab = 'Ellipticity',
        ylab = 'Calcium contrast volume',
        title=('Ellipticitycalc vs Calcium contrast volume'),
          col= 'ivory')

REGRESION LINEAL EN FUNCION DE Ellipticity

#Regresion inicial
mod1=lm(Ellipticity ~ MaxSinAnnDcalc + MinSinusAnnDcalc + ICD4mm_calc + 
    CCV + Raphaecalcification + Predilatation + Postdilation, 
        data = data1)
summary(mod1)
## 
## Call:
## lm(formula = Ellipticity ~ MaxSinAnnDcalc + MinSinusAnnDcalc + 
##     ICD4mm_calc + CCV + Raphaecalcification + Predilatation + 
##     Postdilation, data = data1)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.095182 -0.027343 -0.003434  0.022655  0.113678 
## 
## Coefficients:
##                       Estimate Std. Error t value Pr(>|t|)    
## (Intercept)          9.110e-01  7.485e-02  12.170  < 2e-16 ***
## MaxSinAnnDcalc      -4.230e-02  3.934e-02  -1.075  0.28510    
## MinSinusAnnDcalc     1.971e-02  4.711e-02   0.418  0.67665    
## ICD4mm_calc          1.911e-01  6.664e-02   2.868  0.00512 ** 
## CCV                  2.353e-06  6.937e-06   0.339  0.73517    
## Raphaecalcification  1.830e-02  8.581e-03   2.132  0.03564 *  
## Predilatation        2.195e-03  8.522e-03   0.258  0.79734    
## Postdilation        -7.510e-03  9.299e-03  -0.808  0.42137    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.03819 on 93 degrees of freedom
## Multiple R-squared:  0.1398, Adjusted R-squared:  0.07511 
## F-statistic:  2.16 on 7 and 93 DF,  p-value: 0.04484
# Aplicar el procedimiento stepwise
mod1_1 <- step(mod1)
## Start:  AIC=-651.88
## Ellipticity ~ MaxSinAnnDcalc + MinSinusAnnDcalc + ICD4mm_calc + 
##     CCV + Raphaecalcification + Predilatation + Postdilation
## 
##                       Df Sum of Sq     RSS     AIC
## - Predilatation        1 0.0000967 0.13576 -653.81
## - CCV                  1 0.0001679 0.13583 -653.76
## - MinSinusAnnDcalc     1 0.0002553 0.13592 -653.69
## - Postdilation         1 0.0009515 0.13662 -653.18
## - MaxSinAnnDcalc       1 0.0016862 0.13735 -652.63
## <none>                             0.13567 -651.88
## - Raphaecalcification  1 0.0066309 0.14230 -649.06
## - ICD4mm_calc          1 0.0119965 0.14766 -645.32
## 
## Step:  AIC=-653.81
## Ellipticity ~ MaxSinAnnDcalc + MinSinusAnnDcalc + ICD4mm_calc + 
##     CCV + Raphaecalcification + Postdilation
## 
##                       Df Sum of Sq     RSS     AIC
## - MinSinusAnnDcalc     1 0.0002604 0.13602 -655.62
## - CCV                  1 0.0002743 0.13604 -655.61
## - Postdilation         1 0.0009355 0.13670 -655.12
## - MaxSinAnnDcalc       1 0.0017169 0.13748 -654.54
## <none>                             0.13576 -653.81
## - Raphaecalcification  1 0.0066266 0.14239 -651.00
## - ICD4mm_calc          1 0.0119008 0.14766 -647.32
## 
## Step:  AIC=-655.62
## Ellipticity ~ MaxSinAnnDcalc + ICD4mm_calc + CCV + Raphaecalcification + 
##     Postdilation
## 
##                       Df Sum of Sq     RSS     AIC
## - CCV                  1 0.0001579 0.13618 -657.50
## - Postdilation         1 0.0008747 0.13690 -656.97
## - MaxSinAnnDcalc       1 0.0015436 0.13757 -656.48
## <none>                             0.13602 -655.62
## - Raphaecalcification  1 0.0076204 0.14364 -652.11
## - ICD4mm_calc          1 0.0122682 0.14829 -648.89
## 
## Step:  AIC=-657.5
## Ellipticity ~ MaxSinAnnDcalc + ICD4mm_calc + Raphaecalcification + 
##     Postdilation
## 
##                       Df Sum of Sq     RSS     AIC
## - Postdilation         1 0.0008725 0.13705 -658.85
## - MaxSinAnnDcalc       1 0.0014725 0.13765 -658.41
## <none>                             0.13618 -657.50
## - Raphaecalcification  1 0.0092184 0.14540 -652.88
## - ICD4mm_calc          1 0.0123545 0.14854 -650.73
## 
## Step:  AIC=-658.85
## Ellipticity ~ MaxSinAnnDcalc + ICD4mm_calc + Raphaecalcification
## 
##                       Df Sum of Sq     RSS     AIC
## - MaxSinAnnDcalc       1 0.0016660 0.13872 -659.63
## <none>                             0.13705 -658.85
## - Raphaecalcification  1 0.0095735 0.14663 -654.03
## - ICD4mm_calc          1 0.0131616 0.15021 -651.59
## 
## Step:  AIC=-659.63
## Ellipticity ~ ICD4mm_calc + Raphaecalcification
## 
##                       Df Sum of Sq     RSS     AIC
## <none>                             0.13872 -659.63
## - Raphaecalcification  1 0.0093796 0.14810 -655.02
## - ICD4mm_calc          1 0.0114975 0.15022 -653.59
summary(mod1_1)
## 
## Call:
## lm(formula = Ellipticity ~ ICD4mm_calc + Raphaecalcification, 
##     data = data1)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.090788 -0.026923 -0.001664  0.025962  0.107225 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)    
## (Intercept)         0.893332   0.067016  13.330  < 2e-16 ***
## ICD4mm_calc         0.173242   0.060786   2.850  0.00533 ** 
## Raphaecalcification 0.020101   0.007809   2.574  0.01154 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.03762 on 98 degrees of freedom
## Multiple R-squared:  0.1205, Adjusted R-squared:  0.1025 
## F-statistic: 6.713 on 2 and 98 DF,  p-value: 0.001853

REGRESION LOGISTICA EN FUNCION DE Ellipticitycalc(1;0)

#Modelo binario
mod2 <- glm(Ellipticitycalc ~ MaxSinAnnDcalc + MinSinusAnnDcalc + ICD4mm_calc + 
    CCV + Raphaecalcification + Predilatation + Postdilation,
                data = data1, family = "binomial")
summary(mod2)
## 
## Call:
## glm(formula = Ellipticitycalc ~ MaxSinAnnDcalc + MinSinusAnnDcalc + 
##     ICD4mm_calc + CCV + Raphaecalcification + Predilatation + 
##     Postdilation, family = "binomial", data = data1)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.9306  -1.0652  -0.5116   1.0317   2.1528  
## 
## Coefficients:
##                       Estimate Std. Error z value Pr(>|z|)   
## (Intercept)         -8.708e+00  4.687e+00  -1.858  0.06318 . 
## MaxSinAnnDcalc      -2.467e+00  2.226e+00  -1.108  0.26784   
## MinSinusAnnDcalc    -3.048e+00  2.678e+00  -1.138  0.25509   
## ICD4mm_calc          1.410e+01  4.461e+00   3.162  0.00157 **
## CCV                  3.761e-05  4.010e-04   0.094  0.92528   
## Raphaecalcification  8.753e-01  4.992e-01   1.753  0.07954 . 
## Predilatation       -1.146e-01  4.995e-01  -0.229  0.81850   
## Postdilation        -3.207e-01  5.377e-01  -0.596  0.55092   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 139.53  on 100  degrees of freedom
## Residual deviance: 122.17  on  93  degrees of freedom
## AIC: 138.17
## 
## Number of Fisher Scoring iterations: 4
# Aplicar el procedimiento stepwise
mod2_1 <- step(mod2)
## Start:  AIC=138.17
## Ellipticitycalc ~ MaxSinAnnDcalc + MinSinusAnnDcalc + ICD4mm_calc + 
##     CCV + Raphaecalcification + Predilatation + Postdilation
## 
##                       Df Deviance    AIC
## - CCV                  1   122.18 136.18
## - Predilatation        1   122.23 136.23
## - Postdilation         1   122.53 136.53
## - MaxSinAnnDcalc       1   123.42 137.42
## - MinSinusAnnDcalc     1   123.48 137.48
## <none>                     122.17 138.17
## - Raphaecalcification  1   125.37 139.37
## - ICD4mm_calc          1   134.56 148.56
## 
## Step:  AIC=136.18
## Ellipticitycalc ~ MaxSinAnnDcalc + MinSinusAnnDcalc + ICD4mm_calc + 
##     Raphaecalcification + Predilatation + Postdilation
## 
##                       Df Deviance    AIC
## - Predilatation        1   122.23 134.23
## - Postdilation         1   122.54 134.54
## - MaxSinAnnDcalc       1   123.44 135.44
## - MinSinusAnnDcalc     1   123.66 135.66
## <none>                     122.18 136.18
## - Raphaecalcification  1   125.91 137.91
## - ICD4mm_calc          1   134.69 146.69
## 
## Step:  AIC=134.23
## Ellipticitycalc ~ MaxSinAnnDcalc + MinSinusAnnDcalc + ICD4mm_calc + 
##     Raphaecalcification + Postdilation
## 
##                       Df Deviance    AIC
## - Postdilation         1   122.60 132.60
## - MaxSinAnnDcalc       1   123.49 133.49
## - MinSinusAnnDcalc     1   123.69 133.69
## <none>                     122.23 134.23
## - Raphaecalcification  1   125.92 135.92
## - ICD4mm_calc          1   135.01 145.01
## 
## Step:  AIC=132.6
## Ellipticitycalc ~ MaxSinAnnDcalc + MinSinusAnnDcalc + ICD4mm_calc + 
##     Raphaecalcification
## 
##                       Df Deviance    AIC
## - MaxSinAnnDcalc       1   123.92 131.92
## - MinSinusAnnDcalc     1   124.18 132.18
## <none>                     122.60 132.60
## - Raphaecalcification  1   126.44 134.44
## - ICD4mm_calc          1   135.89 143.89
## 
## Step:  AIC=131.92
## Ellipticitycalc ~ MinSinusAnnDcalc + ICD4mm_calc + Raphaecalcification
## 
##                       Df Deviance    AIC
## <none>                     123.92 131.92
## - Raphaecalcification  1   127.95 133.95
## - MinSinusAnnDcalc     1   128.95 134.95
## - ICD4mm_calc          1   135.92 141.92
summary(mod2_1)
## 
## Call:
## glm(formula = Ellipticitycalc ~ MinSinusAnnDcalc + ICD4mm_calc + 
##     Raphaecalcification, family = "binomial", data = data1)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.8615  -1.0068  -0.5883   1.0051   2.2055  
## 
## Coefficients:
##                     Estimate Std. Error z value Pr(>|z|)   
## (Intercept)          -9.2133     4.5182  -2.039  0.04143 * 
## MinSinusAnnDcalc     -4.7285     2.1765  -2.172  0.02982 * 
## ICD4mm_calc          13.0760     4.1537   3.148  0.00164 **
## Raphaecalcification   0.9166     0.4678   1.959  0.05006 . 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 139.53  on 100  degrees of freedom
## Residual deviance: 123.92  on  97  degrees of freedom
## AIC: 131.92
## 
## Number of Fisher Scoring iterations: 4
correlation_test6 <- cor.test(data1$ICD4mm_calc, data1$MinSinusAnnDcalc )
print(correlation_test6)
## 
##  Pearson's product-moment correlation
## 
## data:  data1$ICD4mm_calc and data1$MinSinusAnnDcalc
## t = 2.4376, df = 99, p-value = 0.01657
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.04458755 0.41413309
## sample estimates:
##       cor 
## 0.2379533

En el análisis realizado, se están evaluando dos situaciones diferentes:

Correlación de Pearson: En este caso, se calculó el coeficiente de correlación de Pearson entre las variables “ICD4mm” y “Ellipticity”. El coeficiente de correlación obtenido fue de 0.012, lo cual indica una correlación extremadamente débil entre ambas variables. Además, el valor p asociado a la prueba de hipótesis es de 0.9052, lo cual indica que no hay evidencia suficiente para rechazar la hipótesis nula de que la correlación sea igual a cero. El intervalo de confianza del 95% para la correlación está entre -0.1838663 y 0.2069580.

Regresión lineal: En este caso, se ajustó un modelo de regresión lineal utilizando la variable “Ellipticitycalc” como variable de respuesta y otras variables independientes. En el modelo, la variable “ICD4mm_calc” resultó significativa (p-value = 0.00157), lo cual indica que tiene un efecto estadísticamente significativo en la variable de respuesta. Sin embargo, es importante tener en cuenta que la significancia en un modelo de regresión no implica necesariamente una fuerte correlación entre las variables.

La diferencia entre los resultados puede deberse a que el coeficiente de correlación de Pearson evalúa la relación lineal entre dos variables de forma independiente de otras variables, mientras que la regresión lineal considera el efecto conjunto de todas las variables independientes en la variable de respuesta. En otras palabras, la significancia de “ICD4mm_calc” en el modelo de regresión puede deberse a su relación con las otras variables incluidas en el modelo, y no necesariamente a su correlación directa con “Ellipticitycalc”.

Es importante destacar que el análisis de los resultados debe considerar el contexto y los objetivos del estudio, así como tener en cuenta otras consideraciones estadísticas y de interpretación.