Using R in Nova

Before loading (capture and load) a model, select “Enable R” in the menu  to connect Nova to R software.

 

COMMANDS:

Load R package: R.eval(“library(Rpackage)”);

Send NOVA object to R: R.assign(‘RObjectName’, NovaObjectName);

(or var NovaObjectToR = new R(‘RObjectName’, NovaObjectName);)

Call a R command in NOVA: var rName = R.eval(“Your R command”);

Transform R Object to Javascript Object: var jsName = R.toJS(rName);

 

EXAMPLE:

In the programming window, insert:

var Var1 = [85, 89, 99, 97, 82, 94, 82, 93, 92, 85];
var Var2 = [89, 90, 98, 96, 83, 92, 81, 95, 89, 81];
R.assign(“rVar1”,Var1);
R.assign(“rVar2”,Var2);
var Rtest = R.eval(“cor.test(rVar1, rVar2)”) // Test for association between variables Var1 and Var2
var jsRtest = R.toJS(Rtest);
var jsRtestCor = jsRtest[‘estimate’].toFixed(3);
var jsRtestPvalue = jsRtest[‘p.value’].toFixed(3);
print(jsRtestCor, jsRtestPvalue);

The console should return Cor = 0.922 and p.value = 0.000.

 

Other examples: coming soon…