Comparaciones y Regresiones

Santiago Cárdenas

2022-06-08

Paquetes

#install.packages("easypackages")
library(easypackages)


#install.packages(c("boot","ggm","ggplot2","polycor","Hmisc","dplyr",
#"readxl","devtools","tidyverse","lubridate",
#"ggridges","wesanderson","RColorBrewer","knitr",
#"kableExtra","hrbrthemes","statsr","stargazer","psych",
#"corrplot","corrr","GGally","ggcorrplot","PerformanceAnalytics",
#"pander","broom","purrr","kableExtra","egg","vtable","qwraps2","rticles",
#"rmdformats","plotly"))

libraries("boot","ggm","ggplot2","polycor","Hmisc","dplyr",
          "readxl","devtools","tidyverse","lubridate",
          "ggridges","wesanderson","RColorBrewer","knitr",
          "kableExtra","hrbrthemes","statsr","stargazer","psych",
          "corrplot","corrr","GGally","ggcorrplot","PerformanceAnalytics",
          "pander","broom","purrr","kableExtra","egg", "vtable",
          "qwraps2", "plotly")

Cargando datos

Datos_Cornel <- read_excel("Datos_Cornel.xlsx")
#Esta base no tiene al participante (MC4PB-HIK) ni los participantes en Rojo

#Carpetas


dir.create("Correlation_Matrices_html")
dir.create("Summary_Tables")
dir.create("Correlation_Plots")
dir.create("Regression_Tables")
dir.create("Graficas_Definitivas")

Exploración inicial de la base

head(Datos_Cornel) #Primeras 10 filas
## # A tibble: 6 x 7
##   Nom       TotalCornel_Pre TotalCornel_Post GCB_Pre_Moyenne GCB_Post_Moyenne
##   <chr>               <dbl>            <dbl>           <dbl>            <dbl>
## 1 MC4PA-AA             NA                 NA              NA               NA
## 2 MC4PA-BLM            16                 13              NA               NA
## 3 MC4PA-DT             25                 29              NA               NA
## 4 MC4PA-DME             3.5                8              NA               NA
## 5 MC4PA-KP             NA                 NA              NA               NA
## 6 MC4PA-MM             NA                 28              NA               NA
## # ... with 2 more variables: `NL_RCTot_Pre(/25)` <dbl>,
## #   `NL_RCTot_Post(/25)` <dbl>
dim(Datos_Cornel) #Número de filas y número de columnas
## [1] 66  7
str(Datos_Cornel) #Estructura de la bas (Tipos de variables)
## tibble [66 x 7] (S3: tbl_df/tbl/data.frame)
##  $ Nom               : chr [1:66] "MC4PA-AA" "MC4PA-BLM" "MC4PA-DT" "MC4PA-DME" ...
##  $ TotalCornel_Pre   : num [1:66] NA 16 25 3.5 NA NA -1.5 -5.5 10.5 -0.5 ...
##  $ TotalCornel_Post  : num [1:66] NA 13 29 8 NA 28 NA -8.5 23.5 NA ...
##  $ GCB_Pre_Moyenne   : num [1:66] NA NA NA NA NA NA NA NA NA NA ...
##  $ GCB_Post_Moyenne  : num [1:66] NA NA NA NA NA NA NA NA NA NA ...
##  $ NL_RCTot_Pre(/25) : num [1:66] NA 10 NA 10 NA 13 NA 16 11 10 ...
##  $ NL_RCTot_Post(/25): num [1:66] NA 11 10 13 NA 12 11 14 12 12 ...

Nombres

names(Datos_Cornel)
## [1] "Nom"                "TotalCornel_Pre"    "TotalCornel_Post"  
## [4] "GCB_Pre_Moyenne"    "GCB_Post_Moyenne"   "NL_RCTot_Pre(/25)" 
## [7] "NL_RCTot_Post(/25)"
Datos_Cornel<- Datos_Cornel %>% 
  rename(NL_RCTot_Pre_25=`NL_RCTot_Pre(/25)`,
         NL_RCTot_Post_25=`NL_RCTot_Post(/25)`)

