[rkward-cvs] SF.net SVN: rkward-code:[4796] trunk/rkward

tfry at users.sf.net tfry at users.sf.net
Wed Aug 13 15:01:59 UTC 2014


Revision: 4796
          http://sourceforge.net/p/rkward/code/4796
Author:   tfry
Date:     2014-08-13 15:01:58 +0000 (Wed, 13 Aug 2014)
Log Message:
-----------
Linear regression plugin gains option to save predicted values

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/plugins/analysis/regression/linear_regression.js
    trunk/rkward/rkward/plugins/analysis/regression/linear_regression.rkh
    trunk/rkward/rkward/plugins/analysis/regression/linear_regression.xml

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2014-06-16 08:16:34 UTC (rev 4795)
+++ trunk/rkward/ChangeLog	2014-08-13 15:01:58 UTC (rev 4796)
@@ -1,3 +1,4 @@
+- Linear regression plugin gains option to save predicted values
 - Fixed some compilation problems
 - Add basic support to export plots using tikzDevice
 - Fixed: cbind-value of <matrix> element was missing commas

Modified: trunk/rkward/rkward/plugins/analysis/regression/linear_regression.js
===================================================================
--- trunk/rkward/rkward/plugins/analysis/regression/linear_regression.js	2014-06-16 08:16:34 UTC (rev 4795)
+++ trunk/rkward/rkward/plugins/analysis/regression/linear_regression.js	2014-08-13 15:01:58 UTC (rev 4796)
@@ -1,9 +1,22 @@
 function calculate () {
 	var vars = trim (getValue ("x")).replace (/\n/g, " + ");
 	var intercept = "";
-	if (!getValue ("intercept.state.numeric")) intercept = "0 + ";
+	if (!getBoolean ("intercept")) intercept = "0 + ";
 
-	echo ('results <- summary.lm (lm (' + getValue ("y") + ' ~ ' + intercept + vars + '))\n');
+	var savefitted = getBoolean ("savefitted.active");
+	var simple_mode = !savefitted;
+
+	model = 'lm (' + getValue ("y") + ' ~ ' + intercept + vars;
+	if (savefitted) model += ', na.action=na.exclude';	// default action of na.omit is a nuisance for fitted values
+	model += ')';
+
+	if (simple_mode) {
+		echo ('results <- summary.lm (' + model + ')\n');
+	} else {
+		echo ('model <- ' + model + '\n');
+		echo ('.GlobalEnv$' + getString ('savefitted') + ' <- fitted (model)\n');
+		echo ('results <- summary.lm (model)\n');
+	}
 }
 
 function printout () {

Modified: trunk/rkward/rkward/plugins/analysis/regression/linear_regression.rkh
===================================================================
--- trunk/rkward/rkward/plugins/analysis/regression/linear_regression.rkh	2014-06-16 08:16:34 UTC (rev 4795)
+++ trunk/rkward/rkward/plugins/analysis/regression/linear_regression.rkh	2014-08-13 15:01:58 UTC (rev 4796)
@@ -12,6 +12,7 @@
 		<setting id="y">The dependent variable. This must be numeric.</setting>
 		<setting id="x">One or more independent variables, each of the same length as the dependent. Note that factor variables are treated as categorial predictors, while numeric variables are treated as continuous predictors, automatically.</setting>
 		<setting id="intercept">Should an intercept term be included in the model?</setting>
+		<setting id="savefitted">Extract and save predicted values from the model.</setting>
 	</settings>
 	<related>
 		<ul>

Modified: trunk/rkward/rkward/plugins/analysis/regression/linear_regression.xml
===================================================================
--- trunk/rkward/rkward/plugins/analysis/regression/linear_regression.xml	2014-06-16 08:16:34 UTC (rev 4795)
+++ trunk/rkward/rkward/plugins/analysis/regression/linear_regression.xml	2014-08-13 15:01:58 UTC (rev 4796)
@@ -11,6 +11,7 @@
 				<varslot type="numeric" id="x" source="vars" required="true" multi="true" label="independent variables"/>
 				<checkbox id="intercept" label="include intercept" checked="true"/>
 				<stretch/>
+				<saveobject id="savefitted" label="Save fitted values" initial="lm_fitted" checkable="true"/>
 			</column>
 		</row>
 	</dialog>





More information about the rkward-tracker mailing list