I am making a program in Java to perform the Welch test, but I downloaded the apache poi because I wanted to use Excel function (T.INV.2T function) in the middle.
So I tried to put the formula in the cell, but the error returned as follows:
I'm a beginner, so I think it's a dirty coding, but please forgive me.
Please do.
error message
Exception in thread "main" org.apache.poi.ss.formula.FormulaParseException: Dotted range (full row or column) expression 'T.INV' must have exact 2 dots.
at org.apache.poi.ss.formula.FormulaParser.parseRangeable (FormulaParser.java:569)
at org.apache.poi.ss.formula.FormulaParser.parseRangeExpression (FormulaParser.java:322)
at org.apache.poi.ss.formula.FormulaParser.parseSimpleFactor (FormulaParser.java:1548)
at org.apache.poi.ss.formula.FormulaParser.percentFactor (FormulaParser.java:1506)
at org.apache.poi.ss.formula.FormulaParser.powerFactor (FormulaParser.java:1493)
at org.apache.poi.ss.formula.FormulaParser.Term (FormulaParser.java:1867)
at org.apache.poi.ss.formula.FormulaParser.additiveExpression (FormulaParser.java: 1994)
at org.apache.poi.ss.formula.FormulaParser.concatExpression (FormulaParser.java: 1978)
at org.apache.poi.ss.formula.FormulaParser.comparisonExpression (FormulaParser.java:1935)
at org.apache.poi.ss.formula.FormulaParser.intersectionExpression (FormulaParser.java:1908)
at org.apache.poi.ss.formula.FormulaParser.unionExpression (FormulaParser.java:1889)
at org.apache.poi.ss.formula.FormulaParser.parseSimpleFactor (FormulaParser.java:1534)
at org.apache.poi.ss.formula.FormulaParser.percentFactor (FormulaParser.java:1506)
at org.apache.poi.ss.formula.FormulaParser.powerFactor (FormulaParser.java:1493)
at org.apache.poi.ss.formula.FormulaParser.Term (FormulaParser.java:1867)
at org.apache.poi.ss.formula.FormulaParser.additiveExpression (FormulaParser.java: 1994)
at org.apache.poi.ss.formula.FormulaParser.concatExpression (FormulaParser.java: 1978)
at org.apache.poi.ss.formula.FormulaParser.comparisonExpression (FormulaParser.java:1935)
at org.apache.poi.ss.formula.FormulaParser.intersectionExpression (FormulaParser.java:1908)
at org.apache.poi.ss.formula.FormulaParser.unionExpression (FormulaParser.java:1889)
at org.apache.poi.ss.formula.FormulaParser.parse (FormulaParser.java: 2036)
at org.apache.poi.ss.formula.FormulaParser.parse (FormulaParser.java:170)
at org.apache.poi.xssf.usermodel.XSSFCell.setFormula (XSSFCell.java:550)
at org.apache.poi.xssf.usermodel.XSSFCell.setCellFormulaImpl (XSSFCell.java:526)
at org.apache.poi.ss.usermodel.CellBase.setCellFormula (CellBase.java:132)
at Main.Welch_test (Main.java:66)
at Main.main (Main.java:130)
code
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.*;
import java.util.Scanner;
public class Main
{
public static void Welch_test()
{
System.out.println("Test population mean two different populations are same or not");
System.out.println("This program works only for two-tailed";
Scanner in = new Scanner (System.in);
System.out.println("Do you want population with same variation(Type1) or different variation(Type2):");
int type = in.nextInt();
System.out.println("How many samples did you take from first population:");
double na = in.nextDouble();
System.out.println("How many samples did you take from second population:");
double nb = in.nextDouble();
System.out.println("What is your Sample mean for first population:");
double Xa = in.nextDouble();
System.out.println("What is your Sample mean for second population:");
double Xb = in.nextDouble();
System.out.println("What is unbias variance for first population:");
doubleUa=in.nextDouble();
System.out.println("What is unbied variance for second population:");
double Ub = in.nextDouble();
System.out.println("What is Level of Signature (Type with %-value)");
double L = in.nextDouble();
double = L/100;
if(type==1)
{
doublek = na+nb-2;
doublep = Math.abs (Xa-Xb);
double one=(1/na)+(1/nb));
double two=(((Ua)*(na-1)))+((Ub)*(nb-1)))/(na+nb-2);
double three=one*two;
double q = Math.sqrt(three);
double T = p/q;
System.out.println("Degre of freedom"+k);
System.out.println("Test statistics" + T);
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet();
Row1 = sheet.createRow(1);
Row2 = sheet.createRow(2);
Cellcell1_1=row1.createCell(1);
Cell cell1_2=row1.createCell(2);
Cell cell1_3 = row1.createCell(3);
Cell cell2_3 = row2.createCell(3);
cell1_1.setCellValue(l);
cell1_2.setCellValue(k);
cell2_3.setCellFormula("T.INV.2T(B2,C2)";
FileOutputStream out=null;
try{
out = new FileOutputStream("T-inverse.xlsx");
wb.write(out);
} catch(IOExceptione){
System.out.println(e.toString());
} US>finally
try{
out.close();
} catch(IOExceptione){
System.out.println(e.toString());
}
}
}
else
{
doublex = Math.abs (Xa-Xb);
doubley = Math.sqrt((Ua)/na)+((Ub)/nb));
double z = x/y;
System.out.println(z);
double parta=(((Ua)/na)+((Ub)/nb))*((Ua)/na)+((Ub)/nb)));
double partb=(((Ub)/nb)*((Ub)/nb-1));
double partc=(((Ua)/na)*((Ua)/na-1));
double partd = partc+partb;
double j=parta/partd;
j = Math.round(j);
System.out.println("Degre of Freedom" + j);
System.out.println("Test statistic is"+z);
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet();
Row1 = sheet.createRow(1);
Row2 = sheet.createRow(2);
Cellcell1_1=row1.createCell(1);
Cell cell1_2=row1.createCell(2);
Cell cell1_3 = row1.createCell(3);
Cell cell2_3 = row2.createCell(3);
cell1_1.setCellValue(l);
cell1_2.setCellValue(j);
cell2_3.setCellFormula("T.INV.2T(B2,C2)";
FileOutputStream out=null;
try{
out = new FileOutputStream("T-inverse.xlsx");
wb.write(out);
} catch(IOExceptione){
System.out.println(e.toString());
} US>finally
try{
out.close();
} catch(IOExceptione){
System.out.println(e.toString());
}
}
}
}
public static void main (String[]args)
{
Welch_test();
}
}
_xlfn.T.INV.2T(B2,C2)
instead of T.INV.2T(B2,C2)
seems to end without any errors. Do you get the desired result?
(I didn't know about the Welch test, so I didn't know if the result was correct.)
Note:
© 2024 OneMinuteCode. All rights reserved.