Please pardon me for asking a naive question. I believe this is a basic task in writing module. However, I tried searching the forum but my search was rejected, saying that my search terms are too common.
When writing a module, how can we add new variables to the data set, like Linear Regression that can save Cook's distance and residuals? I have read the tutorial in https://dev.jamovi.org/ and also successfully wrote a simple package. However, I can't recall coming across a page on how to a variable. Maybe it is there but I missed it?
-- Shu Fai
Adding a new variable to the dataset?
Re: Adding a new variable to the dataset?
hi,
yes, this is something i need to document. your best bet is to see how jmv does it. here's how we do residuals in the ANOVA:
https://github.com/jamovi/jmv/blob/master/jamovi/ancova.r.yaml#L228-L238
and then you could populate it with something like:
https://github.com/jamovi/jmv/blob/master/R/ancova.b.R#L643-L646
cheers
jonathon
yes, this is something i need to document. your best bet is to see how jmv does it. here's how we do residuals in the ANOVA:
https://github.com/jamovi/jmv/blob/master/jamovi/ancova.r.yaml#L228-L238
and then you could populate it with something like:
https://github.com/jamovi/jmv/blob/master/R/ancova.b.R#L643-L646
cheers
jonathon
Re: Adding a new variable to the dataset?
Thanks a lot for your prompt reply! I will take a look and learn how it works.
-- Shu Fai
-- Shu Fai
Re: Adding a new variable to the dataset?
I tried to understand how to add variables but failed, for now.
This is what I added in *.r.yaml:
This is what I tried in the .run function, used "0s" just for testing:
No new variable was created, and there was no error message. I also tried to generate something as in this line, with the values computed inside setValues(...), but also failed:
https://github.com/jamovi/jmv/blob/addb ... .b.R#L1090
ANOVA in jmv uses active binding and private members, and they are used in setValues(). Are these elements required to make the "Output" type result add new output variables, and this type won't work if the values to be added are not stored in a member of "self"?
-- Shu Fai
This is what I added in *.r.yaml:
Code: Select all
- name: hv
type: Output
title: Leverage
varTitle: Leverage
varDescription: Leverage
measureType: continuous
clearWith:
- dv
- iv
Code: Select all
if (self$results$hv$isNotFilled()) {
self$results$hv$setRowNums(rownames(self$data))
self$results$hv$setValues(rep(0, nrow(self$data)))
}
https://github.com/jamovi/jmv/blob/addb ... .b.R#L1090
ANOVA in jmv uses active binding and private members, and they are used in setValues(). Are these elements required to make the "Output" type result add new output variables, and this type won't work if the values to be added are not stored in a member of "self"?
-- Shu Fai
Re: Adding a new variable to the dataset?
could you commit this project somewhere, and point me to the repo? then i can take a proper look.
cheers
jonathon
cheers
jonathon
Re: Adding a new variable to the dataset?
This is the test repo:
https://github.com/sfcheung/jmvtest
This is how the output is set up:
https://github.com/sfcheung/jmvtest/blo ... ml#L33-L41
This is my attempt to save the variable:
https://github.com/sfcheung/jmvtest/blo ... .R#L41-L45
Thanks a lot.
-- Shu Fai
https://github.com/sfcheung/jmvtest
This is how the output is set up:
https://github.com/sfcheung/jmvtest/blo ... ml#L33-L41
This is my attempt to save the variable:
https://github.com/sfcheung/jmvtest/blo ... .R#L41-L45
Thanks a lot.
-- Shu Fai
Re: Adding a new variable to the dataset?
sorry, i forgot to mention ... you need a matching Output option in your .a.yaml too:
https://github.com/jamovi/jmv/blob/master/jamovi/ancova.a.yaml#L405-L407
jonathon
https://github.com/jamovi/jmv/blob/master/jamovi/ancova.a.yaml#L405-L407
jonathon
Re: Adding a new variable to the dataset?
I did not notice that there must be a check box for it to work. It works now! Many many thanks!
-- Shu Fai
-- Shu Fai