Question

I want to get results from an method which is called kruskalmc.

The results in R console look like that:

Multiple comparison test after Kruskal-Wallis 
p.value: 0.05 
Comparisons
      obs.dif critical.dif difference  
1-2    7.65     9.425108      FALSE
1-3   14.40     9.425108       TRUE 
2-3    6.75     9.425108      FALSE

Now i want to get the values from the difference column.

If i try to get it in java with:

REXP res = re.eval("result$dif.com$difference");

I'll get back something like this: [BOOLi* ]

How can i iterate through in BOOLi object in java?

What i want are the values FALSE TRUE FALSE.

Was it helpful?

Solution

I haven't used JRI much but since no-one has answered you I'll go for it.

I could be wrong, but it seems there is no method for converting res to a boolean array – although there are methods for converting to int[], double[] and String[]. You could convert your result to integers like this:

REXP res = re.eval("result$dif.com$difference");
int[] x = res.asIntArray();

for (int i = 0; i < x.length; i++) {
  System.out.println(x[i]);
}

You will get back 1 representing TRUE values and 0 representing FALSE. You can convert those numbers to booleans if you want from Java then or just work with them as they are.

Not an ideal solution so I hope someone comes up with something better.

OTHER TIPS

As far as I can see, the issue is type conversion when exporting from R to java. Looking at part of the documentation for JRI:

The currently supported objects are string, integer and numeric vectors.

To give a reproducible example (from the functions own documentation):

require(pgirmess)
resp <-c(0.44,0.44,0.54,0.32,0.21,0.28,0.7,0.77,0.48,0.64,0.71,0.75,0.8,0.76,0.34,0.80,0.73,0.8)
categ <- as.factor(rep(c("A","B","C"),times=1,each=6))
k1 <- kruskalmc(resp, categ)

Then we can see that is.logical(k1[[3]][,3]) == TRUE:

> str(k1[[3]][,3])
logi [1:3] FALSE TRUE FALSE

while still in R the simplest method would seem to be converting this with

> as.numeric(k1[[3]][,3])
[1] 0 1 0

or you could send it across as character:

> as.character(k1[[3]][,3])
[1] "FALSE" "TRUE"  "FALSE"

Once in java you'll want to convert it back to boolean, or whatever final form you're working with.

Call:

survdiff(formula = model)

                                N Observed Expected (O-E)^2/E (O-E)^2/V
x[, 1]=G1:Vehicle               8        6     2.65      4.22      9.02
x[, 1]=G2:AZ13655037 15mg/kg/qd 8        0     3.35      3.35      9.02

Chisq= 9 on 1 degrees of freedom, p= 0.00267 Now we want to get the values from the p. How can i get it in java?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top