User:Timothee Flutre/Notebook/Postdoc/2011/06/28
From OpenWetWare
(Difference between revisions)
m (→Calculate OLS estimates with summary statistics for simple linear regression) 
(→Simple linear regression: add simulation with PVE and R code) 

Line 18:  Line 18:  
<math>y = X \theta + \epsilon</math> with <math>\epsilon \sim N_N(0,\sigma^2 I_N)</math> and <math>\theta^T = (\mu, \beta)</math>  <math>y = X \theta + \epsilon</math> with <math>\epsilon \sim N_N(0,\sigma^2 I_N)</math> and <math>\theta^T = (\mu, \beta)</math>  
  +  * '''Use only summary statistics''': most importantly, we want the following estimates: <math>\hat{\beta}</math>, <math>se(\hat{\beta})</math> (its standard error) and <math>\hat{\sigma}</math>. In the case where we don't have access to the original data (eg. because genotypes are confidential) but only to some summary statistics (see below), it is still possible to calculate the estimates.  
Here is the ordinaryleastsquare (OLS) estimator of <math>\theta</math>:  Here is the ordinaryleastsquare (OLS) estimator of <math>\theta</math>:  
Line 74:  Line 74:  
<math>V(\hat{\beta}) = \frac{\hat{\sigma}^2}{g^Tg  N\bar{g}^2}</math>  <math>V(\hat{\beta}) = \frac{\hat{\sigma}^2}{g^Tg  N\bar{g}^2}</math>  
+  
+  * '''Simulation with a given PVE''': when testing an inference model, the first step is usually to simulate data. However, how do we choose the parameters? In our case (linear regression: <math>y = \mu + \beta g + \epsilon</math>), it is frequent to fix the proportion of variance in <math>y</math> explained by <math>\beta g</math>:  
+  
+  <math>PVE = \frac{V(\beta g)}{V(y)} = \frac{V(\beta g)}{V(\beta g) + V(\epsilon)}</math> with <math>V(\beta g) = \frac{1}{N}\sum_{n=1}^N (\beta g_n  \bar{\beta g})^2</math> and <math>V(\epsilon) = \sigma^2</math>  
+  
+  This way, by also fixing <math>\beta</math>, it is easy to calculate the corresponding <math>\sigma</math>:  
+  
+  <math>\sigma = \sqrt{\frac{1}{N}\sum_{n=1}^N (\beta g_n  \bar{\beta g})^2 \frac{1  PVE}{PVE}}</math>  
+  
+  Here is some R code implementing this:  
+  
+  <nowiki>  
+  set.seed(1859)  
+  N < 100  
+  g < sample(x=0:2, size=N, replace=TRUE, prob=c(0.5, 0.3, 0.2)) # MAF=0.2  
+  mu < 5  
+  beta < 0.5  
+  pve < 0.8  
+  beta.g.bar < mean(beta * g)  
+  sigma < sqrt((1/N) * sum((beta * g  beta.g.bar)^2) * (1pve) / pve) # 0.778  
+  y < mu + beta * g + rnorm(n=N, mean=0, sd=sigma)  
+  plot(x=0, type="n", xlim=range(g), ylim=range(y),  
+  xlab="genotypes (allele dose)", ylab="phenotypes",  
+  main="Simple linear regression")  
+  for(i in unique(g))  
+  points(x=jitter(g[g == i]), y=y[g == i], col=i+1, pch=19)  
+  ols < lm(y ~ g)  
+  summary(ols) # muhat=5.01, betahat=0.46, R2=0.779  
+  abline(a=coefficients(ols)[1], b=coefficients(ols)[2])  
+  </nowiki>  
+  
<! ##### DO NOT edit below this line unless you know what you are doing. ##### >  <! ##### DO NOT edit below this line unless you know what you are doing. ##### > 
Revision as of 14:19, 19 June 2012
Project name  Main project page Next entry 
Simple linear regression
In matrix notation: y = Xθ + ε with ε˜N_{N}(0,σ^{2}I_{N}) and θ^{T} = (μ,β)
Here is the ordinaryleastsquare (OLS) estimator of θ:
Let's now define 4 summary statistics, very easy to compute:
This allows to obtain the estimate of the effect size only by having the summary statistics available:
The same works for the estimate of the standard deviation of the errors:
We can also benefit from this for the standard error of the parameters:
with and V(ε) = σ^{2} This way, by also fixing β, it is easy to calculate the corresponding σ:
Here is some R code implementing this: set.seed(1859) N < 100 g < sample(x=0:2, size=N, replace=TRUE, prob=c(0.5, 0.3, 0.2)) # MAF=0.2 mu < 5 beta < 0.5 pve < 0.8 beta.g.bar < mean(beta * g) sigma < sqrt((1/N) * sum((beta * g  beta.g.bar)^2) * (1pve) / pve) # 0.778 y < mu + beta * g + rnorm(n=N, mean=0, sd=sigma) plot(x=0, type="n", xlim=range(g), ylim=range(y), xlab="genotypes (allele dose)", ylab="phenotypes", main="Simple linear regression") for(i in unique(g)) points(x=jitter(g[g == i]), y=y[g == i], col=i+1, pch=19) ols < lm(y ~ g) summary(ols) # muhat=5.01, betahat=0.46, R2=0.779 abline(a=coefficients(ols)[1], b=coefficients(ols)[2])
