如何将变量粘贴到公式中
当我尝试将变量粘贴到公式中时,我会遇到一个特殊的错误。我有以下变量:
# Choose explanatory variables
vars_int <- c("age",
"male",
"race_ethnicity",
"patient_regional_location",
"marital_status",
"total_admits",
"chf",
"copd",
"diabwc",
"mld",
"cevd",
"Obesity",
"Smoking")
当我将它们直接复制到公式中时,一切都很好:
# Generate inverse probability weights
wts_17 <- ipwpoint(
exposure = exposure,
family = "binomial",
link = "logit",
denominator = ~
age +
male +
race_ethnicity +
patient_regional_location +
marital_status +
total_admits +
chf +
copd +
diabwc +
mld +
cevd +
Obesity +
Smoking,
data = df_17)
但是,当我尝试使用过去的功能进行操作时,一切都会崩溃:
paste("~", paste(vars_int, collapse = " + "))
[1] "~ age + male + race_ethnicity + patient_regional_location + marital_status + total_admits + chf + copd + diabwc + mld + cevd + Obesity + Smoking"
> wts_17 <- ipwpoint(
+ exposure = exposure,
+ family = "binomial",
+ link = "logit",
+ denominator = paste("~", paste(vars_int, collapse = " + ")),
+ data = df_17)
Error in ipwpoint(exposure = exposure, family = "binomial", link = "logit", :
Invalid denominator formula specified
有人知道为什么会发生这种情况吗?
I'm getting a peculiar error when I try to paste variables into my formula. I have the following variables:
# Choose explanatory variables
vars_int <- c("age",
"male",
"race_ethnicity",
"patient_regional_location",
"marital_status",
"total_admits",
"chf",
"copd",
"diabwc",
"mld",
"cevd",
"Obesity",
"Smoking")
When I copy them directly into a formula, everything works fine:
# Generate inverse probability weights
wts_17 <- ipwpoint(
exposure = exposure,
family = "binomial",
link = "logit",
denominator = ~
age +
male +
race_ethnicity +
patient_regional_location +
marital_status +
total_admits +
chf +
copd +
diabwc +
mld +
cevd +
Obesity +
Smoking,
data = df_17)
But then when I try to do it using a past function, everything falls apart:
paste("~", paste(vars_int, collapse = " + "))
[1] "~ age + male + race_ethnicity + patient_regional_location + marital_status + total_admits + chf + copd + diabwc + mld + cevd + Obesity + Smoking"
> wts_17 <- ipwpoint(
+ exposure = exposure,
+ family = "binomial",
+ link = "logit",
+ denominator = paste("~", paste(vars_int, collapse = " + ")),
+ data = df_17)
Error in ipwpoint(exposure = exposure, family = "binomial", link = "logit", :
Invalid denominator formula specified
Does anyone know why this is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论