forked from rgcgithub/regenie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMCC.hpp
147 lines (118 loc) · 4.91 KB
/
MCC.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
This file is part of the regenie software package.
Copyright (c) 2020-2024 Joelle Mbatchou, Andrey Ziyatdinov & Jonathan Marchini
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TESTMCC_H
#define TESTMCC_H
//-------------------------------------------------------------
// Class MCCResults for MCC test results
//-------------------------------------------------------------
class MCCResults
{
public:
double nl_dbl_dmin = 10.0 * std::numeric_limits<double>::min();
unsigned int N; // number of samples
unsigned int K; // numbr of covariates
unsigned int q; // number of traits
unsigned int M; // number of variables (to test for association)
Eigen::VectorXd n, n2;
// sum_x: q x M matrices
Eigen::MatrixXd sum_x, sum_x_sq;
Eigen::MatrixXd sum_x2, sum_x2_sq;
Eigen::MatrixXd sum_x3;
Eigen::MatrixXd sum_x4;
Eigen::MatrixXd sum_nx, sum_nx_sq;
Eigen::MatrixXd sum_nx2, sum_nx2_sq, sum_nx2_cub;
Eigen::MatrixXd sum_nx3, sum_nx4, sum_nx6;
// expectations: q x M matrices
Eigen::MatrixXd A; // observed test statistic
Eigen::MatrixXd EA, EA2, EA3, EA4;
// moments
Eigen::MatrixXd variance, kurtosis, skewness;
// Beta/Gamma distr.
Eigen::MatrixXd S1, S2;
Eigen::MatrixXd S1g, S2g, L;
MatrixXb SkipBeta, SkipGamma, Skip;
Eigen::MatrixXd R, PvalBeta, PvalGamma, Pval;
// DKAT
Eigen::MatrixXd D;
Eigen::MatrixXd Dm1, Dm2, Dm3;
Eigen::MatrixXd ShapeD, ScaleD, LocationD;
Eigen::MatrixXd PvalD;
//----------
// Methods
//----------
MCCResults();
MCCResults(unsigned int, unsigned int, unsigned int, unsigned int, const Eigen::VectorXd &n_);
~MCCResults();
void statistics(const MatrixXb &, const Eigen::MatrixXd &, const Eigen::MatrixXd &);
void expectations(const MatrixXb &, const Eigen::MatrixXd &,
const Eigen::VectorXd &, const Eigen::VectorXd &,
const Eigen::VectorXd &, const Eigen::VectorXd &,
const Eigen::VectorXd &, const Eigen::VectorXd &);
void moments();
void distr();
void dkat(const MatrixXb &, const Eigen::MatrixXd &,
const Eigen::MatrixXd &,
const Eigen::VectorXd &, const Eigen::VectorXd &,
const Eigen::VectorXd &, const Eigen::VectorXd &,
const Eigen::VectorXd &, const Eigen::VectorXd &,
const Eigen::VectorXd &, const Eigen::VectorXd &);
};
//-------------------------------------------------------------
// Class MCC for Moment-Matching Correlation (MCC) test
//-------------------------------------------------------------
class MCC
{
public:
/********************
* Public attributes
********************/
int verbose;
// dimensions
unsigned int n_samples; // number of samples
unsigned int n_traits; // number of traits
unsigned int n_covariates; // number of covariates
MatrixXb Mask; // masked samples = samples with missing values on phenotypes; 0 = missing
Eigen::VectorXd Neff; // number of non-missing samples (per trait)
Eigen::MatrixXd Yres; // matrix of residualized traits (missing are set to 0)
Eigen::MatrixXd Ynorm; // matrix of normalized residualized traits (missing are set to 0)
// precomputed products
Eigen::VectorXd sum_y, sum_y_sq;
Eigen::VectorXd sum_y2, sum_y2_sq;
Eigen::VectorXd sum_y3;
Eigen::VectorXd sum_y4;
// precomputed products for DKAT
Eigen::VectorXd sum_ny, sum_ny_sq;
Eigen::VectorXd sum_ny2, sum_ny2_sq, sum_ny2_cub;
Eigen::VectorXd sum_ny3, sum_ny4, sum_ny6;
/********************
* Public methods
********************/
void setup_y(const MatrixXb &, const Eigen::MatrixXd &res, unsigned int _n_covariates = 1);
MCCResults run(const Eigen::MatrixXd& G);
MCC();
~MCC() { };
private:
/********************
* Private methods
********************/
void check_setup_data();
void precomp_sumy();
};
#endif