Skip to content

Instantly share code, notes, and snippets.

@swuecho
Created March 6, 2012 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swuecho/1987551 to your computer and use it in GitHub Desktop.
Save swuecho/1987551 to your computer and use it in GitHub Desktop.
Meta analysis
###########data import###################
d<-read.csv('meta4digital.csv')
####################### fixed effect size#####################
df<-length(d$dIChR)-1
# 1/var of each study
W<-1/d$varIChR
# g of each study
Y<-d$dIChR
# sum var
M<-sum(W*Y)/sum(W)
Vm<-1/sum(W)
SEm<-sqrt(Vm)
Z<-M/SEm
p<-2*(1-pnorm(Z,0,1))
Q<-sum(W*(Y-M)^2)
p_Q<-pchisq(Q,df)
C<-sum(W)-sum(W^2)/sum(W)
# T_square
T_square<-(Q-(length(W)-1))/C
# tau
tau<-sqrt(T_square)
# I_square
I_square<-(Q-df)/Q*100
#####################random effect size###############
V_rand<-d$varIChR+T_square
W_rand<-1/V_rand
M_rand<-sum(W_rand*Y)/sum(W_rand)
Vm_rand<-1/sum(W_rand)
SEm_rand<-sqrt(Vm_rand)
Z_rand<-M_rand/SEm_rand
p_rand<-2*(1-pnorm(Z_rand,0,1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment