-
Notifications
You must be signed in to change notification settings - Fork 0
/
amova.h
169 lines (127 loc) · 5.6 KB
/
amova.h
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/**
* @file amova.h
* @brief header file for amova.cpp
* @details contains functions for performing Analysis of Molecular Variance (AMOVA)
*/
#ifndef __AMOVA_H__
#define __AMOVA_H__
/* INCLUDES ----------------------------------------------------------------- */
#include "shared.h"
/* END-OF-INCLUDES ---------------------------------------------------------- */
/* FORWARD-DECLARATIONS ----------------------------------------------------- */
typedef struct metadata_t metadata_t;
typedef struct argStruct argStruct;
typedef struct dmat_t dmat_t;
typedef struct outfile_t outfile_t;
typedef struct amova_t amova_t;
typedef struct strArray strArray;
/* END-OF-FORWARD-DECLARATIONS ---------------------------------------------- */
/* MACROS ------------------------------------------------------------------- */
/* END-OF-MACROS ------------------------------------------------------------ */
/* TYPEDEF-STRUCTS ---------------------------------------------------------- */
/**
* @brief amova - struct for storing AMOVA results
* @note if isShared==FALSE; then the arrays are allocated for each bootstrap replicate
* and the first array always stores the original data
*/
struct amova_t {
/// ------------------------------------------///
/// -> shared between bootstrap replicates <- ///
/// @var metadata - pointer to metadata to be used in AMOVA
metadata_t* metadata;
/// @var df - array of degrees of freedom
/// @note size = nLevels
/// df[i] = df for i-th level within the (i-1)-th level
/// [bootstrap] isShared = TRUE
int* df;
/// @var df_total - total degrees of freedom
/// [bootstrap] isShared = TRUE
int df_total;
/// @var vmat - used in the calculation of cmat
/// @note size = (nLevels * (nLevels+1)) / 2
/// upper triangular matrix of v_ij elements used in calculation of variance coefficients
/// [bootstrap] isShared = TRUE
double* vmat;
/// @var cmat - upper triangular matrix of variance coefficients
/// @note size = (nLevels * (nLevels+1)) / 2
/// in classical amova permutation test, this is isShared = FALSE
/// in bootstrapping, this is isShared = TRUE since ninds are not permuted
/// [bootstrap] isShared = TRUE
double* cmat;
/// @var lmat - inverse of cmat
/// @note size = (nLevels * (nLevels+1)) / 2
/// [bootstrap] isShared = TRUE
double* lmat;
/// ------------------------------------------///
/// -> unique to each bootstrap replicate <- ///
size_t nRuns;
/// @var ss - array of sum of squares within (SS^(w))
/// @note size = [nRuns][nLevels]
/// ss[i] = SS within the i-th level
/// ss[nLevels-1] = SS within individuals (currently unused! set to 0.0)
/// [bootstrap] isShared = FALSE
double** ss;
/// @var ss_total - total sum of squares
/// @note size = nRuns
/// [bootstrap] isShared = FALSE
double* ss_total;
/// @var ssd - array of sum of squared deviations (SSD)
/// @note size = [nRuns][nLevels]
/// [bootstrap] isShared = FALSE
double** ssd;
/// @var ssd_total - total sum of squared deviations (SSD)
/// @note size = nRuns
/// [bootstrap] isShared = FALSE
double* ssd_total;
/// @var msd - array of mean squared deviations
/// @note size = [nRuns][nLevels]
/// [bootstrap] isShared = FALSE
double** msd;
/// @var msd_total - total mean squared deviation
/// @note size = nRuns
/// [bootstrap] isShared = FALSE
double* msd_total;
/// @var sigmasq - array of variance components
/// @note size = [nRuns][nLevels]
/// sigmasq[r][i] = variance component for i-th level (for r-th run)
/// [bootstrap] isShared = FALSE
double** sigmasq;
/// @var sigmasq_total - sum of all variance components
/// @note size = nRuns
/// [bootstrap] isShared = FALSE
double* sigmasq_total;
/// @var phi_xt - array of phi_xt statistics
/// @note size = [nRuns][nLevels-1]
/// [bootstrap] isShared = FALSE
double** phi_xt;
/// @var phi_xy - array of phi_xy statistics
/// @note size = [nRuns][nLevels-2]
/// phi_xy[r][i] = Phi_{i(i-1)}^{*(r)} (r-th run)
/// [bootstrap] isShared = FALSE
double** phi_xy;
/// @note *_adj: allocated iff adjustment is needed (found a negative variance component)
/// @var sigmasq_adj - array of adjusted variance components
/// @note size = [nRuns][nLevels]
/// sigmasq_adj[r][i] = adjusted variance component for i-th level (for r-th run)
/// [bootstrap] isShared = FALSE
double** sigmasq_adj;
/// @var sigmasq_total_adj - sum of all adjusted variance components
/// @note size = [nRuns]
double* sigmasq_total_adj;
/// @var phi_xt_adj - array of adjusted phi_xt statistics
/// @note size = [nRuns][nLevels-1]
/// [bootstrap] isShared = FALSE
double** phi_xt_adj;
/// @var phi_xy_adj - array of adjusted phi_xy statistics
/// @note size = [nRuns][nLevels-2]
/// [bootstrap] isShared = FALSE
double** phi_xy_adj;
};
/* END-OF-TYPEDEF-STRUCTS --------------------------------------------------- */
/* FUNCTION-DECLARATIONS ----------------------------------------------------- */
amova_t* amova_get(dmat_t* dmat, metadata_t* mtd);
void amova_destroy(amova_t* amv);
/* END-OF-FUNCTION-DECLARATIONS ---------------------------------------------- */
// #endif // __X_H__
/* ========================================================================== */
#endif // __AMOVA_H__