-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
76 lines (56 loc) · 1.55 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# MRME
<!-- badges: start -->
<!-- badges: end -->
**MRME** is a Mendelian randomization (MR) method to estimate the causal effect by considering missing values in exposure variable.
## Installation
You can install the development version of MRME from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("AnqiWang2021/MRME")
```
## Example
This is a basic example which shows you how to solve a common problem:
```{r example}
library(MRME)
library(MASS)
N = 10000 #the sample size
K = 1 #the number of instrumental variables
n = 2
p = 0.3
#Sigma matrix
Sigma = matrix(c(0.58,0.35,0.35,0.58),2,2)
######parameter set
beta0 = 0.8
beta1 = 0.2
alpha0 = 0.13
alphav = 0.2
epsilon = mvrnorm(N,rep(0,2),Sigma)
#########genetic matrix
G<-rbinom(N*K,n,p)
G = as.matrix(G)
######## generate X and Y
X = alpha0 + as.matrix(G)%*%alphav + epsilon[,1]
Y = beta0 + beta1 *X +epsilon[,2]
########generate missing X, missing rate 30%
p_miss = exp(0.25 + 0.6*Y + G%*%rep(0.05,1))/(1 + exp(0.25 +0.6*Y + G%*%rep(0.05,1)))
maxit = 1000
tol = 1e-8
Sigma_start= matrix(c(0.4,0.2,0.2,0.4),2,2)
para_start = c(0.6,0.1,rep(0.05,2))
result = EM_miss(para_start,Sigma_start,G,Y,X,maxit,tol)
Sigma_est = result$Sigma
par_est = result$para
result_var = EM_miss_var(Sigma_est,par_est,G,Y,X)
```