Missig Values (NAS)

#Total NAS:

sum(is.na(Datos_Cornel))
## [1] 127
#NAS por columna

map(Datos_Cornel, ~sum(is.na(.)))  
## $Nom
## [1] 0
## 
## $TotalCornel_Pre
## [1] 13
## 
## $TotalCornel_Post
## [1] 11
## 
## $GCB_Pre_Moyenne
## [1] 45
## 
## $GCB_Post_Moyenne
## [1] 30
## 
## $NL_RCTot_Pre_25
## [1] 14
## 
## $NL_RCTot_Post_25
## [1] 14
#NA graph

#Export

Plot0<- Datos_Cornel  %>%
  summarise_all(list(~is.na(.)))%>%
  pivot_longer(everything(),
               names_to = "Variables", values_to="Missing") %>%
  count(Variables, Missing) %>%
  ggplot(aes(y=Variables,x=n,fill=Missing))+
  geom_col()+
  scale_fill_brewer(palette = "Accent")+
  labs(title="NAS en la base por variables")+
  theme_classic()+
  theme(axis.text.x = element_text( size = 13),#Tamaños de letra
        axis.title.y = element_text( size = 15),
        axis.title.x = element_text( size = 15),
        plot.title = element_text(size = 20,face = "bold"),
        plot.subtitle = element_text(size = 15),
        legend.title = element_text(size = 15),
        legend.text = element_text(size = 13))


ggsave(plot = Plot0, filename = "./Graficas_Definitivas/Barplot_NAS.png", 
       width = 11, 
       height = 7,
       type = "cairo",
       dpi = "retina")

ggplotly(Plot0)

Summary Statistics

#Pongo también Summary porque incluye el conteo de NAS
summary(Datos_Cornel)
##      Nom            TotalCornel_Pre TotalCornel_Post GCB_Pre_Moyenne
##  Length:66          Min.   :-9.50   Min.   :-8.50    Min.   :1.540  
##  Class :character   1st Qu.: 3.00   1st Qu.: 3.00    1st Qu.:2.460  
##  Mode  :character   Median :10.50   Median :11.50    Median :3.080  
##                     Mean   :11.28   Mean   :11.20    Mean   :2.905  
##                     3rd Qu.:19.50   3rd Qu.:17.25    3rd Qu.:3.385  
##                     Max.   :33.50   Max.   :30.50    Max.   :3.770  
##                     NA's   :13      NA's   :11       NA's   :45     
##  GCB_Post_Moyenne NL_RCTot_Pre_25 NL_RCTot_Post_25
##  Min.   :1.000    Min.   : 1      Min.   : 3.00   
##  1st Qu.:2.846    1st Qu.: 7      1st Qu.: 7.00   
##  Median :3.154    Median : 9      Median :10.00   
##  Mean   :3.047    Mean   : 9      Mean   :10.02   
##  3rd Qu.:3.462    3rd Qu.:11      3rd Qu.:12.00   
##  Max.   :4.000    Max.   :19      Max.   :18.00   
##  NA's   :30       NA's   :14      NA's   :14
stargazer(as.data.frame(Datos_Cornel),
          type = "text",
          median = TRUE,
          title = "Summary Statistics",
          out="./Summary_Tables/Summary_Statistics.html")
## 
## Summary Statistics
## ==========================================================================
## Statistic        N   Mean  St. Dev.  Min   Pctl(25) Median Pctl(75)  Max  
## --------------------------------------------------------------------------
## TotalCornel_Pre  53 11.283  10.486  -9.500  3.000   10.500  19.500  33.500
## TotalCornel_Post 55 11.200  9.694   -8.500  3.000   11.500  17.250  30.500
## GCB_Pre_Moyenne  21 2.905   0.599   1.540   2.460   3.080   3.385   3.770 
## GCB_Post_Moyenne 36 3.047   0.633   1.000   2.846   3.154   3.462   4.000 
## NL_RCTot_Pre_25  52 9.000   3.367   1.000   7.000   9.000   11.000  19.000
## NL_RCTot_Post_25 52 10.019  3.723   3.000   7.000   10.000  12.000  18.000
## --------------------------------------------------------------------------
#txt

