-
Notifications
You must be signed in to change notification settings - Fork 44
Longitudinal Traits (Random Regression Model)
A naive longitudinal dataset with each individual having records on 5 time points is simulated to demonstrate the use of JWAS for random regression model. 50 individuals are randomly selected from the example dataset and values in "y1" and "y2" are assumed to be the random regression coefficients of additive genetic effects for the individuals. A linear regression of normal time covariates (Tmat) is used to simulate the phenotypes of individuals at each of the 5 time points. A consistent noise is added to the phenotypes.
using JWAS,DataFrames,CSV,Statistics,JWAS.Datasets,StatsBase,LinearAlgebra,Kronecker phenofile = dataset("phenotypes.csv") phenotypes = CSV.read(phenofile,DataFrame,delim = ',',header=true,missingstrings=["NA"])
phenotype = phenotypes[sample(1:size(phenotypes,1),50,replace=false),[:ID,:y1,:y2]]
n = size(phenotype,1) Idt = Matrix{Float64}(I, n, n) nTime = 5 Tmat = [ones(nTime) collect(1:nTime)] Z = Idt ⊗ Tmat us = [[] for i in 1:n] for i in 1:n us[i] = Matrix(phenotype)[i,2:end] end
uhat = vcat(us...) gBLUP = Z*uhat gBLUP= convert(Array{Float64,1}, gBLUP)
TimeSeriesPheno = DataFrame(ID = repeat(phenotype[!,:ID], inner = nTime), time = repeat(collect(1:nTime),outer=n),Y = gBLUP) TimeSeriesPheno[!,:Y] = TimeSeriesPheno[!,:Y] + randn(size(TimeSeriesPheno,1))
show(TimeSeriesPheno, allcols=true)