Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfc1ed9f

Browse files
committed
More robust support for user-supplied demographic variable names
This undoes4def5e7, which provided a fix for merging errors based on the output of `make_mean_diffs`. Doing so led to errors when calling `discord_regression()` which were not picked up by unit tests.The solution here provides a more robust method for prepping data by altering the output of `make_mean_diffs` to adhere to the user-supplied variable column names.
1 parent1c34d45 commitfc1ed9f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

‎R/func_discord_data.R‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ discord_data <- function(data, outcome, predictors, id = "extended_id", sex = "s
6969
mrg<-function(x,y) {
7070
merge(x=x,
7171
y=y,
72-
by= c("id","race_1","race_2"),
72+
by= c("id", paste0(race,"_1"),
73+
paste0(race,"_2")),
7374
all.x=TRUE)
7475
}
7576

@@ -80,7 +81,8 @@ discord_data <- function(data, outcome, predictors, id = "extended_id", sex = "s
8081
mrg<-function(x,y) {
8182
merge(x=x,
8283
y=y,
83-
by= c("id","sex_1","sex_2"),
84+
by= c("id", paste0(sex,"_1"),
85+
paste0(sex,"_2")),
8486
all.x=TRUE)
8587
}
8688

@@ -91,7 +93,8 @@ discord_data <- function(data, outcome, predictors, id = "extended_id", sex = "s
9193
mrg<-function(x,y) {
9294
merge(x=x,
9395
y=y,
94-
by= c("id","race_1","race_2","sex_1","sex_2"),
96+
by= c("id", paste0(sex,"_1"), paste0(sex,"_2"),
97+
paste0(race,"_1"), paste0(race,"_2")),
9598
all.x=TRUE)
9699
}
97100

‎R/helpers_regression.R‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ make_mean_diffs <- function(data, id, sex, race, demographics, variable, pair_id
101101
race_2=data[[raceS1]])
102102
}
103103

104+
names(output_demographics)<- paste0(race, c("_1","_2"))
104105
}elseif (demographics=="sex") {
105106

106107
if (data[,"order"]=="s1") {
@@ -111,6 +112,8 @@ make_mean_diffs <- function(data, id, sex, race, demographics, variable, pair_id
111112
sex_2=data[[sexS1]])
112113
}
113114

115+
names(output_demographics)<- paste0(sex, c("_1","_2"))
116+
114117
}elseif (demographics=="both") {
115118

116119
if (data[,"order"]=="s1") {
@@ -125,6 +128,7 @@ make_mean_diffs <- function(data, id, sex, race, demographics, variable, pair_id
125128
race_2=data[[raceS1]])
126129
}
127130

131+
names(output_demographics)<- c(paste0(sex, c("_1","_2")), paste0(race, c("_1","_2")))
128132
}
129133

130134
if (exists("output_demographics")) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp