Page 1 of 2

Inputs for Jamovi vs R

Posted: Sun Oct 29, 2023 8:00 pm
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.

Re: Inputs for Jamovi vs R

Posted: Mon Oct 30, 2023 11:36 pm
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

Re: Inputs for Jamovi vs R

Posted: Sat Nov 04, 2023 6:41 pm
by unm111
Hi Maurizio,

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

Best,
M

Re: Inputs for Jamovi vs R

Posted: Sat Nov 04, 2023 10:03 pm
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

Re: Inputs for Jamovi vs R

Posted: Sun Nov 05, 2023 4:53 am
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

Re: Inputs for Jamovi vs R

Posted: Wed Nov 29, 2023 9:07 pm
by unm111
Here is the code for reference. https://github.com/mquazi/trend_Jamovi/tree/main

Re: Inputs for Jamovi vs R

Posted: Wed Nov 29, 2023 9:23 pm
by jonathon
hi @unm111,

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

jonathon

Re: Inputs for Jamovi vs R

Posted: Wed Nov 29, 2023 10:45 pm
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

Re: Inputs for Jamovi vs R

Posted: Thu Feb 15, 2024 12:09 am
by unm111
I merged the changes Maurizio had in the PR, still the same error.

Re: Inputs for Jamovi vs R

Posted: Fri Feb 16, 2024 12:11 am
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