11module MissingTest
22
33using MultiResponseVarianceComponentModels
4- using Test
4+ using BenchmarkTools, LinearAlgebra, Profile, Random, StatsBase, Test
5+
6+ const MRVCModels = MultiResponseVarianceComponentModels
7+ Random. seed! (789 )
8+
9+ n, p, d, m = 855 , 3 , 4 , 3
10+ X = [ones (n) randn (n, p - 1 )] # design matrix including intercept
11+ # V[1] is an AR1(ρ) matrix, with entries ρ^|i-j|
12+ # V[2] has entries i * (n - j + 1) for j ≥ i, then scaled to be a correlation matrix
13+ # V[3] is identity
14+ ρ = 0.5
15+ V = Vector {Matrix{Float64}} (undef, m)
16+ V[1 ] = [ρ^ abs (i - j) for i in 1 : n, j in 1 : n]
17+ V[2 ] = [j ≥ i ? i * (n - j + 1 ) : j * (n - i + 1 ) for i in 1 : n, j in 1 : n]
18+ StatsBase. cov2cor! (V[2 ], [sqrt (V[2 ][i, i]) for i in 1 : n])
19+ V[3 ] = Matrix (UniformScaling (1.0 ), n, n)
20+ # true parameter values
21+ B_true = 2 * rand (p, d) # uniform on [0, 2]
22+ Σ_true = [
23+ Matrix (UniformScaling (0.2 ), d, d),
24+ Matrix (UniformScaling (0.2 ), d, d),
25+ Matrix (UniformScaling (0.6 ), d, d)
26+ ]
27+ Ω_true = zeros (n * d, n * d)
28+ for k in 1 : m
29+ Ω_true .+ = kron (Σ_true[k], V[k])
30+ end
31+ y = vec (X * B_true) + cholesky (Symmetric (Ω_true)). L * randn (n * d)
32+ Y = reshape (y, n, d)
33+
34+ Y_miss = Matrix {Union{eltype(Y), Missing}} (missing , size (Y))
35+ copy! (Y_miss, Y)
36+ Y_miss[rand (1 : length (Y_miss), n)] .= missing
537
638@testset " permute" begin
739 Y = reshape (1 : 16 , 4 , 4 )
@@ -15,4 +47,9 @@ using Test
1547 @test Y_imputed == [3.0 7.5 9.0 13.0 ; 2.0 7.5 10.0 14.0 ; 3.0 7.0 11.0 13.5 ; 4.0 8.0 12.0 13.5 ]
1648end
1749
50+ @testset " fit! missing response with MM" begin
51+ model = MRVCModel (Y_miss, X, V; se = false )
52+ # @timev MultiResponseVarianceComponentModels.fit!(model)
53+ end
54+
1855end
0 commit comments