用R语言做多变量孟德尔随机化分析,用下面的代码提取暴露和结局共同的列时,显示:

combined_data <- merge(alcohol, smokeindex, by = "SNP") # Keep only common rows
combined_data <- merge(combined_data, migraine_Y, by = "SNP")
于是我换了一个代码,加了一个“all = TRUE”,conbied_data有数据了,但有缺失值

然后我继续做下一步:alcohol <- alcohol[alcohol$SNP %in% combined_data$SNP,]
smokeindex <- smokeindex[smokeindex$SNP %in% combined_data$SNP,]
migraine_y <- migraine_Y[migraine_Y$SNP %in% combined_data$SNP,]
发现这三个数据的行数仍没有一致,之后做到MRMV_IVW这步时,还是报错:错误于model.frame.default(formula = By ~ Bx - 1, weights = Byse^(-2), : 变量的长度不一样('Bx'),请问该怎么解决呢
#------将唯一SNP和第一个,第二个暴露因素合并------
alcohol<-merge(uni_snp,Alcohol,by="SNP")
smokeindex<-merge(uni_snp,Smokeindex,by="SNP")
#------将唯一SNP和结局合并------
migraine_Y<-merge(uni_snp,migraine,by="SNP")
# Assuming each dataset has a common column 'SNP' for identification
combined_data <- merge(alcohol, smokeindex, by = "SNP", all = TRUE) # Keep only common rows
combined_data <- merge(combined_data, migraine_Y, by = "SNP", all = TRUE)
alcohol <- alcohol[alcohol$SNP %in% combined_data$SNP,]
smokeindex <- smokeindex[smokeindex$SNP %in% combined_data$SNP,]
migraine_y <- migraine_Y[migraine_Y$SNP %in% combined_data$SNP,]
# 重新生成MRMVInputObject
MRMVInputObject <- mr_mvinput(bx = cbind(alcohol$BETA,smokeindex$BETA),
bxse = cbind(alcohol$SE,smokeindex$SE),
by = migraine_y$BETA,
byse = migraine_y$SE)
# 再次运行MRMV_IVW
MRMV_IVW <- mr_mvivw(MRMVInputObject,
model = "default",
correl = FALSE,
distribution = "normal",
alpha = 0.05)