stargazer(as.data.frame(Datos_Cornel),
          median = TRUE,
          title = "Summary Statistics",
          out="./Summary_Tables/Summary_Statistics.txt")

Comparaciones

Cornel pre vs post

## Cornel Pre y post Con y  Sin NAS

#Acá creo dos bases distintas. Una solo con los valores completos
#Y otra que incluye NAs.

Cornel_Pre_Post_ConNAS<- Datos_Cornel %>% 
  select(TotalCornel_Pre,TotalCornel_Post)

Cornel_Pre_Post_SinNAS<- Datos_Cornel %>% 
  select(TotalCornel_Pre,TotalCornel_Post) %>% 
  na.omit()
 

#Pre

Datos_Cornel_Pre <- Cornel_Pre_Post_SinNAS %>% 
    select(TotalCornel_Pre) %>%
  mutate(Time=as.factor("Pre"))


Datos_Cornel_Pre <- Datos_Cornel_Pre %>% 
  rename(Score_Cornel=TotalCornel_Pre) 

  

#Post
Datos_Cornel_Post <- Cornel_Pre_Post_SinNAS %>% 
  select(TotalCornel_Post) %>% 
  mutate(Time=as.factor("Post"))

Datos_Cornel_Post <- Datos_Cornel_Post %>% 
  rename(Score_Cornel=TotalCornel_Post) 


#Pre & Post

Datos_Cornel_Pre_Post_SinNAS<-rbind(Datos_Cornel_Pre,Datos_Cornel_Post)

#Boxplot COrnel Pre vs Post

    #Eport

      Plot1<- Datos_Cornel_Pre_Post_SinNAS %>% 
        ggplot(aes(y=Score_Cornel,x=Time, fill= Time))+
        geom_boxplot(alpha = 0.6)+
        geom_jitter(alpha = 0.6)+
        scale_fill_manual(values = c("#F652A0", "#36EEE0"))+
        labs(title="Cornel Scores",
             subtitle = "Pre vs Post",
             y="Score",
             x="Test")+
        stat_summary(fun.y=mean, geom="point", 
                     shape=20, size=5, color="white", 
                     fill="red") +
        theme_classic()+
        theme(axis.text.x = element_text( size = 13),#Tamaños de letra
              axis.title.y = element_text( size = 15),
              axis.title.x = element_text( size = 15),
              plot.title = element_text(size = 20,face = "bold"),
              plot.subtitle = element_text(size = 15),
              legend.title = element_text(size = 15),
              legend.text = element_text(size = 13))
      
      
ggsave(plot = Plot1, filename = "./Graficas_Definitivas/Boxplot_Cornel_Pre_Vs_Post.png", 
             width = 11, 
             height = 7,
             type = "cairo",
             dpi = "retina")


ggplotly(Plot1)

Summary Table Cornel (Match Values)

stargazer(as.data.frame(Cornel_Pre_Post_SinNAS),
          type = "text",
          median = TRUE,
          title = "Summary Statistics Cornel",
          out="./Summary_Tables/Summary_Statistics_Cornel.html")
## 
## Summary Statistics Cornel
## ====================================================================
## Statistic        N   Mean  St. Dev. Min Pctl(25) Median Pctl(75) Max
## --------------------------------------------------------------------
## TotalCornel_Pre  46 11.054  9.702   -10   3.5      11      19    34 
## TotalCornel_Post 46 10.239  9.550   -8    2.1     10.5     17    30 
## --------------------------------------------------------------------
#Txt
 stargazer(as.data.frame(Cornel_Pre_Post_SinNAS),
          median = TRUE,
          title = "Summary Statistics Cornel",
          out="./Summary_Tables/Summary_Statistics_Cornel.txt")

