xue-hr / BiDirectCausal

R package for methods inferring bi-directional causal effects.
Other
4 stars 1 forks source link

When the sample size is large, the code for bidirectcausal method gives an error. #1

Open slayers0917 opened 1 year ago

slayers0917 commented 1 year ago

Hello, I got some problems when I use this package. When the sample size is large, the code for bidirectcausal method gives an error. How can this problem can be solved. Thanks!

xue-hr commented 1 year ago

Thanks for the comment! May I know what the error exactly is? It would be helpful to share your codes and results, thanks!

slayers0917 commented 1 year ago

Thanks for reply. This is the error and warnings and my code is also here. What' more, I want to know in your paper Robust inference of bi-directional causal relationships in presence of correlated pleiotropy with GWAS summary data, in the application, why you need to calculate the p_{c}? If the SNP only appears in one dataset, how can it be calculated? Thanks very much! b_X = c(-0.0494597,-0.1225190, 0.1031910, -0.0803954, 0.0496063, -0.0524684, -0.1226100, 0.1145660, 0.0868996, 0.0514451, 0.0553118, -0.1180780, -0.1179570, -0.0684767, -0.0502800, -0.0933099, -0.0730268, 0.0748902, 0.0522335, 0.0516626, -0.0713711, 0.0917951, -0.0675296, -0.1361630, 0.0930796, 0.0726514, -0.1069430) b_Y = c(-0.090804, -0.191620, -0.276780, 0.087834, -0.116990, -0.164510, 0.720240, 0.151040, -0.092209, -0.100400, 0.114700, -0.118190, -0.332630, 0.086278, 0.080370, 0.075291, 0.447050, -0.112410, 0.087863, -0.167000, -0.121670, 0.093567, 0.095589, 0.140360, 0.148590, 0.302840, 0.245770, -0.098691, -0.090686, 0.093457, 0.191520, 0.185020 ,-0.072538) se_X =c( 0.00881250, 0.01218560, 0.01449410, 0.01042860, 0.00864595, 0.00885602, 0.02226370, 0.01031790, 0.00862747, 0.00877601, 0.00889615, 0.01204300, 0.00875162, 0.01006160, 0.00914166, 0.01000840, 0.00949135, 0.01139940, 0.00876385, 0.00868508, 0.01097490, 0.00969277, 0.01067030, 0.01652310, 0.00989562, 0.00887141, 0.01489810) se_Y =c( 0.014115, 0.020854, 0.047929, 0.015696, 0.014039, 0.024454, 0.023350, 0.026299,0.016641 , 0.016667, 0.018266, 0.015702, 0.033390, 0.015194, 0.013081, 0.013084, 0.064278, 0.014746, 0.013787,0.021704 , 0.013117, 0.013679, 0.012792, 0.015764, 0.019189, 0.032920, 0.014955, 0.012799, 0.013095, 0.013694, 0.013610, 0.021859, 0.013079) BiDirMRcML(b_X = b_X, b_Y =b_Y, se_X = se_X, se_Y = se_Y, n_X = 260000, n_Y = 700000, sig.cutoff = 0.05/2, num_pert = 100,random_start = 0, random.seed = 1)

