This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.

library(lmerTest)
map <- read.table("/mnt/ultrastarQuatre/Microbiome/Skin/skin_pool/skin1234567/No_Ear_Face/Alpha_Diversity_11766_Depth/final_map.txt", sep = '\t', header=TRUE)
choa1_file <- read.table("/mnt/ultrastarQuatre/Microbiome/Skin/skin_pool/skin1234567/No_Ear_Face/Alpha_Diversity_11766_Depth/chao1.txt", sep = '\t', header =TRUE)
simpson_file <- read.table("/mnt/ultrastarQuatre/Microbiome/Skin/skin_pool/skin1234567/No_Ear_Face/Alpha_Diversity_11766_Depth/simpson.txt", sep = '\t', header =TRUE)

merge the two tables

mdata <- merge(map,choa1_file,by="SampleID")
mdata <- merge(mdata,simpson_file, by="SampleID")
mdata <- mdata[,c(1,5,9,10,13,14)]
mdata <- merge(mdata, beta_file, by="SampleID")

LME with Healthy as reference

mdata$Treatment <- factor(mdata$Treatment,levels=c("Healthy","PSO_L","PSO_N"))
### Chao1 stats (reference=Healthy)
chao1.model.healthy = lmer(Chao1 ~ Treatment + (1|Patient) , data=mdata)
summary(chao1.model.healthy)
Linear mixed model fit by REML 
t-tests use  Satterthwaite approximations to degrees of freedom ['lmerMod']
Formula: Chao1 ~ Treatment + (1 | Patient)
   Data: mdata

REML criterion at convergence: 6441.2

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-2.3497 -0.5633 -0.0451  0.4410  4.3364 

Random effects:
 Groups   Name        Variance Std.Dev.
 Patient  (Intercept) 102521   320.2   
 Residual             272936   522.4   
Number of obs: 417, groups:  Patient, 54

Fixed effects:
               Estimate Std. Error     df t value Pr(>|t|)    
(Intercept)      888.58      76.24  63.58  11.654   <2e-16 ***
TreatmentPSO_L   168.07     109.55  72.24   1.534    0.129    
TreatmentPSO_N   124.73     105.90  63.64   1.178    0.243    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
            (Intr) TPSO_L
TrtmntPSO_L -0.696       
TrtmntPSO_N -0.720  0.817
### Simpson stats (reference= Healthy)
simpson.model.healthy = lmer(Simpson ~Treatment +(1|Patient), data=mdata)
summary(simpson.model.healthy)
Linear mixed model fit by REML 
t-tests use  Satterthwaite approximations to degrees of freedom ['lmerMod']
Formula: Simpson ~ Treatment + (1 | Patient)
   Data: mdata

REML criterion at convergence: -265.2

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-4.1327 -0.3715  0.2769  0.5856  1.8460 

Random effects:
 Groups   Name        Variance Std.Dev.
 Patient  (Intercept) 0.00963  0.09813 
 Residual             0.02513  0.15852 
Number of obs: 417, groups:  Patient, 54

Fixed effects:
               Estimate Std. Error       df t value Pr(>|t|)    
(Intercept)     0.77381    0.02329 59.82000  33.222   <2e-16 ***
TreatmentPSO_L  0.05284    0.03345 67.95000   1.579    0.119    
TreatmentPSO_N  0.03621    0.03235 59.87000   1.119    0.268    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
            (Intr) TPSO_L
TrtmntPSO_L -0.696       
TrtmntPSO_N -0.720  0.819
### Beta-diversity (PC1) stats (reference= Healthy)
beta.pc1.healthy = lmer(PC1 ~ Treatment + (1|Patient), data = mdata)
summary(beta.pc1.healthy)
Linear mixed model fit by REML 
t-tests use  Satterthwaite approximations to degrees of freedom ['lmerMod']
Formula: PC1 ~ Treatment + (1 | Patient)
   Data: mdata

REML criterion at convergence: -348.4

Scaled residuals: 
     Min       1Q   Median       3Q      Max 
-2.54785 -0.62132 -0.03505  0.67839  2.97771 

Random effects:
 Groups   Name        Variance Std.Dev.
 Patient  (Intercept) 0.008044 0.08969 
 Residual             0.020505 0.14319 
Number of obs: 417, groups:  Patient, 54

Fixed effects:
               Estimate Std. Error       df t value Pr(>|t|)
(Intercept)     0.03222    0.02121 61.44000   1.519    0.134
TreatmentPSO_L -0.04946    0.03045 69.63000  -1.624    0.109
TreatmentPSO_N -0.04547    0.02946 61.49000  -1.543    0.128

