Skip to content

Description of Mixed Effects Model

Hao Cheng edited this page Mar 2, 2021 · 3 revisions

Description of Mixed Effects Model

Linear Mixed Model

# Step 1: Load packages
using JWAS,DataFrames,CSV,Statistics,JWAS.Datasets

# Step 2: Read data 
phenofile  = dataset("phenotypes.csv")
phenotypes = CSV.read(phenofile,DataFrame,delim = ',',header=true,missingstrings=["NA"])

# Step 3: Build Model Equations

model_equation  ="y1 = intercept + x1 + x2 + x2*x3"
model = build_model(model_equation);

# Step 4: Set Factors or Covariates
set_covariate(model,"x1");

# Step 5: Set Random or Fixed Effects
set_random(model,"x2");

# Step 6: Solve Mixed Model Equations
out=solve(model,phenotypes);
describe(model)

# Following values are returned and saved in "out"
# out[1]     (1) names ;
# out[2]     (2) incidence matrix;
# out[3]     (3) left-hand side of mixed model equations 
# out[4]     (4) right-hand side of mixed model equations

Linear Additive Genetic Model

# Step 1: Load packages
using JWAS,DataFrames,CSV,Statistics,JWAS.Datasets

# Step 2: Read data 
phenofile  = dataset("phenotypes.csv")
pedfile    = dataset("pedigree.csv")
phenotypes = CSV.read(phenofile,DataFrame,delim = ',',header=true,missingstrings=["NA"])
pedigree   = get_pedigree(pedfile,separator=",",header=true);

# Step 3: Build Model Equations

model_equation  ="y1 = intercept + x1 + x2 + x2*x3 + ID + dam"
model = build_model(model_equation);

# Step 4: Set Factors or Covariates
set_covariate(model,"x1");

# Step 5: Set Random or Fixed Effects
set_random(model,"x2");
set_random(model,"ID dam",pedigree);

# Step 6: Solve Mixed Model Equations
out=solve(model,phenotypes);
describe(model)

# Following values are returned and saved in "out"
# out[1]     (1) names ;
# out[2]     (2) incidence matrix;
# out[3]     (3) left-hand side of mixed model equations 
# out[4]     (4) right-hand side of mixed model equations
Clone this wiki locally