pca.py: Add ability to drop columns (questions) from input data
authorW. Trevor King <wking@tremily.us>
Tue, 19 Mar 2013 13:04:30 +0000 (09:04 -0400)
committerW. Trevor King <wking@tremily.us>
Tue, 19 Mar 2013 13:04:30 +0000 (09:04 -0400)
posts/Factor_analysis/pca.py

index 03d1639690e0a6e69acea6e808c65fdeabd797ba..0e8aaaf2795a36ddddb425bae55718caeea11501 100755 (executable)
@@ -597,6 +597,9 @@ if __name__ == '__main__':
     parser.add_argument(
         '-u', dest='unitary', default=False, action='store_const', const=True,
         help='use unitary eigenvalues for factor loading')
     parser.add_argument(
         '-u', dest='unitary', default=False, action='store_const', const=True,
         help='use unitary eigenvalues for factor loading')
+    parser.add_argument(
+        '-d', dest='drop', type=int, action='append',
+        help='drop a column from the analysis')
     parser.add_argument(
         'path',
         help='path to the tab-delimited data file to analyze')
     parser.add_argument(
         'path',
         help='path to the tab-delimited data file to analyze')
@@ -604,4 +607,6 @@ if __name__ == '__main__':
     args = parser.parse_args()
 
     scores = _numpy.genfromtxt(fname=args.path, delimiter='\t')
     args = parser.parse_args()
 
     scores = _numpy.genfromtxt(fname=args.path, delimiter='\t')
+    if args.drop:
+        scores = _numpy.delete(scores, args.drop, axis=1)
     analyze(scores=scores, output_dim=args.output_dim, unitary=args.unitary)
     analyze(scores=scores, output_dim=args.output_dim, unitary=args.unitary)