Moyenne Pre vs Post

## Moyenne Pre y post Con y  Sin NAS

#Acá creo dos bases distintas. Una solo con los valores completos
#Y otra que incluye NAs.

Moyenne_Pre_Post_ConNAS<- Datos_Cornel %>% 
  select(GCB_Pre_Moyenne, GCB_Post_Moyenne)

Moyenne_Pre_Post_SinNAS<- Datos_Cornel %>% 
  select(GCB_Pre_Moyenne, GCB_Post_Moyenne) %>% 
  na.omit()


#Pre

Datos_Moyenne_Pre <- Moyenne_Pre_Post_SinNAS %>% 
  select(GCB_Pre_Moyenne) %>%
  mutate(Time=as.factor("Pre"))

Datos_Moyenne_Pre <- Datos_Moyenne_Pre %>% 
  rename(Score_Moyenne=GCB_Pre_Moyenne) 


#Post

Datos_Moyenne_Post <- Moyenne_Pre_Post_SinNAS %>% 
  select(GCB_Post_Moyenne) %>%
  mutate(Time=as.factor("Post"))

Datos_Moyenne_Post <- Datos_Moyenne_Post %>% 
  rename(Score_Moyenne=GCB_Post_Moyenne) 



#Rbind Pre & Post Moyenne

Datos_Moyenne_Pre_Post_SinNAS<-rbind(Datos_Moyenne_Pre,
                                    Datos_Moyenne_Post)



#Boxplot

      #Export
        
    Plot2 <- Datos_Moyenne_Pre_Post_SinNAS %>% 
      ggplot(aes(y=Score_Moyenne,x=Time, fill= Time))+
      geom_boxplot(alpha = 0.6)+
      geom_jitter(alpha = 0.6)+
      scale_fill_manual(values = c("#F652A0", "#36EEE0"))+
      labs(title="Generic Conspiracy Belief Scores",
           subtitle = "Pre vs Post",
           y="Score",
           x="Test")+
      stat_summary(fun.y=mean, geom="point", 
                   shape=20, size=5, color="white", 
                   fill="red") +
      theme_classic()+
      theme(axis.text.x = element_text( size = 13),#Tamaños de letra
            axis.title.y = element_text( size = 15),
            axis.title.x = element_text( size = 15),
            plot.title = element_text(size = 20,face = "bold"),
            plot.subtitle = element_text(size = 15),
            legend.title = element_text(size = 15),
            legend.text = element_text(size = 13))

    ggsave(plot = Plot2, filename = "./Graficas_Definitivas/Boxplot_Moyenne_Pre_Post.png", 
       width = 11, 
       height = 7,
       type = "cairo",
       dpi = "retina")

ggplotly(Plot2)    

Summary Table Moyenne (Match values)

stargazer(as.data.frame(Moyenne_Pre_Post_SinNAS),
              type = "text",
              median = TRUE,
              title = "Summary Statistics Moyenne",
              out="./Summary_Tables/Summary_Statistics_Moyenne.html")
## 
## Summary Statistics Moyenne
## =======================================================================
## Statistic        N  Mean  St. Dev.  Min  Pctl(25) Median Pctl(75)  Max 
## -----------------------------------------------------------------------
## GCB_Pre_Moyenne  19 2.867  0.617   1.540  2.460   3.000   3.421   3.770
## GCB_Post_Moyenne 19 2.895  0.764   1.000  2.615   3.154   3.346   4.000
## -----------------------------------------------------------------------
#txt
stargazer(as.data.frame(Moyenne_Pre_Post_SinNAS),
          median = TRUE,
          title = "Summary Statistics Moyenne",
          out="./Summary_Tables/Summary_Statistics_Moyenne.txt")

New Leash pre vs post

##New Leash Pre y post Con y Sin NAS

#Acá creo dos bases distintas. Una solo con los valores completos
#Y otra que incluye NAs.
    