Error in while ((abs(theta_old - theta) > 1e-07) & (ite_ind < maxit)) { : missing value where TRUE/FALSE needed In addition: Warning messages: 1: In cML_estimate_random(b_exp = b_exp_new, b_out = b_out_new, se_exp = se_exp, : May not converge to minimums with some given start points and maximum number of iteration, lead to Fisher Information matrices not positive definite. Could try increasing number of iterations (maxit) or try different start points. Note: If multiple random start points are used, this warning does not likely affect result. 2: In cML_estimate_random(b_exp = b_exp_new, b_out = b_out_new, se_exp = se_exp, : May not converge to minimums with some given start points and maximum number of iteration, lead to Fisher Information matrices not positive definite. Could try increasing number of iterations (maxit) or try different start points. Note: If multiple random start points are used, this warning does not likely affect result. 3: In cML_estimate_random(b_exp = b_exp_new, b_out = b_out_new, se_exp = se_exp, : May not converge to minimums with some given start points and maximum number of iteration, lead to Fisher Information matrices not positive definite. Could try increasing number of iterations (maxit) or try different start points. Note: If multiple random start points are used, this warning does not likely affect result. 4: In cML_estimate_random(b_exp = b_exp_new, b_out = b_out_new, se_exp = se_exp, : May not converge to minimums with some given start points and maximum number of iteration, lead to Fisher Information matrices not positive definite. Could try increasing number of iterations (maxit) or try different start points. Note: If multiple random start points are used, this warning does not likely affect result. 5: In cML_estimate_random(b_exp = b_exp_new, b_out = b_out_new, se_exp = se_exp, : May not converge to minimums with some given start points and maximum number of iteration, lead to Fisher Information matrices not positive definite. Could try increasing number of iterations (maxit) or try different start points. Note: If multiple random start points are used, this warning does not likely affect result. 6: In cML_estimate_random(b_exp = b_exp_new, b_out = b_out_new, se_exp = se_exp, : May not converge to minimums with some given start points and maximum number of iteration, lead to Fisher Information matrices not positive definite. Could try increasing number of iterations (maxit) or try different start points. Note: If multiple random start points are used, this warning does not likely affect result. 7: In cML_estimate_random(b_exp = b_exp_new, b_out = b_out_new, se_exp = se_exp, : May not converge to minimums with some given start points and maximum number of iteration, lead to Fisher Information matrices not positive definite. Could try increasing number of iterations (maxit) or try different start points. Note: If multiple random start points are used, this warning does not likely affect result.

xue-hr commented 1 year ago

The problem is not about the sample size. Your b_X and se_X have length 27, b_Y and se_Y have length 33, so the lengths do not match. Let me know if you have other questions!

slayers0917 commented 1 year ago

The problem is not about the sample size. Your b_X and se_X have length 27, b_Y and se_Y have length 33, so the lengths do not match. Let me know if you have other questions!

Thanks for your comment. I have adjusted my data and now the length of them is 46 but I still have an error. This is my code and results. Thanks! b_X = c(-0.1321780, 0.1646830, 0.0951338, 0.3486850, 0.0664499, 0.0763852, 0.0885784, 0.1905630, 0.0676140, 0.1288300, 0.1274600, -0.1425600, -0.0797150, -0.0837310, 0.0878340, -0.0792600, 0.4353100, 0.0864660, 0.0885360, 0.1770700, 0.1518000, 0.0778000, -0.1720700, -0.0740220, 0.0842770, 0.0743310, 0.0803700, 0.1301600, -0.1004000, -0.1670000, 0.0990430, 0.3321500, -0.0828050, 0.0738550, 0.0857350, 0.1728500, -0.0892800, -0.0922090, 0.3954700, 0.0852910, 0.3844300, 0.2217300, -0.0977210, 0.1122400, -0.0889880, 0.0930740) b_Y = c( 0.02138100, 0.07243100, -0.00631340, -0.01989900, -0.03193100, 0.01282500, -0.03451200, 0.01869700, -0.05686100, 0.01321180, -0.02915210, 0.04066370, 0.02305420, -0.01597970, 0.01979280, 0.01210610, -0.05946350, 0.02537040, 0.00801136, 0.04137880, 0.05959110, 0.01951920, -0.01859930, 0.01649360, 0.03120020, 0.02291930, -0.03201080, -0.00786666, 0.06031620, 0.00776451, 0.02990580, 0.02650330, 0.01928390, 0.01723870, -0.01879940, -0.05146190, -0.01924190, -0.00919468, 0.06677980, -0.00393064, -0.01803790, 0.03063350, 0.01704600, -0.06199560, -0.01815520, -0.02880320) se_X = c( 0.0204596, 0.0296348, 0.0142143, 0.0392862, 0.0118358, 0.0122937, 0.0144533, 0.0120210, 0.0118783, 0.0229900, 0.0222050, 0.0248240, 0.0141120, 0.0140320, 0.0156960, 0.0139710, 0.0640520, 0.0141220, 0.0134960, 0.0239100, 0.0185410, 0.0139780, 0.0239860, 0.0133820, 0.0152260, 0.0129610, 0.0130810, 0.0235800, 0.0166670, 0.0217040, 0.0181030, 0.0485560, 0.0144950, 0.0130320, 0.0136820, 0.0240390, 0.0139590, 0.0166410, 0.0707560, 0.0155650, 0.0317020, 0.0306530, 0.0155610, 0.0201360, 0.0152930, 0.0135900) se_Y = c(0.0224130, 0.0562780, 0.0173840, 0.0588640, 0.0126270, 0.0145230, 0.0269480, 0.0130240, 0.0130570, 0.0185716, 0.0204428, 0.0376297, 0.0161222, 0.0125626, 0.0132335, 0.0128644, 0.1193040, 0.0122010, 0.0119079, 0.0213415, 0.0212976, 0.0133152, 0.0200634, 0.0120892, 0.0126352, 0.0122824, 0.0122325, 0.0274956, 0.0136155, 0.0201295, 0.0128692, 0.0483606, 0.0125509, 0.0121076, 0.0120516, 0.0214265, 0.0119852, 0.0160384, 0.0411795, 0.0143194, 0.0248530, 0.0222946, 0.0119042, 0.0162195, 0.0123827, 0.0122735) BiDirMRcML(b_X = b_X, b_Y =b_Y, se_X = se_X, se_Y = se_Y, n_X = 260000, n_Y = 700000, sig.cutoff = 0.05/2, num_pert = 100,random_start = 0, random.seed = 1)

Error in while ((abs(theta_old - theta) > 1e-07) & (ite_ind < maxit)) { : missing value where TRUE/FALSE needed In addition: Warning messages: 1: In min(b_out/b_exp) : no non-missing arguments to min; returning Inf 2: In max(b_out/b_exp) : no non-missing arguments to max; returning -Inf

xue-hr commented 1 year ago

Hi,

Sorry for the late reply, I am not quite familiar with the issue system on GitHub and just see your comment.

I tried the data you provided, the reason is: in the paper we adopted a IV screening process, i.e. when we test the causal effect from Y to X, we only use SNPs that have GREATER absolute correlations with Y than X as IVs. In your provided data, there is NO such SNP, i.e. all SNPs significant with Y are having greater absolute correlations with X than Y; thus after the screening no SNP left to infer Y to X.

Specifically in the code, if we have a closer look at the function BiDirMRcML, we can see it has four parts of results: the first two MRcML_XtoY_NoS, MRcML_YtoX_NoS, results without IV screening; the second two MRcML_XtoY_S, MRcML_YtoX_S, results with IV screening. The problem is the last one, MRcML_YtoX_S, there is no IV left.

Hope the late reply did not cause too much troubles in your research, please let me know if there are any other issues!

Best, Haoran