MRCIEU / TwoSampleMR

R package for performing 2-sample MR using MR-Base database
https://mrcieu.github.io/TwoSampleMR
Other
436 stars 177 forks source link

weird F statistics with r2 calculated by get_r_from_bsen() #434

Open MOKA1066 opened 1 year ago

MOKA1066 commented 1 year ago

library(TwoSampleMR)

exposure data

exp_dep1 <- extract_instruments(outcomes = 'ieu-b-4877', p1 = 5e-08)

calculate r

b <- exp_dep1['beta.exposure'] se <- exp_dep1['se.exposure'] n <- exp_dep1['samplesize.exposure']

r <- get_r_from_bsen(b,se,n)

calculate F statistics

f <- (n-k-1)*r^2/k/(1-r^2)

results:

f samplesize.exposure 1 0.7945091 2 0.4956253 3 0.3762885 4 0.4192938 5 0.5676587 6 0.3795136 7 0.4106922 8 0.3300601 9 0.3300611 10 0.6031393

Could anyone help me find where I was wrong?

WangYY-666 commented 2 months ago

hello, I am also learn this F value to calculate. And I think you could turn "r <- get_r_from_bsen(b,se,n)" to "r2<-^". (https://rdrr.io/github/MRCIEU/TwoSampleMR/man/get_r_from_bsen.html) Then you let R2 to the formation "f <- (n-k-1)r^2/k/(1-r^2)"or test"F=(N-2)R2/(1-R2)"

I tried your data: outcomes = 'ieu-b-4877'

r2<-get_r_from_bsen(b,se,n) f=(N-2)*r2/(1-r2)

expo_data$F_value [1] 6912.719 4741.291 5833.335 4761.718 6014.564 4496.261 [7] 4431.136 6407.896 4782.075 8176.970 6195.895 4815.774 [13] 5399.528 5326.950 4438.407 4651.769 4707.066 4637.830 [19] 4754.923 5582.836 4503.455 4644.811 6111.189 5459.313 [25] 4467.431 4935.294 4707.068 6263.854 5652.209 9725.027 [31] 4532.070 4637.836 6583.642 4467.432 4727.626 4452.945

Hope this answer can help you!