当前位置: 移动技术网 > IT编程>开发语言>.net > .net 调用R语言的函数(计算统计值pvalue 对应excel :ttest)

.net 调用R语言的函数(计算统计值pvalue 对应excel :ttest)

2019年03月30日  | 移动技术网IT编程  | 我要评论

道奇caravan,奥林匹斯星传4,隐儿工作奇遇记

 

pvalue 计算

 

项目设计pvalue计算,但是由于.net 没有类似的公式或者函数,最终决定使用.net 调用r语言


采用.net 调用r语言的公用函数
需要安装 r语言环境 https://mirrors.tuna.tsinghua.edu.cn/cran/


前端调用api 发现需要ajax 同步调用
public string getpvalue(double[] data1, double[] data2)
{

rengine.setenvironmentvariables();
rengine engine = rengine.getinstance();
// rengine需要明确的初始化,
// 你可以设置一些参数。
engine.initialize();
// net向量转r向量
numericvector group1 = engine.createnumericvector(data1);
engine.setsymbol("group1", group1);
// 直接r脚本解析

// string value = "group2 <- c(55,66,377,88)";
numericvector group2 = engine.evaluate("group2 <- c(" + string.join(",", data2) + ")").asnumeric();
// 测试不同并获取pvalue
genericvector testresult = engine.evaluate("t.test(group1, group2,var.equal = true)").aslist();
double pvalue = testresult["p.value"].asnumeric().first();


//engine.dispose();

return convert.todouble(pvalue).tostring("f3");// getthree(objconvert.objstring(math.round(pvalue, 3)));

//rengine.setenvironmentvariables();
// rengine engine = rengine.getinstance();
// rengine需要明确的初始化,
// 你可以设置一些参数。
//engine.initialize();
// net向量转r向量

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网