Accessing output from the jmv( ) package

General help and assistance with jamovi. Bug reports can be made at our issues page: https://github.com/jamovi/jamovi/issues . (If you're unsure feel free to discuss it here)
Post Reply
User avatar
leehw
Posts: 20
Joined: Fri Nov 22, 2019 8:48 am

Accessing output from the jmv( ) package

Post by leehw »

I've started developing some teaching materials, using Jamovi as a (rather brilliant) teaching tool to scaffold students as they start to learn the basics of R. Enabling syntax in Jamovi, copying and pasting and running it with the jmv() package seems like a fantastic way to go.

But I've hit a snag. I want to be able to show student how to format their output tables, e.g. using kableExtra or similar packages. I figured I'd need to do a lot of experimentation to get this working, but I'm stuck at the first hurdle.

When I run most base R functions, or indeed functions from other packages, I generally get a dataframe or list saved to the local environment. So if I run this...

Code: Select all

lm_output <- lm(Sepal.Width ~ Petal.Width, iris)
I can access various bits of the output like this

Code: Select all

lm_output$coefficients
I can inspect the object I've saved the output to, over in the Data part of the Environment inspector, and figure out which bits I need.

When I use the jmv() package, e.g.

Code: Select all

library(jmv)

corr_output <- corrMatrix(iris, vars=vars(Sepal.Width, Petal.Length, Petal.Width),
           pearson = TRUE, sig = TRUE, flag = TRUE, n = TRUE, hypothesis = "corr")
I instead get an object saved as a single value with <Object containing active binding> against it.

How do I go about accessing tables and values, please? Is there a way to assign the output to an object in a similar way to how it works with base R functions etc?

(I'm hoping I've made that clear, but I'm not certain, so please do let me know if you need more detail.)
User avatar
MAgojam
Posts: 432
Joined: Thu Jun 08, 2017 2:33 pm
Location: Parma (Italy)

Re: Accessing output from the jmv( ) package

Post by MAgojam »

leehw wrote:I instead get an object saved as a single value with <Object containing active binding> against it.
Hey leehw,
this happens because the functions in jmv are R6 classes, as you can see here:
https://github.com/jamovi/jmv/blob/mast ... matrix.b.R

a few lines of code to play with:

Code: Select all

library(jmv)

out <- jmv::corrMatrix(data=iris,
                       vars=vars(Sepal.Width,
                                 Petal.Length, 
                                 Petal.Width),
                       pearson = TRUE, 
                       sig = TRUE, 
                       flag = TRUE, 
                       n = TRUE, 
                       hypothesis = "corr")
class(out)
names(out)

# a correlation matrix table
out$matrix
# or
out$analysis$results[[1]]

# a correlation matrix plot
out$plot
# or
out$analysis$results[[2]]

ls(out)
ls(out$matrix)
ls(out$matrix$asDF)

mt1 <- out$matrix
class(mt1)

df1 <- out$matrix$asDF
class(df1)

cat("Petal.Lenght-Sepal.Width",
    "\n------------------------",
    "\nr = ", df1[2, 7],
    "\np = ", df1[2, 8],
    "\nN = ", df1[2, 9],
    "\n\nPetal.Width-Sepal.Width",
    "\n-----------------------",
    "\nr = ", df1[3, 7],
    "\np = ", df1[3, 8],
    "\nN = ", df1[3, 9],
    "\n\nPetal.Width-Petal.Lenght",
    "\n------------------------",
    "\nr = ", df1[3, 10],
    "\np = ", df1[3, 11],
    "\nN = ", df1[3, 12]
    )
this from Rj:
Rj_iris.PNG
Rj_iris.PNG (122.6 KiB) Viewed 2476 times
Cheers,
Maurizio
User avatar
leehw
Posts: 20
Joined: Fri Nov 22, 2019 8:48 am

Re: Accessing output from the jmv( ) package

Post by leehw »

I've heard of R6 classes, but never explicitly used them. I'll do some reading. This definitely gives me a steer in the right direction.

Thanks, Maurizio!
User avatar
jonathon
Posts: 2743
Joined: Fri Jan 27, 2017 10:04 am

Re: Accessing output from the jmv( ) package

Post by jonathon »

mz is spot on, but you can also see the documentation either in R, or here:

https://www.jamovi.org/jmv/corrmatrix.html

if you're using RStudio, if you've assigned the results from corrMatrix to corr_output, you can type:

corr_output$

and RStudio will suggest different things you can access

cheers
Post Reply