Correlation of Fixed Effects:
            (Intr) TPSO_L
TrtmntPSO_L -0.697       
TrtmntPSO_N -0.720  0.822

RME using PSO_N as reference

mdata$Treatment <- factor(mdata$Treatment,levels=c("PSO_N","PSO_L","Healthy"))
### Chao1 stats (refence = PSO_N)
chao1.model.PSO_N = lmer(Chao1 ~ Treatment + (1|Patient) , data=mdata)
summary(chao1.model.PSO_N)
Linear mixed model fit by REML 
t-tests use  Satterthwaite approximations to degrees of freedom ['lmerMod']
Formula: Chao1 ~ Treatment + (1 | Patient)
   Data: mdata

REML criterion at convergence: 6441.2

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-2.3497 -0.5633 -0.0451  0.4410  4.3364 

Random effects:
 Groups   Name        Variance Std.Dev.
 Patient  (Intercept) 102521   320.2   
 Residual             272936   522.4   
Number of obs: 417, groups:  Patient, 54

Fixed effects:
                 Estimate Std. Error      df t value Pr(>|t|)    
(Intercept)       1013.31      73.49   63.70  13.788   <2e-16 ***
TreatmentPSO_L      43.34      65.30  372.20   0.664    0.507    
TreatmentHealthy  -124.73     105.90   63.60  -1.178    0.243    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
            (Intr) TPSO_L
TrtmntPSO_L -0.362       
TrtmntHlthy -0.694  0.251
### Simpson stats (reference= PSO_N)
simpson.model.PSO_N = lmer(Simpson ~Treatment +(1|Patient), data=mdata)
summary(simpson.model.PSO_N)
Linear mixed model fit by REML 
t-tests use  Satterthwaite approximations to degrees of freedom ['lmerMod']
Formula: Simpson ~ Treatment + (1 | Patient)
   Data: mdata

REML criterion at convergence: -265.2

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-4.1327 -0.3715  0.2769  0.5856  1.8460 

Random effects:
 Groups   Name        Variance Std.Dev.
 Patient  (Intercept) 0.00963  0.09813 
 Residual             0.02513  0.15852 
Number of obs: 417, groups:  Patient, 54

Fixed effects:
                  Estimate Std. Error        df t value Pr(>|t|)    
(Intercept)        0.81002    0.02245  59.90000  36.078   <2e-16 ***
TreatmentPSO_L     0.01663    0.01981 367.50000   0.839    0.402    
TreatmentHealthy  -0.03621    0.03235  59.90000  -1.119    0.268    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
            (Intr) TPSO_L
TrtmntPSO_L -0.360       
TrtmntHlthy -0.694  0.250
### Beta-diversity (PC1) stats (reference= PSO_N)
beta.pc1.PSO_N = lmer(PC1 ~ Treatment + (1|Patient), data = mdata)
summary(beta.pc1.PSO_N)
Linear mixed model fit by REML 
t-tests use  Satterthwaite approximations to degrees of freedom ['lmerMod']
Formula: PC1 ~ Treatment + (1 | Patient)
   Data: mdata

REML criterion at convergence: -348.4

Scaled residuals: 
     Min       1Q   Median       3Q      Max 
-2.54785 -0.62132 -0.03505  0.67839  2.97771 

Random effects:
 Groups   Name        Variance Std.Dev.
 Patient  (Intercept) 0.008044 0.08969 
 Residual             0.020505 0.14319 
Number of obs: 417, groups:  Patient, 54

Fixed effects:
                   Estimate Std. Error         df t value Pr(>|t|)
(Intercept)       -0.013249   0.020445  61.600000  -0.648    0.519
TreatmentPSO_L    -0.003989   0.017900 368.800000  -0.223    0.824
TreatmentHealthy   0.045469   0.029460  61.500000   1.543    0.128

Correlation of Fixed Effects:
            (Intr) TPSO_L
TrtmntPSO_L -0.357       
TrtmntHlthy -0.694  0.248
LS0tCnRpdGxlOiAiUnVubmluZyBsaW5lYXIgbWl4ZWQgZWZmZWN0IG1vZGVsIgpvdXRwdXQ6CiAgaHRtbF9kb2N1bWVudDoKICAgIGRmX3ByaW50OiBwYWdlZAogIGh0bWxfbm90ZWJvb2s6IGRlZmF1bHQKICBwZGZfZG9jdW1lbnQ6IGRlZmF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