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

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Aug 3 03:00:53 PDT 2013


Author: pvanbosgeo
Date: 2013-08-03 03:00:53 -0700 (Sat, 03 Aug 2013)
New Revision: 57382

Modified:
   grass-addons/grass7/raster/r.vif/r.vif
   grass-addons/grass7/raster/r.vif/r.vif.html
Log:
Added the option to compute VIF on a random subset of raster cells

Modified: grass-addons/grass7/raster/r.vif/r.vif
===================================================================
--- grass-addons/grass7/raster/r.vif/r.vif	2013-08-03 01:26:19 UTC (rev 57381)
+++ grass-addons/grass7/raster/r.vif/r.vif	2013-08-03 10:00:53 UTC (rev 57382)
@@ -6,7 +6,9 @@
 # MODULE:       r.vif
 # AUTHOR(S):    Paulo van Breugel <p.vanbreugel AT gmail.com>
 # PURPOSE:      Calculate the variance inflaction factor of set of
-#				variables
+#				variables. Alternatively, to speed the calculation up, 
+#               this can be done for an user defined number of random 
+#               cells.
 # Dependency:	r.regression.multi
 #
 # COPYRIGHT: (C) 2013 Paulo van Breugel
@@ -42,6 +44,14 @@
 #% required: no
 #%end
 
+#%option
+#% key: nsp
+#% type: string
+#% gisprompt: new
+#% description: random sample size
+#% key_desc: number or percentage
+#% required: no
+#%end
 
 #=======================================================================
 ## GRASS team recommandations
@@ -97,6 +107,7 @@
 
 OPF=${GIS_OPT_OUTPUT_FILE}
 MAPS=${GIS_OPT_MAPS}
+TEMP1=`g.tempfile pid=$$`
 
 # test for missing input raster maps
 oIFS=$IFS
@@ -113,7 +124,7 @@
 unset tstIN
 
 #=======================================================================
-## Test if file exists. If so, append _v1 to file name
+## Test if text file exists. If so, append _v1 to file name
 #=======================================================================
 
 k=1
@@ -133,11 +144,29 @@
 ## Calculate VIF and write to standard output (& optionally to file)
 #=======================================================================
 
+# List with the input maps and first input map
+MAPS=`echo $GIS_OPT_MAPS | sed 's;,; ;g'`
+MAP1=`echo $MAPS | awk '{ print $1 }'`
+eval `g.gisenv`
+
 # Write text file with column headers
 if [ -n "$OPF" ]; then 
     echo "variable,vif,sqrtvif" > "$OPF"
 fi
 
+if [ ! -z "$GIS_OPT_NSP" ]; then
+    # Copy mask as backup if it exists
+    eval `g.findfile element=cell file=MASK mapset=$MAPSET`
+    remove_mask=1
+    if [ $file ] ; then 
+        g.copy rast=MASK,mask_r_vif_backup
+        mask_exists=1
+        unset file
+    fi
+    r.random input=$MAP1 n=$GIS_OPT_NSP raster_output=TMP_R_VIF_98765
+    r.mask --overwrite raster=TMP_R_VIF_98765
+fi
+
 # Calculate VIF for each variable
 MAPS=`echo $GIS_OPT_MAPS | sed 's;,; ;g'`
 for nvar in ${MAPS} ; do
@@ -155,7 +184,21 @@
 	if [ -n "$OPF" ] ; then 
         echo "$nvar,$vif,$sqrtvif" >> "$OPF"
     fi
-	
 done
 
+if [ $remove_mask ]; then
+    g.remove rast=MASK@${MAPSET},TMP_R_VIF_98765
+    unset remove_mask
+fi
 
+if [ $mask_exists ]; then
+    r.mask raster=mask_r_vif_backup
+    g.remove rast=mask_r_vif_backup
+    unset mask_exist
+fi
+
+
+
+
+
+

Modified: grass-addons/grass7/raster/r.vif/r.vif.html
===================================================================
--- grass-addons/grass7/raster/r.vif/r.vif.html	2013-08-03 01:26:19 UTC (rev 57381)
+++ grass-addons/grass7/raster/r.vif/r.vif.html	2013-08-03 10:00:53 UTC (rev 57382)
@@ -4,6 +4,9 @@
 
 <p>This module will compute variance inflaction factor (VIF) 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 collinearity. 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>The user has the option to compute the VIF over a random subset of the raster cells. Like in the r.random module (which is used to select the random set of raster cells), the user may specify the quantity of random cells either as a positive integer (e.g., 10), or as a percentage of the raster map layer's cells (e.g., 10%, or 3.05%). Percentages less than one percent may be stated as decimals. 
+
+
 <h2>Notes</h2>
 
 <p> This add-on doesn't work in GRASS 6.* as it depends on r.regression.multi, which is available in GRASS 7 main only. 



More information about the grass-commit mailing list