-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathstat_wald_ht.py
More file actions
46 lines (34 loc) · 1.18 KB
/
Copy pathstat_wald_ht.py
File metadata and controls
46 lines (34 loc) · 1.18 KB
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
"""
calculating the test statistics.
Author: Chao Huang (chaohuang.stat@gmail.com)
Last update: 2017-08-14
"""
import numpy as np
from numpy.linalg import inv
"""
installed all the libraries above
"""
def wald_ht(x_design, efit_beta, esig_eta, cdesign):
"""
Smoothing individual function without preselected bandwidth.
Args:
x_design (matrix): design matrix (n*p)
efit_beta (matrix): coefficient matrix (p*l*m, m=d in MFSDA)
esig_eta (matrix): covariance matrix of eta (m*m*l, m=d in MFSDA)
cdesign (matrix): linear constraint matrix (1*(p-1))
"""
# Set up
p, l, m = efit_beta.shape
delta_beta = np.zeros((m*p, l))
for mii in range(m):
delta_beta[(mii*p):(mii+1)*p, :] = efit_beta[:, :, mii]
c_mat = np.kron(np.eye(m), cdesign)
dd = np.dot(c_mat, delta_beta)
omegax = inv(np.dot(cdesign, np.dot(inv(np.dot(x_design.T, x_design)), cdesign.T)))
lstat = np.zeros((l, 1))
for lii in range(l):
inv_esig_eta = inv(np.squeeze(esig_eta[:, :, lii]))
lstat[lii] = np.dot(np.dot(dd[:, lii].T, inv_esig_eta), dd[:, lii])
lstat = omegax * lstat
gstat = np.mean(lstat)
return gstat, lstat