[GRASS-SVN] r70089 - grass-addons/grass7/raster/r.vif

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Dec 18 04:24:59 PST 2016


Author: pvanbosgeo
Date: 2016-12-18 04:24:59 -0800 (Sun, 18 Dec 2016)
New Revision: 70089

Modified:
   grass-addons/grass7/raster/r.vif/r.vif.html
   grass-addons/grass7/raster/r.vif/r.vif.py
Log:
r.vif addon: minor corrections style

Modified: grass-addons/grass7/raster/r.vif/r.vif.html
===================================================================
--- grass-addons/grass7/raster/r.vif/r.vif.html	2016-12-17 21:21:52 UTC (rev 70088)
+++ grass-addons/grass7/raster/r.vif/r.vif.html	2016-12-18 12:24:59 UTC (rev 70089)
@@ -1,15 +1,15 @@
 <h2>DESCRIPTION</h2>
 
-The <em>r.vif</em> module computes the variance inflation factor 
+The <em>r.vif</em> module computes the variance inflation factor
 (<a href="https://en.wikipedia.org/wiki/Variance_inflation_factor">VIF</a>)
-[1] and the square root of the VIF. The VIF quantifies how much 
-the variance (the square of the estimate's standard deviation) of an 
-estimated regression coefficient is increased because of 
+[1] and the square root of the VIF. The VIF quantifies how much
+the variance (the square of the estimate's standard deviation) of an
+estimated regression coefficient is increased because of
 <a href="https://en.wikipedia.org/wiki/Multicollinearity">multi-collinearity</a>.
-The square root of VIF is a measure of how much larger 
-the standard error is, compared with what it would be if that 
-variable were uncorrelated with the other predictor variables in the 
-model. 
+The square root of VIF is a measure of how much larger
+the standard error is, compared with what it would be if that
+variable were uncorrelated with the other predictor variables in the
+model.
 
 <p>By default the VIF is calculated for each variable. If the user
 sets a VIF threshold value (maxvif) a stepwise variable selection
@@ -20,10 +20,10 @@
 maxvif. This can thus be used to select a sub-set of variables for
 e.g., multiple regression analysis.
 
-<p>The user can optionally select one or more variables to be 
-retained in the stepwise selection. For example, the user selects 
-the variable <i>bio_5</i> to be retained. If in any step this 
-variable has the highest VIF, the variable with the next highest VIF 
+<p>The user can optionally select one or more variables to be
+retained in the stepwise selection. For example, the user selects
+the variable <i>bio_5</i> to be retained. If in any step this
+variable has the highest VIF, the variable with the next highest VIF
 will be removed instead (see the examples).
 
 <p>The user can set the 's' flag to only print the finally selected
@@ -47,7 +47,7 @@
 
 Run VIF, setting the maximum VIF at 10. The function will print the
 VIF computed at each step to the console. The same will also be
-written to a text file. 
+written to a text file.
 
 <div class="code"><pre>MAPS=`g.list type=raster pattern=*2011*precip sep=,`
 r.vif maps=$MAPS file=results1.csv maxvif=10
@@ -79,7 +79,7 @@
 2011_07_precip     7.58     2.75
 2011_08_precip     3.32     1.82
 
-selected variables are: 
+selected variables are:
 --------------------------------------
 2011_01_precip, 2011_04_precip, 2011_05_precip, 2011_06_precip, 2011_07_precip, 2011_08_precip
 
@@ -121,7 +121,7 @@
 2011_07_precip     8.36     2.89
 2011_08_precip     3.30     1.82
 
-selected variables are: 
+selected variables are:
 --------------------------------------
 2011_02_precip, 2011_03_precip, 2011_04_precip, 2011_05_precip, 2011_06_precip, 2011_07_precip, 2011_08_precip
 
@@ -134,7 +134,7 @@
 Like example 1, but without writing the results to
 file, and with the 's' flag set, which means only the list with
 finally selected variables are printed to screen. This output can be
-directl parsed in a script. 
+directl parsed in a script.
 
 <div class="code"><pre>MAPS=`g.list type=raster pattern=*2011*precip sep=,`
 r.vif -s maps=$MAPS maxvif=10
@@ -173,19 +173,21 @@
 
 Suggested citation:
 
-<p>van Breugel, P., Friis, I., Demissew, S., Lillesø, J.-P. B., & 
-Kindt, R. 2015. Current and Future Fire Regimes and Their Influence 
-on Natural Vegetation in Ethiopia. Ecosystems. doi: 
+<p>van Breugel, P., Friis, I., Demissew, S., Lillesø, J.-P. B., &
+Kindt, R. 2015. Current and Future Fire Regimes and Their Influence
+on Natural Vegetation in Ethiopia. Ecosystems. doi:
 10.1007/s10021-015-9938-x.
 
 
 <h2>References</h2>
+
 [1] Graham, M.H. 2003. Confronting
 multicollinearity in ecological multiple regression. Ecology 84:
-2809–2815.
-[2] Craney, T.A., & Surles, J.G. 2002. Model-Dependent
+2809-2815.
+
+<p>[2] Craney, T.A., & Surles, J.G. 2002. Model-Dependent
 Variance Inflation Factor Cutoff Values. Quality Engineering 14:
-391–403.
+391-403.
 
 <h2>AUTHOR</h2>
 

Modified: grass-addons/grass7/raster/r.vif/r.vif.py
===================================================================
--- grass-addons/grass7/raster/r.vif/r.vif.py	2016-12-17 21:21:52 UTC (rev 70088)
+++ grass-addons/grass7/raster/r.vif/r.vif.py	2016-12-18 12:24:59 UTC (rev 70089)
@@ -75,9 +75,9 @@
 #%requires_all: -s,maxvif
 #%end
 
-#==============================================================================
-## General
-#==============================================================================
+# =============================================================================
+# General
+# =============================================================================
 
 # import libraries
 import os
@@ -91,13 +91,15 @@
     grass.message("You must be in GRASS GIS to run this program.")
     sys.exit(1)
 
+
 # Check if layers exist
 def CheckLayer(envlay):
     for chl in xrange(len(envlay)):
-        ffile = grass.find_file(envlay[chl], element = 'cell')
+        ffile = grass.find_file(envlay[chl], element='cell')
         if ffile['fullname'] == '':
             grass.fatal("The layer " + envlay[chl] + " does not exist.")
 
+
 # main function
 def main():
 
@@ -122,9 +124,9 @@
     OPF = options['file']
     flag_s = flags['s']
 
-    #==========================================================================
-    ## Calculate VIF and write to standard output (& optionally to file)
-    #==========================================================================
+    # =========================================================================
+    # Calculate VIF and write to standard output (& optionally to file)
+    # =========================================================================
 
     # Determine maximum width of the columns to be printed to std output
     name_lengths = []
@@ -139,8 +141,8 @@
     out_round = []
 
     # VIF is computed for each variable
-    #--------------------------------------------------------------------------
-    if MXVIF =='':
+    # -------------------------------------------------------------------------
+    if MXVIF == '':
         # Print header of table to std output
         print('{0[0]:{1}s} {0[1]:8s} {0[2]:8s}'.format(
             ['variable', 'vif', 'sqrtvif'], nlength))
@@ -151,8 +153,8 @@
             MAPx = IPF[:]
             del MAPx[k]
             vifstat = grass.read_command("r.regression.multi",
-                               flags="g", quiet=True,
-                               mapx=MAPx, mapy=MAPy)
+                                         flags="g", quiet=True,
+                                         mapx=MAPx, mapy=MAPy)
             vifstat = vifstat.split('\n')
             vifstat = [i.split('=') for i in vifstat]
             if float(vifstat[1][1]) > 0.9999999999:
@@ -175,7 +177,7 @@
             print("Statistics are written to " + OPF + "\n")
 
     # The stepwise variable selection procedure is run
-    #--------------------------------------------------------------------------
+    # -------------------------------------------------------------------------
     else:
         rvifmx = MXVIF + 1
         m = 0
@@ -207,8 +209,8 @@
                 MAPx = IPF[:]
                 del MAPx[k]
                 vifstat = grass.read_command("r.regression.multi",
-                                   flags="g", quiet=True,
-                                   mapx=MAPx, mapy=MAPy)
+                                             flags="g", quiet=True,
+                                             mapx=MAPx, mapy=MAPy)
                 vifstat = vifstat.split('\n')
                 vifstat = [i.split('=') for i in vifstat]
                 if float(vifstat[1][1]) > 0.9999999999:
