2x2 contingency table

Everything related to the development of modules in jamovi
Post Reply
decaux
Posts: 27
Joined: Wed Feb 19, 2020 1:35 pm

2x2 contingency table

Post by decaux »

I am trying to produce a 2 x 2 contingency table as output and have lifted code from jamovi github yaml and r files, specifically from conttablespaired

A consistent error that I get is for the construction of .(' ') in the .b.R file, e.g. in the line:
subTitles <- c(.('Count'), .('% within row'), .('% within column'))

Debug in jamovi states: could not find function "."

Would appreciate some guidance. Thanks
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: 2x2 contingency table

Post by jonathon »

are you using the latest jamovi?

jonathon
decaux
Posts: 27
Joined: Wed Feb 19, 2020 1:35 pm

Re: 2x2 contingency table

Post by decaux »

I have now installed latest verstion 2.3.2.0 and get the same result, see screenshot here:
https://www.dropbox.com/s/tzhkbj4v0ukza ... t.png?dl=0

I have been using an older version of the conttablespaired.b.R but the relevant code looks the same in the most recent available on github. I am sorry, I am not familiar with the use of dots in the concatenate R function, e.g.
c(.('Count'), .('% within row'), .('% within column'))
which seems to be the problem.
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: 2x2 contingency table

Post by jonathon »

you can ditch the dots if you like ... they are for translations.

alternatively, import the . from jmvcore:

https://github.com/jamovi/jmv/blob/master/NAMESPACE#L31

cheers

jonathon
decaux
Posts: 27
Joined: Wed Feb 19, 2020 1:35 pm

Re: 2x2 contingency table

Post by decaux »

Great, thanks, that has got rid of that problem and it now is attempting to give a contingency table labelled correctly.
However, I am getting another error in the .init = function() section where it says "attempt to apply non-function", see screenshot:
https://www.dropbox.com/s/m9d7z8y3od70v ... 2.png?dl=0

Perhaps it's something to do with the object properties of freqs$ ? Such as freqs$addColumn
Or perhaps I should alter other constructions involving dots, such as name='.total[count]' ?
decaux
Posts: 27
Joined: Wed Feb 19, 2020 1:35 pm

Re: 2x2 contingency table

Post by decaux »

Please ignore previous, this is the problem:
Debug

Error in bitwOr(self$format, format): object 'Cell.BEGIN_GROUP' not found

private$.init()
freqs$addFormat(rowNo = i, 1, Cell.BEGIN_GROUP)
self$getCell(col = col, rowNo = rowNo, rowKey = rowKey)$addFormat(format)
bitwOr(self$format, format)
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: 2x2 contingency table

Post by jonathon »

same as before, you need to import Cell.BEGIN_GROUP from jmvcore.

cheers
decaux
Posts: 27
Joined: Wed Feb 19, 2020 1:35 pm

Re: 2x2 contingency table

Post by decaux »

Thanks, I have put the following in the NAMESPACE file:
import(jmvcore)
importFrom(jmvcore,.)
importFrom(jmvcore,Cell.BEGIN_GROUP)
importFrom(jmvcore,Cell.END_GROUP)
importFrom(jmvcore,Cell.BEGIN_END_GROUP)

However I now get the error in the post I said to ignore, namely
"attempt to apply non-function", see same screenshot:
https://www.dropbox.com/s/m9d7z8y3od70v4z/jam_screenshot2.png?dl=0
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: 2x2 contingency table

Post by jonathon »

you may find it easier to develop your module in rstudio, as it will be able to give you better diagnostics. alternatively, you can add print statements, and run jamovi at the terminal. once you narrow it down to the line of code that's responsible, i think this will be pretty clear (unfortunately, R's error messages aren't great like that).

that error means you're doing something like:

fred()

and fred isn't actually a function.

cheers

jonathon
decaux
Posts: 27
Joined: Wed Feb 19, 2020 1:35 pm

Re: 2x2 contingency table

Post by decaux »

Great advice, many thanks
Post Reply