Mixed Models Module

Everything related to the development of modules in jamovi
User avatar
mcfanda@gmail.com
Posts: 452
Joined: Thu Mar 23, 2017 9:24 pm

Mixed Models Module

Post by mcfanda@gmail.com »

Hi
I've a working version of the mixed models module. Still a lot work to be done, but it works. Any debug, suggestion, and like is very welcomed.

https://github.com/mcfanda/jamovi_mixed.git
User avatar
jonathon
Posts: 2609
Joined: Fri Jan 27, 2017 10:04 am

Re: Mixed Models Module

Post by jonathon »

hey! this looks really great!

you'll have to provide us with example data that we can try out.

cheers
User avatar
jonathon
Posts: 2609
Joined: Fri Jan 27, 2017 10:04 am

Re: Mixed Models Module

Post by jonathon »

Here's a quick review:

in .cleanData() you're using:

as.numeric(as.character(data[,x]))

to coerce factors to numeric. the issue with this is that if the column contains non-numeric values, it will (almost) silently convert these to missing values (NAs).

so you should use jmvcore::toNumeric() instead

after calling toNumeric() you can check that it is now numeric, and throw an error if it isn't.

https://dev.jamovi.org/tuts0202-handling-data.html

you also want to add .Rhistory and *.jmo to your .gitignore file (and not to your repo)

i'd encourage you to use camelCase for option names, and i'd encourage you to use the same column labels as we use in jamovi (just to be consistent). i.e.

SD for standard deviation
SE for standard error
p for p value
t for t statistic
we try and avoid dots in column headings

etc. we'll try and put together a style-guide for this stuff.

for your footnote, you have 'some computational error has occurred in lmerTest, summary from lme4 is returned' ... which is fine, but the user will be more interested in *why* and *how/if they can fix it* (and will be less interested in where it went wrong) ... but this error message might be appropriate if you're targeting a very technical audience.

finally, your indentation could do with some love, it's not always consistent.

cheers
User avatar
mcfanda@gmail.com
Posts: 452
Joined: Thu Mar 23, 2017 9:24 pm

Re: Mixed Models Module

Post by mcfanda@gmail.com »

great, thanks, i'm going to update accordingly
User avatar
mcfanda@gmail.com
Posts: 452
Joined: Thu Mar 23, 2017 9:24 pm

Re: Mixed Models Module

Post by mcfanda@gmail.com »

HI,
I have a little problem with jmvcore::toNumeric(), because it does not seem to convert factor to numeric when the variables come from a .cvs imported file. To exemplify, try this code

q<-as.data.frame(c(1,2,"1"))
names(q)<-"x"
jmvcore::toNumeric(q$x)

I thought it would convert the variable into a numeric variable, but it returns a factor. I guess it is because the variable "x" is a factor but does not have "values", which is the attribute toNumeric() test for. Is this intentional?
User avatar
jonathon
Posts: 2609
Joined: Fri Jan 27, 2017 10:04 am

Re: Mixed Models Module

Post by jonathon »

hey, sorry for the slow response.

in the context of an R session, i think you're better off throwing an error if they pass in a variable which is a factor, when a numeric is expected. so after calling toNumeric(), if it's not numeric, throw an error "argument X requires a numeric argument".

so in R, there's two reasons someone would pass in a factor (where a numeric variable is expected), 1) is that they made a mistake and assigned a wrong or inappropriate variable, 2) the other is that it *is* the correct variable, they just haven't changed it to a numeric.

if you automatically convert a factor to a numeric, you make things a little easier for the 2nd scenario, but the person in the 1st scenario is going to be pretty confused.

so i think it's better to throw an error that a numeric variable is required (in an R session), which helps person 1), and require person 2) to explicitly cast the variable to numeric.

does that make sense?

i appreciate you asking, because it draws my attention to things we haven't explained well.

of course, in jamovi, we *do* automatically change a factor to numeric, but factors in jamovi are a bit different to in R. i.e. we *know* when a factor is made entirely of numeric values (so we can rule out scenario 1)
User avatar
mcfanda@gmail.com
Posts: 452
Joined: Thu Mar 23, 2017 9:24 pm

Re: Mixed Models Module

Post by mcfanda@gmail.com »

make sense to me. i'd update accordingly
User avatar
mcfanda@gmail.com
Posts: 452
Joined: Thu Mar 23, 2017 9:24 pm

R packages space

Post by mcfanda@gmail.com »

Hi
it's not clear to me how jamovi invokes R. It seems that the R session underneath jamovi has a different .libPaths() that the R I would call from command line or from RStudio. Does it make sense?
User avatar
jonathon
Posts: 2609
Joined: Fri Jan 27, 2017 10:04 am

Re: Mixed Models Module

Post by jonathon »

hi mcfanda,

quite right. jamovi uses it's own version of R, and it doesn't use the system version of R at all. this is because we don't want changes to jamovi to change a user's R session, and we don't want changes to a user's R setup to change the behaviour of jamovi.

jamovi ships with a number of 'base' packages which all analyses/modules can use (listed below), and any additional packages will be bundled into the module. jmvtools will download it, and install it into the module -- if you look in the build directory for a module, you'll find all the packages it needs (from the DESCRIPTION) in there.

this has the advantage that a given module always ships with the same package dependencies, and improves reproducibility.

so you're right, it is different to the system .libPaths(), but you should still be able to do what you need.

let me know if there's a particular problem you're trying to solve.

cheers

jonathon

included packages are:

base64enc
evaluate
jmvcore
markdown
RColorBrewer
RInside
stringi
bitops
ggplot2
knitr
mime
Rcpp
rjson
stringr
colorspace
gridExtra
labeling
munsell
RCurl
rlang
tibble
dichromat
gtable
lazyeval
plyr
reshape
RProtoBuf
yaml
digest
highr
magrittr
R6
reshape2
scales
User avatar
mcfanda@gmail.com
Posts: 452
Joined: Thu Mar 23, 2017 9:24 pm

Re: Mixed Models Module

Post by mcfanda@gmail.com »

Thanks. that will solve the problem. However I made a terrible mistake: I left my project with a compilation error last time I worked on it (in june!) so now I have no recollection of what could have been wrong.

TypeError: Cannot read property 'isOptionControl' of undefined
at isOptionControl (/home/marcello/R/x86_64-pc-linux-gnu-library/3.3/jmvtools/node_modules/jamovi-compiler/uicompiler.js:566:50)
at removeMissingOptions (/home/marcello/R/x86_64-pc-linux-gnu-library/3.3/jmvtools/node_modules/jamovi-compiler/uicompiler.js:175:26)
at removeMissingOptions (/home/marcello/R/x86_64-pc-linux-gnu-library/3.3/jmvtools/node_modules/jamovi-compiler/uicompiler.js:173:32)
at uicompile (/home/marcello/R/x86_64-pc-linux-gnu-library/3.3/jmvtools/node_modules/jamovi-compiler/uicompiler.js:53:19)
at Object.<anonymous> (/home/marcello/R/x86_64-pc-linux-gnu-library/3.3/jmvtools/node_modules/jamovi-compiler/index.js:232:13)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)

Cannot read property 'isOptionControl' of undefined


Any hint where to start looking for the error?
Post Reply