NL_Pre_Post_ConNAS<- Datos_Cornel %>% 
  select(NL_RCTot_Pre_25,NL_RCTot_Post_25)


NL_Pre_Post_SinNAS<- Datos_Cornel %>% 
  select(NL_RCTot_Pre_25,NL_RCTot_Post_25) %>% 
  na.omit()


#Pre

Datos_NL_Pre <- NL_Pre_Post_SinNAS %>% 
  select(NL_RCTot_Pre_25) %>%
  mutate(Time=as.factor("Pre"))

Datos_NL_Pre <- Datos_NL_Pre %>% 
  rename(Score_NL=NL_RCTot_Pre_25) 


#Post

Datos_NL_Post <- NL_Pre_Post_SinNAS %>% 
  select(NL_RCTot_Post_25) %>%
  mutate(Time=as.factor("Post"))

Datos_NL_Post <- Datos_NL_Post %>% 
  rename(Score_NL=NL_RCTot_Post_25) 


#Rbind Pre & Post NL

Datos_NL_Pre_Post_SinNAS<-rbind(Datos_NL_Pre,
                                Datos_NL_Post)



#Boxplot

      #Export
      
      Plot3<-Datos_NL_Pre_Post_SinNAS %>% 
        ggplot(aes(y=Score_NL,x=Time, fill= Time))+
        geom_boxplot(alpha = 0.6)+
        geom_jitter(alpha = 0.6)+
        scale_fill_manual(values = c("#F652A0", "#36EEE0"))+
        labs(title="New Leash Scores",
             subtitle = "Pre vs Post",
             y="Score",
             x="Test")+
        stat_summary(fun.y=mean, geom="point", 
                     shape=20, size=5, color="white", 
                     fill="red") +
        theme_classic()+
        theme(axis.text.x = element_text( size = 13),#Tamaños de letra
              axis.title.y = element_text( size = 15),
              axis.title.x = element_text( size = 15),
              plot.title = element_text(size = 20,face = "bold"),
              plot.subtitle = element_text(size = 15),
              legend.title = element_text(size = 15),
              legend.text = element_text(size = 13)) 
          
      ggsave(plot = Plot3, filename = "./Graficas_Definitivas/Boxplot_New_Leash_Pre_Post.png", 
             width = 11, 
             height = 7,
             type = "cairo",
             dpi = "retina")

ggplotly(Plot3)      

Summary Table New Leash (Match values)

stargazer(as.data.frame(NL_Pre_Post_SinNAS),
                type = "text",
                median = TRUE,
                title = "Summary Statistics New Leash",
                out="./Summary_Tables/Summary_Statistics_New_Leash.html")
## 
## Summary Statistics New Leash
## ====================================================================
## Statistic        N   Mean  St. Dev. Min Pctl(25) Median Pctl(75) Max
## --------------------------------------------------------------------
## NL_RCTot_Pre_25  43 9.372   3.302    1     7       9       11    19 
## NL_RCTot_Post_25 43 10.209  3.833    3    7.5      10     12.5   18 
## --------------------------------------------------------------------
#txt
 stargazer(as.data.frame(NL_Pre_Post_SinNAS),
            median = TRUE,
            title = "Summary Statistics New Leash",
            out="./Summary_Tables/Summary_Statistics_New_Leash.txt")

Corelations

Corplot

Corelations <- Datos_Cornel %>% 
  select(GCB_Pre_Moyenne,TotalCornel_Pre,NL_RCTot_Pre_25)

ggcorrplot(cor(Corelations,use = "pairwise.complete.obs"),
           hc.order=TRUE, type='lower',lab = TRUE,
           title = "Corelations",
           ggtheme = ggplot2::theme_minimal(),
           colors = c("#F652A0","white","#36EEE0"))

    #Export
  
    ggcorrplot<- ggcorrplot(cor(Corelations,use = "pairwise.complete.obs"),
                                                      hc.order=TRUE, type='lower',lab = TRUE,
                                                      title = "Corelations",
                                                      ggtheme = ggplot2::theme_minimal(),
                                                      colors = c("#F652A0","white","#36EEE0"))

    ggsave(plot = ggcorrplot, filename = "./Correlation_Plots/Corplot.png", 
       width = 9, 
       height = 7,
       type = "cairo",
       dpi = "retina")

