Page 1 of 1
Adding a new variable to the dataset?
Posted: Wed Feb 23, 2022 3:13 am
by sfcheung
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
Re: Adding a new variable to the dataset?
Posted: Wed Feb 23, 2022 5:03 am
by jonathon
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
Re: Adding a new variable to the dataset?
Posted: Wed Feb 23, 2022 5:26 am
by sfcheung
Thanks a lot for your prompt reply! I will take a look and learn how it works.
-- Shu Fai
Re: Adding a new variable to the dataset?
Posted: Sun Feb 27, 2022 4:02 pm
by sfcheung
I tried to understand how to add variables but failed, for now.
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
This is what I tried in the .run function, used "0s" just for testing:
Code: Select all
if (self$results$hv$isNotFilled()) {
self$results$hv$setRowNums(rownames(self$data))
self$results$hv$setValues(rep(0, nrow(self$data)))
}
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
Re: Adding a new variable to the dataset?
Posted: Sun Feb 27, 2022 10:57 pm
by jonathon
could you commit this project somewhere, and point me to the repo? then i can take a proper look.
cheers
jonathon
Re: Adding a new variable to the dataset?
Posted: Mon Feb 28, 2022 1:22 am
by sfcheung
Re: Adding a new variable to the dataset?
Posted: Mon Feb 28, 2022 1:30 am
by jonathon
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
Re: Adding a new variable to the dataset?
Posted: Mon Feb 28, 2022 9:38 am
by sfcheung
I did not notice that there must be a check box for it to work. It works now! Many many thanks!
-- Shu Fai