-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmulticol_new.py
More file actions
44 lines (41 loc) · 1.13 KB
/
Copy pathmulticol_new.py
File metadata and controls
44 lines (41 loc) · 1.13 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
# -*- coding: utf-8 -*-
"""
Created on Fri Dec 04 09:05:53 2015
@author: a3940004
"""
# -*- coding: utf-8 -*-
"""
--------------------
Created on Thu Jul 24 13:37:39 2014
This function checks for perfect multicollineratity
--------------------
Notes:
Input: Xmat
Output: Xout, ind_x
Xout: matrix with linearly independent columns of Xmat
ind_x: indicator (1/0) for included variables
@author: A3940004
--------------------
"""
import numpy as np
def multicol_new(Xmat):
Xmat = np.asarray(Xmat)
nx,mx = Xmat.shape
# get a copy of Xmat
xtest = np.asarray(Xmat).copy()
# initialize xout with only one column
xout = np.zeros((nx,1))
ind_x = np.zeros((mx,1))
# ready to start looping over columns
# chck that it is indeed the case that not full rank
rank_x = np.linalg.matrix_rank(Xmat)
if rank_x==mx:
# if full-rank: just output same matrix
xout = Xmat
ind_x = np.ones((mx,1))
# if not full-rank, continue below
else:
for v in range(mx):
if np.linalg.matrix_rank(Xmat[:,:v+1]) < v+1:
print 'bad column is: ', v
#return xout,ind_x