Corelation Matrix (Stargazer)

Correlation_Matrix <-Datos_Cornel %>% 
      select(2:7) %>% 
      cor(use = "pairwise.complete.obs")
    
    
    stargazer(Correlation_Matrix,
              title="Correlation Matrix",
              type = "text",
              out = "./Correlation_Matrices_html/Correlation_Matrix.html")
## 
## Correlation Matrix
## ===================================================================================================================
##                  TotalCornel_Pre TotalCornel_Post GCB_Pre_Moyenne GCB_Post_Moyenne NL_RCTot_Pre_25 NL_RCTot_Post_25
## -------------------------------------------------------------------------------------------------------------------
## TotalCornel_Pre         1             0.395           -0.049           0.172           -0.072           0.035      
## TotalCornel_Post      0.395             1              0.340           0.210            0.117           0.119      
## GCB_Pre_Moyenne      -0.049           0.340              1             0.324            0.593           0.074      
## GCB_Post_Moyenne      0.172           0.210            0.324             1              0.442           -0.084     
## NL_RCTot_Pre_25      -0.072           0.117            0.593           0.442              1             0.093      
## NL_RCTot_Post_25      0.035           0.119            0.074           -0.084           0.093             1        
## -------------------------------------------------------------------------------------------------------------------
    stargazer(Correlation_Matrix,
              title="Correlation Matrix",
              out = "./Correlation_Matrices_html/Correlation_Matrix.html")

Scatterplots & Regresion Table

GCB_Pre_Moyenne vs TotalCornel_Pre

##GCB_Pre_Moyenne vs TotalCornel_Pre

    #Export

    Scatter_1<- Corelations%>%
    select(GCB_Pre_Moyenne,TotalCornel_Pre) %>% 
    na.omit() %>% 
    ggplot(aes(y=GCB_Pre_Moyenne,x= TotalCornel_Pre))+
    geom_point(alpha = 0.5)+
    geom_smooth(method=lm, color="darkred", fill="#36EEE0")+
    labs(title="GCB_Pre_Moyenne vs Cornel Pre")+
    theme_classic()+
    theme(axis.text.x = element_text( size = 13),
          axis.title.y = element_text( size = 15),
          axis.title.x = element_text( size = 15),
          plot.title = element_text(size = 20,face = "bold"),
          plot.subtitle = element_text(size = 15),
          legend.title = element_text(size = 15),
          legend.text = element_text(size = 13))

     ggsave(plot =Scatter_1, 
       filename = "./Graficas_Definitivas/Scatter_GCB_Pre_Moyenne_vs_Cornel_Pre.png", 
       width = 9, height = 7,
       type= "cairo",
       dpi = "retina")

     
ggplotly(Scatter_1)     
    #Regression table:

    #Cuando hago las tablas con Stargazer pongo "Text" en type
    #Para que la tabla me aparezca en el programa, pero dejo
    #el formato de out en ".html"

    m1_GCB_VS_TotalCornel_Pre<-lm(GCB_Pre_Moyenne ~ TotalCornel_Pre,
                      data = Datos_Cornel)
    
    summary(m1_GCB_VS_TotalCornel_Pre)
## 
## Call:
## lm(formula = GCB_Pre_Moyenne ~ TotalCornel_Pre, data = Datos_Cornel)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.3348 -0.4207  0.1595  0.5126  0.8982 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      2.938231   0.229534   12.80 1.78e-09 ***
## TotalCornel_Pre -0.002951   0.015569   -0.19    0.852    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.6194 on 15 degrees of freedom
##   (49 observations deleted due to missingness)
## Multiple R-squared:  0.002389,   Adjusted R-squared:  -0.06412 
## F-statistic: 0.03592 on 1 and 15 DF,  p-value: 0.8522
    #Export

    stargazer(m1_GCB_VS_TotalCornel_Pre,
          ci = TRUE,
          type = "text",
          title="GCB Pre Moyenne ~ Total Cornel Pre",
          align=TRUE,
          style = "all",
          out = "Regression_Tables/m1_GCB_VS_TotalCornel_Pre.html")
