Load your own Write R language algorithm library public list<double> GETZTFB (double[] data) {list<double> par = new list< ;d ouble> (); try {//Call R language algorithm rengine.setenvironmentvariables (); Rengine engine = Rengine.getinstance (null, true, NULL, NULL); Numericvector x = engine. Createnumericvector (data); Engine. Setsymbol ("x", x); String path = System.Windows.Forms.Application.StartupPath + "\\R_FILE\\ZTFB. R "; Path = "Source (\" "+ Path +" \ ")"; Path = path. Replace ("\ \", "\\\\");//This step is critical, otherwise it will error engine. Evaluate (path); Engine. Evaluate ("a<-ztfb (x)"); Engine. Evaluate (@ "Normal <-function (theta) {//MU <-theta[1] Sigma <-Theta[2]// n <-Length (x)//LOGL < ;- -0.5*n*log (2*PI)-N*log (Sigma)-sum (0.5* (X-MU) ^2/sigma^2)// Return (-LOGL)//}//A< ;-Nlminb (C (0,1), normal) "); Numericvector a = engine. Evaluate ("a$par[1]"). Asnumeric (); Numericvector B = engine. Evaluate ("a$par[2]"). Asnumeric (); Par. ADD (Convert.todouble (a[0)); Par. ADD (Convert.todouble (b[0)); } catch (Exception ex) {throw new Exception (ex). Message); } return par; }///load r language Download library public list<double> GETZTFB (double[] data) {list<double> par = new List<dou Ble> (); try {//Call R language algorithm Rengine.seteNvironmentvariables (); Rengine engine = Rengine.getinstance (null, true, NULL, NULL),///Load R language Library Engine.evaluate ("library (\" bit\ ", lib.loc=\" c:/ Program files/r/r-3.3.2/library\ ")") Numericvector x = engine. Createnumericvector (data); Engine. Setsymbol ("x", x); String path = System.Windows.Forms.Application.StartupPath + "\\R_FILE\\ZTFB. R "; Path = "Source (\" "+ Path +" \ ")"; Path = path. Replace ("\ \", "\\\\");//This step is critical, otherwise it will error engine. Evaluate (path); Engine. Evaluate ("a<-ztfb (x)"); Engine. Evaluate (@ "Normal <-function (theta) {//MU <-theta[1] Sigma <-Theta[2]// n <-Length (x)//LOGL <--0.5*n*log (2*PI)-N*log (Sigma)-sum (0.5* (X-MU) ^2/sigma^2)// Return (-LOGL)//}//a<- NLMINB (c (0,1), normal) "); Numericvector a = engine. Evaluate ("a$par[1]"). Asnumeric (); Numericvector B = engine. Evaluate ("a$par[2]"). Asnumeric (); Par. ADD (Convert.todouble (a[0)); Par. ADD (Convert.todouble (b[0)); } catch (Exception ex) {throw new Exception (ex). Message); } return par; }
. NET call R language