Inputs for Jamovi vs R

Everything related to the development of modules in jamovi
unm111
Posts: 4
Joined: Sat Oct 21, 2023 6:08 pm

Inputs for Jamovi vs R

Post by unm111 »

I am trying to build a module for MannKendall Trend analysis for Jamovi but has hit a roadblock.

The test only takes x as an input
>>
>>

Code: Select all

MannKendall(x)
So in a.yaml I have

Code: Select all

options:
    - name: data
      type: Data
      description:
          R: the data as a data frame

    - name: x
      title: Series to check trend
      type: Variable 
      description:
          R: a vector of strings specifying the series variable in `data`
...
But I am getting an error (see attached image).

I followed the ttest example which takes the 5 inputs
>> ttestIS(data, dep, group, alt='not equal', varEq=FALSE)

But when I check in R, the ttest takes only x and y as required inputs
>>

Code: Select all

Description
Performs one and two sample t-tests on vectors of data.

Usage
t.test(x, ...)

## Default S3 method:
t.test(x, y = NULL,
       alternative = c("two.sided", "less", "greater"),
       mu = 0, paired = FALSE, var.equal = FALSE,
       conf.level = 0.95, ...)

## S3 method for class 'formula'
t.test(formula, data, subset, na.action, ...)
How to decide on how many inputs to have? In R help section or anywhere else?

Best,
M
Guess my question is how to decide the inputs.
Attachments
Error on Jamovi
Error on Jamovi
Capture.PNG (14.38 KiB) Viewed 5430 times
User avatar
MAgojam
Posts: 417
Joined: Thu Jun 08, 2017 2:33 pm
Location: Parma (Italy)

Re: Inputs for Jamovi vs R

Post by MAgojam »

Hey @unm111,
It looks like you'll want to use the MannKendall() function from the Kendall package (author A.I. McLeod) for your module.
So in the .a.yaml file you have type: Variable which will allow you to select a single variable on the sheet and not type: Variables to be able to select one.
In your b.r file there is MannKendall(self$options$x), which does not receive a vector with the data, because with self$options$x, the argument you pass to the function is just a string with the variable name.
So I'll leave you some bare-bones code and if you want, copy the pieces indicated in the corresponding files to try it out.

Code: Select all

## File: mannkendall.b.r 
mannkendallClass <-
    if (requireNamespace('jmvcore', quietly = TRUE))
        R6::R6Class("mannkendallClass",
            inherit = mannkendallBase,
            private = list(
                .run = function() {

                    if ( length(self$options$x) < 1 )
                        return()

                    results <- Kendall::MannKendall(x = self$data[, self$options$x])

                    self$results$text$setContent(results)

                }

            )
        )
## --- end .b.r


## File: mannkendall.a.yaml 
name:  mannkendall
title: Mann-Kendall trend test
menuGroup: ANOVA
menuSubgroup: Non-Parametric
menuTitle: Trend Test
menuSubtitle: Mann-Kendall

version: '0.0.1'
jas: '1.2'

options:
    - name: data
      type: Data
      description:
          R: the data as a data frame

    - name: x
      title: Series to check trend
      type: Variable
      suggested:
          - continuous
      permitted:
          - numeric
      rejectInf: false

...
## --- end .a.yaml


## File: mannkendall.r.yaml
name:  mannkendall
title: Mann-Kendall trend test
jrs:   '1.1'

items:
    - name:  text
      title: Results Test
      type:  Preformatted

...
## --- end .r.yaml
Cheers,
Maurizio
unm111
Posts: 4
Joined: Sat Oct 21, 2023 6:08 pm

Re: Inputs for Jamovi vs R

Post by unm111 »

Hi Maurizio,

Thanks for your response.
I implemented the changes you suggested, but I still have the same error. PFA.

Best,
M
Attachments
Capture.PNG
Capture.PNG (10.96 KiB) Viewed 5246 times
User avatar
MAgojam
Posts: 417
Joined: Thu Jun 08, 2017 2:33 pm
Location: Parma (Italy)

Re: Inputs for Jamovi vs R

Post by MAgojam »

unm111 wrote: Sat Nov 04, 2023 6:41 pm .. but I still have the same error.
Hey @unm111,
I think I should take a look at your form.
If GitHub hosts it, send me the link to reach it, I'll see what happens and I can fix it if necessary.

Cheers,
Maurizio
User avatar
jonathon
Posts: 2598
Joined: Fri Jan 27, 2017 10:04 am

Re: Inputs for Jamovi vs R

Post by jonathon »

i think the problem here is that you've named your analysis MannKendall, which also happens to be the name of the function you're trying to call.

in this situation R doesn't know that you want to call MannKendall() from the Kendall package, and thinks you're wanting to call MannKendall() from your own module... you analysis is calling itself.

to disambiguate this, call Kendall::MannKendall() from within .run()

cheers
unm111
Posts: 4
Joined: Sat Oct 21, 2023 6:08 pm

Re: Inputs for Jamovi vs R

Post by unm111 »

Here is the code for reference. https://github.com/mquazi/trend_Jamovi/tree/main
User avatar
jonathon
Posts: 2598
Joined: Fri Jan 27, 2017 10:04 am

Re: Inputs for Jamovi vs R

Post by jonathon »

hi @unm111,

did you see my remarks two posts up? i believe that's the problem you're facing.

jonathon
User avatar
MAgojam
Posts: 417
Joined: Thu Jun 08, 2017 2:33 pm
Location: Parma (Italy)

Re: Inputs for Jamovi vs R

Post by MAgojam »

Hey @unm111,
Jonathon has already called your attention to how to fix the problem.
Technically R is a function language with a very simple syntax and is case sensitive, so mannkendall and MannKendall are names for two different functions.
A few posts above I gave you the correct code for a copy and paste, but it doesn't seem like you got it.
So, now I've fixed the code for you and you have a PR from me if you want to accept it.

Cheers,
Maurizio
unm111
Posts: 4
Joined: Sat Oct 21, 2023 6:08 pm

Re: Inputs for Jamovi vs R

Post by unm111 »

I merged the changes Maurizio had in the PR, still the same error.
User avatar
jonathon
Posts: 2598
Joined: Fri Jan 27, 2017 10:04 am

Re: Inputs for Jamovi vs R

Post by jonathon »

having merged the changes (which introduces the changes on github), have you then synchronised those changes with the repo on your computer? i.e. are you able to see mz's changes in your local files?

we're keen to get you underway!

jonathon
Post Reply