[education/rkward] /: Add option to show standardized coefficients for linear regression
Thomas Friedrichsmeier
null at kde.org
Wed Apr 13 08:40:49 BST 2022
Git commit 1d33efe58c504d3d855ecd7d4adffa4a3ab4c08f by Thomas Friedrichsmeier.
Committed on 13/04/2022 at 07:40.
Pushed by tfry into branch 'master'.
Add option to show standardized coefficients for linear regression
M +1 -0 ChangeLog
M +6 -1 rkward/plugins/analysis/regression/linear_regression.js
M +1 -0 rkward/plugins/analysis/regression/linear_regression.rkh
M +2 -1 rkward/plugins/analysis/regression/linear_regression.xml
https://invent.kde.org/education/rkward/commit/1d33efe58c504d3d855ecd7d4adffa4a3ab4c08f
diff --git a/ChangeLog b/ChangeLog
index 9f6442d7..fb2c0cdd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,5 @@
--- Version 0.7.3 - Apr-21-2022
+- Add option to show standardized coefficients for linear regression
- Fixed: Possible backend hang when closing a data editor before it was done fetching its data
- Fixed: Crash when installing packages from within check installation dialog
- Fixed: Spurious string I18N_ARGUMENT_MISMATCH in several plugins
diff --git a/rkward/plugins/analysis/regression/linear_regression.js b/rkward/plugins/analysis/regression/linear_regression.js
index 8d877922..3487f063 100644
--- a/rkward/plugins/analysis/regression/linear_regression.js
+++ b/rkward/plugins/analysis/regression/linear_regression.js
@@ -1,3 +1,7 @@
+function preprocess() {
+ if (getBoolean("beta")) echo ('require("lm.beta")\n');
+}
+
function calculate () {
var vars = trim (getValue ("x")).replace (/\n/g, " + ");
var intercept = "";
@@ -11,9 +15,10 @@ function calculate () {
model = 'lm (' + getValue ("y") + ' ~ ' + intercept + vars;
if (!simple_mode) model += ', na.action=na.exclude'; // default action of na.omit is a nuisance for fitted values
model += ')';
+ if (getBoolean("beta")) model = 'lm.beta (' + model + ')';
if (simple_mode) {
- echo ('results <- summary.lm (' + model + ')\n');
+ echo ('results <- summary (' + model + ')\n');
} else {
echo ('model <- ' + model + '\n');
if (savemodel) echo ('.GlobalEnv$' + getString ('savemodel') + ' <- model\n');
diff --git a/rkward/plugins/analysis/regression/linear_regression.rkh b/rkward/plugins/analysis/regression/linear_regression.rkh
index a7f884ca..db1d88b8 100644
--- a/rkward/plugins/analysis/regression/linear_regression.rkh
+++ b/rkward/plugins/analysis/regression/linear_regression.rkh
@@ -13,6 +13,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="beta">Print standardized correlation coefficients? This requires the lm.beta package.</setting>
<caption id="tab_save"/>
<setting id="savemodel">Save the full fitted model.</setting>
<setting id="savefitted">Extract and save predicted values from the model.</setting>
diff --git a/rkward/plugins/analysis/regression/linear_regression.xml b/rkward/plugins/analysis/regression/linear_regression.xml
index cb09d54a..2a1e049f 100644
--- a/rkward/plugins/analysis/regression/linear_regression.xml
+++ b/rkward/plugins/analysis/regression/linear_regression.xml
@@ -10,7 +10,8 @@
<column>
<varslot types="numeric" id="y" source="vars" required="true" label="dependent variable"/>
<varslot types="numeric" id="x" source="vars" required="true" multi="true" label="independent variables"/>
- <checkbox id="intercept" label="include intercept" checked="true"/>
+ <checkbox id="intercept" label="Include intercept" checked="true"/>
+ <checkbox id="beta" label="Show standardized coefficients" checked="false"/>
<stretch/>
</column>
</row>
More information about the rkward-tracker
mailing list