Bayesian Linear Mixed Models (Conventional)

In [20]:
using JWAS,JWAS.Datasets,DataFrames,CSV

In [2]:
phenofile  = Datasets.dataset("example","phenotypes.txt")
phenotypes = CSV.read(phenofile,delim = ',',header=true,missingstrings=["NA"]);

In [3]:
first(phenotypes,5)


Out[3]:

5 rows × 9 columns

IDy1y2y3x1x2x3damweights
StringFloat64⍰Float64⍰Float64⍰Float64Float64StringString⍰Float64
1a1-0.063.58-1.180.92.0mmissing1.0
2a3-2.073.191.00.72.0fmissing1.0
3a4-2.636.97-0.830.61.0ma21.0
4a52.31missing-1.520.42.0ma21.0
5a7missingmissingmissing0.10.1ma31.0
Univariate Linear Mixed Models (Conventional)

In [4]:
model_equation1  ="y1 = intercept + x1*x3 + x2 + x3";

In [5]:
model1 = build_model(model_equation1);

In [6]:
set_covariate(model1,"x1");

In [7]:
set_random(model1,"x2");

In [8]:
out1=runMCMC(model1,phenotypes);


Checking phenotypes...
Individual IDs (strings) are provided in the first column of the phenotypic data.
Phenotypes for all traits included in the model for individual a7 in the row 5 are missing. This record is deleted.
Prior information for residual variance is not provided and is generated from the data.
Prior information for random effect variance is not provided and is generated from the data.

A Linear Mixed Model was build using model equations:

y1 = intercept + x1*x3 + x2 + x3

Model Information:

Term            C/F          F/R            nLevels
intercept       factor       fixed                1
x1*x3           interaction  fixed                2
x2              factor       random               2
x3              factor       fixed                2

MCMC Information:

methods                   conventional (no markers)
chain_length                                    100
burnin                                            0
estimateScale                                 false
starting_value                                false
printout_frequency                              101
output_samples_frequency                          1
constraint                                    false
missing_phenotypes                             true
update_priors_frequency                           0
seed                                          false

Hyper-parameters Information:

random effect variances (y1:x2):              [1.253]
residual variances:                           1.253

Degree of freedom for hyper-parameters:

residual variances:                           4.000
random effect variances:                      5.000



The file MCMC_samples_residual_variance.txt already exists!!! It is overwritten by the new output.
The file MCMC_samples_y1.x2_variances.txt already exists!!! It is overwritten by the new output.
running MCMC for conventional (no markers)...100%|██████| Time: 0:00:01

The version of Julia and Platform in use:

Julia Version 1.3.1
Commit 2d5741174c (2019-12-30 21:36 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.6.0)
  CPU: Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)


The analysis has finished. Results are saved in the returned variable and text files. MCMC samples are saved in text files.



In [9]:
keys(out1)


Out[9]:
Base.KeySet for a Dict{Any,Any} with 2 entries. Keys:
  "location parameters"
  "residual variance"

In [10]:
out1["location parameters"]


Out[10]:

7 rows × 5 columns

TraitEffectLevelEstimateStd_Error
AnyAnyAnyAnyAny
1y1interceptintercept-0.685652.15387
2y1x1*x3x1 * m-3.533232.7287
3y1x1*x3x1 * f2.511697.1064
4y1x22.01.013591.53674
5y1x21.0-1.278991.43765
6y1x3m2.542683.66508
7y1x3f-4.141173.3524

In [11]:
out1["residual variance"]


Out[11]:

1 rows × 3 columns

CovarianceEstimateStd_Error
AnyAnyAny
1y1_y11.534951.65136
Multivariate Linear Mixed Models (Conventional)

In [12]:
model_equation2 ="y1 = intercept + x1 + x3
                  y2 = intercept + x1 + x2 + x3
                  y3 = intercept + x1 + x1*x3 + x2";

In [13]:
model2 = build_model(model_equation2);

In [14]:
set_covariate(model2,"x1");

In [15]:
set_random(model2,"x2");


x2 is not found in model equation 1.

In [16]:
out2=runMCMC(model2,phenotypes,chain_length=5000,output_samples_frequency=100);


Checking phenotypes...
Individual IDs (strings) are provided in the first column of the phenotypic data.
Phenotypes for all traits included in the model for individual a7 in the row 5 are missing. This record is deleted.
Prior information for residual variance is not provided and is generated from the data.
Prior information for random effect variance is not provided and is generated from the data.

A Linear Mixed Model was build using model equations:

y1 = intercept + x1 + x3
y2 = intercept + x1 + x2 + x3
y3 = intercept + x1 + x1*x3 + x2

Model Information:

Term            C/F          F/R            nLevels
intercept       factor       fixed                1
x1              covariate    fixed                1
x3              factor       fixed                2
x2              factor       random               2
x1*x3           interaction  fixed                2

MCMC Information:

methods                   conventional (no markers)
chain_length                                   5000
burnin                                            0
estimateScale                                 false
starting_value                                false
printout_frequency                             5001
output_samples_frequency                        100
constraint                                    false
missing_phenotypes                             true
update_priors_frequency                           0
seed                                          false

Hyper-parameters Information:

random effect variances (y2:x2,y3:x2):
 1.081  0.0  
 0.0    0.316
residual variances:           
 1.253  0.0    0.0  
 0.0    1.081  0.0  
 0.0    0.0    0.316

Degree of freedom for hyper-parameters:

residual variances:                           7.000
random effect variances:                      6.000



The file MCMC_samples_residual_variance.txt already exists!!! It is overwritten by the new output.
The file MCMC_samples_y2.x2_y3.x2_variances.txt already exists!!! It is overwritten by the new output.
running MCMC for conventional (no markers)...100%|██████| Time: 0:00:03

The version of Julia and Platform in use:

Julia Version 1.3.1
Commit 2d5741174c (2019-12-30 21:36 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.6.0)
  CPU: Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)


The analysis has finished. Results are saved in the returned variable and text files. MCMC samples are saved in text files.



In [17]:
keys(out2)


Out[17]:
Base.KeySet for a Dict{Any,Any} with 2 entries. Keys:
  "location parameters"
  "residual variance"

In [18]:
out2["location parameters"]


Out[18]:

16 rows × 5 columns

TraitEffectLevelEstimateStd_Error
AnyAnyAnyAnyAny
1y1interceptintercept58.404334.3336
2y1x1x1-4.83794.53666
3y1x3m-55.540634.0001
4y1x3f-57.045434.0681
5y2interceptintercept15.213714.6064
6y2x1x1-11.90298.04085
7y2x22.00.2180781.02655
8y2x21.00.1428651.07977
9y2x3m-1.2875815.4774
10y2x3f-4.1013915.3815
11y3interceptintercept-1.662671.01476
12y3x1x1-15.34714.4518
13y3x1*x3x1 * m16.135314.3822
14y3x1*x3x1 * f19.342514.3084
15y3x22.0-0.1195270.59711
16y3x21.00.1439610.493966

In [19]:
out2["residual variance"]


Out[19]:

9 rows × 3 columns

CovarianceEstimateStd_Error
AnyAnyAny
1y1_y13.414082.91564
2y1_y2-0.2369252.33926
3y1_y3-0.1750380.861852
4y2_y1-0.2369252.33926
5y2_y21.531611.56651
6y2_y30.03333310.479879
7y3_y1-0.1750380.861852
8y3_y20.03333310.479879
9y3_y30.3031690.273024