aj-grant / mrhorse

3 stars 3 forks source link

Error in 1:dim(D)[2] : argument of length 0 from running mvmr_horse #1

Open jjandshi opened 7 months ago

jjandshi commented 7 months ago

Hi,

When I tried demo data set, it worked as follows. try_dat = read.csv('data_mv_ex.csv') Res = mvmr_horse(try_dat) Res$MR_Estimate

Exposure Estimate Std Error 95% CI p-value X1 0.092 0.014 0.064, 0.120 0.000 X2 0.104 0.014 0.076, 0.131 0.000

However, if the data set was organized using mr_mvinput, the error popped up. mvmr_try = mr_mvinput(bx = cbind(try_dat$betaX1, try_dat$betaX2), bxse = cbind(try_dat$betaX1se, try_dat$betaX2se), by = try_dat$betaY, byse = try_dat$betaYse, exposure = c("X1", "X2"))

set.seed(20240319) try_hs = mvmr_horse(mvmr_try, no_ini = 3, variable.names = "theta")

Error in 1:dim(D)[2] : argument of length 0

Can you please take a look at it?

Thanks, Justin

aj-grant commented 7 months ago

Hi Justin, Thanks! The code currently requires the input in the form of a data frame with specific heading names. I will hopefully have an updated version which allows a bit more flexibility with this, but in the meantime the following should work:

mvmr_try = data.frame(betaX1 = try_dat$betaX1, betaX2 = try_dat$betaX2, betaX1se = try_dat$betaX1se, betaX2se = try_dat$betaX2se, betaY = try_dat$betaY, betaYse = try_dat$betaYse)

set.seed(20240319) try_hs = mvmr_horse(mvmr_try, no_ini = 3, variable.names = "theta")