## 
## GCB Pre Moyenne ~ Total Cornel Pre
## ==================================================
##                          Dependent variable:      
##                     ------------------------------
##                            GCB_Pre_Moyenne        
## --------------------------------------------------
## TotalCornel_Pre                 -0.003            
##                            (-0.033, 0.028)        
##                               t = -0.190          
##                               p = 0.853           
## Constant                       2.938***           
##                             (2.488, 3.388)        
##                               t = 12.801          
##                               p = 0.000           
## --------------------------------------------------
## Observations                      17              
## R2                              0.002             
## Adjusted R2                     -0.064            
## Residual Std. Error        0.619 (df = 15)        
## F Statistic         0.036 (df = 1; 15) (p = 0.853)
## ==================================================
## Note:                  *p<0.1; **p<0.05; ***p<0.01

Cornel Post VS NL_RCTot_Pre_25

#Cornel Post VS NL_RCTot_Pre_25


  #Export
  
  Scatter_2 <-  Corelations%>%
    select(GCB_Pre_Moyenne,NL_RCTot_Pre_25) %>% 
    na.omit() %>% 
    ggplot(aes(y=GCB_Pre_Moyenne,x= NL_RCTot_Pre_25))+
    geom_point(alpha = 0.5)+
    geom_smooth(method=lm, color="darkred", fill="#36EEE0")+
    labs(title="GCB_Pre_Moyenne vs NL_RCTot_Pre_25")+
    theme_classic()+
    theme(axis.text.x = element_text( size = 13),
          axis.title.y = element_text( size = 15),
          axis.title.x = element_text( size = 15),
          plot.title = element_text(size = 20,face = "bold"),
          plot.subtitle = element_text(size = 15),
          legend.title = element_text(size = 15),
          legend.text = element_text(size = 13))
  
  
  ggsave(plot =Scatter_2, 
         filename = "./Graficas_Definitivas/Scatter_GCB_Pre_Moyenne vs NL_RCTot_Pre_25.png", 
         width = 9, height = 7,
         type= "cairo",
         dpi = "retina")

  
  ggplotly(Scatter_2)  
    #Regression table:

    m1_GCB_VS_NL_RCTot_Pre<-lm( GCB_Pre_Moyenne ~ NL_RCTot_Pre_25,
                               data = Datos_Cornel)

    summary(m1_GCB_VS_NL_RCTot_Pre)
## 
## Call:
## lm(formula = GCB_Pre_Moyenne ~ NL_RCTot_Pre_25, data = Datos_Cornel)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.8533 -0.2919  0.1182  0.3146  0.9221 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)   
## (Intercept)      1.63553    0.45779   3.573  0.00254 **
## NL_RCTot_Pre_25  0.15155    0.05138   2.950  0.00942 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4989 on 16 degrees of freedom
##   (48 observations deleted due to missingness)
## Multiple R-squared:  0.3522, Adjusted R-squared:  0.3117 
## F-statistic:   8.7 on 1 and 16 DF,  p-value: 0.009419
    #Export

    stargazer(m1_GCB_VS_NL_RCTot_Pre,
          ci = TRUE,
          type = "text",
          title="GCB Pre Moyenne ~ NL RCTot Pre 25",
          align=TRUE,
          style = "all",
          out = "Regression_Tables/m1_GCB_VS_NL_RCTot_Pre.html")