@@ -248,7 +250,6 @@
                 del IPF[rvifindex]
                 del IPFn[rvifindex]
 
-
         # Write final selected variables to std output
         if not flag_s:
             print
@@ -262,27 +263,23 @@
         else:
             print(','.join(IPFn))
 
-    if len(OPF) > 0:
-        try:
-            text_file = open(OPF, "w")
-            if MXVIF =='':
-                text_file.write("variable,vif,sqrtvif\n")
-                for i in xrange(len(out_vif)):
-                    text_file.write('{0:s},{1:.6f},{2:.6f}\n'.format(
-                        out_variable[i], out_vif[i], out_sqrt[i]))
-            else:
-                text_file.write("round,removed,variable,vif,sqrtvif\n")
-                for i in xrange(len(out_vif)):
-                    text_file.write('{0:d},{1:s},{2:s},{3:.6f},{4:.6f}\n'.format(
-                        out_round[i], out_removed[i],out_variable[i],
-                         out_vif[i], out_sqrt[i]))
+        if len(OPF) > 0:
+            try:
+                text_file = open(OPF, "w")
+        if MXVIF == '':
+            text_file.write("variable,vif,sqrtvif\n")
+        for i in xrange(len(out_vif)):
+            text_file.write('{0:s},{1:.6f},{2:.6f}\n'.format(
+                out_variable[i], out_vif[i], out_sqrt[i]))
+        else:
+            text_file.write("round,removed,variable,vif,sqrtvif\n")
+        for i in xrange(len(out_vif)):
+            text_file.write('{0:d},{1:s},{2:s},{3:.6f},{4:.6f}\n'.
+                            format(out_round[i], out_removed[i],
+                                   out_variable[i], out_vif[i], out_sqrt[i]))
         finally:
             text_file.close()
 
 if __name__ == "__main__":
     options, flags = grass.parser()
     sys.exit(main())
-
-
-
-



More information about the grass-commit mailing list