Skip to content

Commit 25203d1

Browse files
committed
z
1 parent 5f05c5c commit 25203d1

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: jsmodule
22
Title: 'RStudio' Addins and 'Shiny' Modules for Medical Research
33
Version: 1.0.3
4-
Date: 2019-11-08
4+
Date: 2019-11-12
55
Authors@R: c(person("Jinseob", "Kim", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-9403-605X")),
66
person("Zarathu", role = c("cph", "fnd"))
77
)

NEWS.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# jsmodule 1.0.3
22

3-
* Bug fixes: Incorrect p-value when applying cluster options.
3+
## Bug fixes
4+
5+
* Incorrect p-value when applying cluster options.
6+
7+
* PS matching: allow continuous variables as Independent variables
8+
9+
## Update
10+
11+
* PS matching: allow 1:N matching.
412

513

614
# jsmodule 1.0.2

R/FilePsInput.R

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ FilePsInput <- function(id, label = "Upload data (csv/xlsx/sav/sas7bdat/dta)") {
6060
uiOutput(ns("group_ps")),
6161
uiOutput(ns("indep_ps")),
6262
uiOutput(ns("pcut")),
63-
uiOutput(ns("caliperps"))
63+
uiOutput(ns("caliperps")),
64+
uiOutput(ns("ratio"))
6465
)
66+
67+
6568
}
6669

6770

@@ -191,7 +194,8 @@ FilePs <- function(input, output, session, nfactor.limit = 20) {
191194
nclass <- unlist(out[, lapply(.SD, function(x){length(unique(x))}), .SDcols = conti_vars])
192195
factor_adds_list = mklist(data_varStruct, names(nclass)[(nclass <= nfactor.limit) & (nclass < nrow(out))])
193196

194-
except_vars <- names(nclass)[ nclass== 1 | nclass >= nfactor.limit]
197+
#except_vars <- names(nclass)[ nclass== 1 | nclass >= nfactor.limit]
198+
except_vars <- names(nclass)[ nclass== 1]
195199
add_vars <- names(nclass)[nclass >= 1 & nclass <= 5]
196200
#factor_vars_ini <- union(factor_vars, add_vars)
197201
naomit <- ifelse(length(naCol) == 0, "Data has <B>no</B> missing values.", paste("Column <B>", paste(naCol, collapse = ", "), "</B> are(is) excluded due to missing value.", sep = ""))
@@ -219,6 +223,13 @@ FilePs <- function(input, output, session, nfactor.limit = 20) {
219223
selected = 0.1, inline =T)
220224
})
221225

226+
output$ratio <- renderUI({
227+
if (is.null(input$file)){return(NULL)}
228+
radioButtons(session$ns("ratio_ps"), label = "Case:control ratio",
229+
choices = c("1:1" = 1, "1:2" = 2, "1:3" = 3, "1:4" = 4),
230+
selected = 1, inline =T)
231+
})
232+
222233

223234
observeEvent(data.info(), {
224235
output$factor <- renderUI({
@@ -513,15 +524,15 @@ FilePs <- function(input, output, session, nfactor.limit = 20) {
513524

514525

515526

516-
mat.info <- eventReactive(c(input$indep_pscal, input$group_pscal, input$caliper, data()), {
527+
mat.info <- eventReactive(c(input$indep_pscal, input$group_pscal, input$caliper, input$ratio_ps, data()), {
517528
req(input$indep_pscal)
518529
if (is.null(input$group_pscal) | is.null(input$indep_pscal)){
519530
return(NULL)
520531
}
521532
data <- data.table(data()$data)
522533

523534
forms <- as.formula(paste(input$group_pscal, " ~ ", paste(input$indep_pscal, collapse = "+"), sep=""))
524-
m.out <- MatchIt::matchit(forms, data = data, caliper = input$caliper)
535+
m.out <- MatchIt::matchit(forms, data = data, caliper = input$caliper, ratio = as.integer(input$ratio_ps))
525536
pscore <- m.out$distance
526537
iptw <- ifelse(m.out$treat == levels(m.out$treat)[2], 1/pscore, 1/(1-pscore))
527538
wdata <- cbind(data, pscore, iptw)

R/jsPropensityGadget.R

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ jsPropensityGadget <- function(data, nfactor.limit = 20){
6060
conti_original <- setdiff(names(out), factor_vars)
6161
nclass <- unlist(out[, lapply(.SD, function(x){length(unique(x))}), .SDcols = conti_original])
6262
factor_adds_list = mklist(data_varStruct1, names(nclass)[nclass <= nfactor.limit])
63-
64-
except_vars <- names(nclass)[ nclass== 1 | nclass >= nfactor.limit]
63+
except_vars <- names(nclass)[ nclass== 1]
64+
#except_vars <- names(nclass)[ nclass== 1 | nclass >= nfactor.limit]
6565
factor_adds <- names(nclass)[nclass >= 1 & nclass <= 5]
6666

6767

@@ -85,7 +85,8 @@ jsPropensityGadget <- function(data, nfactor.limit = 20){
8585
uiOutput("group_ps"),
8686
uiOutput("indep_ps"),
8787
uiOutput("pcut"),
88-
uiOutput("caliperps")
88+
uiOutput("caliperps"),
89+
uiOutput("ratio")
8990

9091
),
9192
mainPanel(
@@ -307,6 +308,12 @@ jsPropensityGadget <- function(data, nfactor.limit = 20){
307308
selected = 0.1, inline =T)
308309
})
309310

311+
output$ratio <- renderUI({
312+
radioButtons("ratio_ps", label = "Case:control ratio",
313+
choices = c("1:1" = 1, "1:2" = 2, "1:3" = 3, "1:4" = 4),
314+
selected = 1, inline =T)
315+
})
316+
310317
output$factor <- renderUI({
311318
selectInput("factor_vname", label = "Additional categorical variables",
312319
choices = factor_adds_list, multiple = T,
@@ -590,15 +597,15 @@ jsPropensityGadget <- function(data, nfactor.limit = 20){
590597

591598

592599

593-
mat.info <- eventReactive(c(input$indep_pscal, input$group_pscal, input$caliper, data.info()), {
600+
mat.info <- eventReactive(c(input$indep_pscal, input$group_pscal, input$caliper, input$ratio_ps, data.info()), {
594601
req(input$indep_pscal)
595602
if (is.null(input$group_pscal) | is.null(input$indep_pscal)){
596603
return(NULL)
597604
}
598605
data <- data.table::data.table(data.info()$data)
599606

600607
forms <- as.formula(paste(input$group_pscal, " ~ ", paste(input$indep_pscal, collapse = "+"), sep=""))
601-
m.out <- MatchIt::matchit(forms, data = data, caliper = input$caliper)
608+
m.out <- MatchIt::matchit(forms, data = data, caliper = input$caliper, ratio = as.integer(input$ratio_ps))
602609
pscore <- m.out$distance
603610
iptw <- ifelse(m.out$treat == levels(m.out$treat)[2], 1/pscore, 1/(1-pscore))
604611
wdata <- cbind(data, pscore, iptw)

0 commit comments

Comments
 (0)