## 
## GCB Pre Moyenne ~ NL RCTot Pre 25
## =====================================================
##                            Dependent variable:       
##                     ---------------------------------
##                              GCB_Pre_Moyenne         
## -----------------------------------------------------
## NL_RCTot_Pre_25                 0.152***             
##                              (0.051, 0.252)          
##                                 t = 2.950            
##                                 p = 0.010            
## Constant                        1.636***             
##                              (0.738, 2.533)          
##                                 t = 3.573            
##                                 p = 0.003            
## -----------------------------------------------------
## Observations                       18                
## R2                                0.352              
## Adjusted R2                       0.312              
## Residual Std. Error          0.499 (df = 16)         
## F Statistic         8.700*** (df = 1; 16) (p = 0.010)
## =====================================================
## Note:                     *p<0.1; **p<0.05; ***p<0.01

Cornel Pre VS NL_RCTot_Pre_25

    #Export
    Scatter_3 <- Corelations%>%
      select(TotalCornel_Pre,NL_RCTot_Pre_25) %>% 
      na.omit() %>% 
      ggplot(aes(y=NL_RCTot_Pre_25,x= TotalCornel_Pre))+
      geom_point(alpha = 0.5)+
      geom_smooth(method=lm, color="darkred", fill="#36EEE0")+
      labs(title="NL_RCTot_Pre_25 vs TotalCornel_Pre")+
      theme_classic()+
      theme(axis.text.x = element_text( size = 13),
            axis.title.y = element_text( size = 15),
            axis.title.x = element_text( size = 15),
            plot.title = element_text(size = 20,face = "bold"),
            plot.subtitle = element_text(size = 15),
            legend.title = element_text(size = 15),
            legend.text = element_text(size = 13))

    
    ggsave(plot =Scatter_3, 
           filename = "./Graficas_Definitivas/Scatter_NL_RCTot_Pre_25_vs_TotalCornel_Pre.png", 
           width = 9, height = 7,
           type= "cairo",
           dpi = "retina")


  ggplotly(Scatter_3)  
  #Regression table:


m1_NL_RCTot_Pre_25_VS_TotalCornel_Pre <-lm(NL_RCTot_Pre_25 ~ TotalCornel_Pre,
                            data = Datos_Cornel)

summary(m1_NL_RCTot_Pre_25_VS_TotalCornel_Pre)
## 
## Call:
## lm(formula = NL_RCTot_Pre_25 ~ TotalCornel_Pre, data = Datos_Cornel)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -7.7348 -2.2142  0.1043  2.1580 10.1818 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      9.09232    0.72176  12.598   <2e-16 ***
## TotalCornel_Pre -0.02384    0.04886  -0.488    0.628    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.388 on 46 degrees of freedom
##   (18 observations deleted due to missingness)
## Multiple R-squared:  0.005147,   Adjusted R-squared:  -0.01648 
## F-statistic: 0.238 on 1 and 46 DF,  p-value: 0.628
#Export

stargazer(m1_NL_RCTot_Pre_25_VS_TotalCornel_Pre,
          ci = TRUE,
          type = "text",
          title="NL RCTot Pre 25 ~ TotalCornel Pre",
          align=TRUE,
          style = "all",
          out = "Regression_Tables/m1_NL_RCTot_Pre_25_VS_TotalCornel_Pre.html")
## 
## NL RCTot Pre 25 ~ TotalCornel Pre
## ==================================================
##                          Dependent variable:      
##                     ------------------------------
##                            NL_RCTot_Pre_25        
## --------------------------------------------------
## TotalCornel_Pre                 -0.024            
##                            (-0.120, 0.072)        
##                               t = -0.488          
##                               p = 0.628           
## Constant                       9.092***           
##                            (7.678, 10.507)        
##                               t = 12.598          
##                               p = 0.000           
## --------------------------------------------------
## Observations                      48              
## R2                              0.005             
## Adjusted R2                     -0.016            
## Residual Std. Error        3.388 (df = 46)        
## F Statistic         0.238 (df = 1; 46) (p = 0.628)
## ==================================================
## Note:                  *p<0.1; **p<0.05; ***p<0.01