* Encoding: UTF-8.
* SPSS Program for Fixed and Random-Effects Analysis.
* This is a syntax file (teach_RE.sps) that includes the data.
* Open this file as a syntax file, and it will create and save a SPSS data file (teacher.sav) when it runs.
*To use this program with your own data or another data file, simply replace the data list code
that precedes the ===== line below with this line .
* get file ='your file name.sav' .
Data List list records=1
/ study N_E N_C T weeks weekcat V.
Begin Data
1 79 339 0.03 2 2 .015625
2 60 198 0.12 21 3 .021609
3 72 72 -0.14 19 3 .027889
4 11 22 1.18 0 0 .139129
5 11 22 0.26 0 0 .136161
6 129 348 -0.06 3 3 .010609
7 110 636 -0.02 17 3 .010609
8 26 99 -0.32 24 3 .048400
9 75 74 0.27 0 0 .026896
10 32 32 0.80 1 1 .063001
11 22 22 0.54 0 0 .091204
12 43 38 0.18 0 0 .049729
13 24 24 -0.02 1 1 .083521
14 19 32 0.23 2 2 .084100
15 80 79 -0.18 17 3 .025281
16 72 72 -0.06 5 3 .027889
17 65 255 0.30 1 1 .019321
18 233 224 0.07 2 2 .008836
19 65 67 -0.07 7 3 .030276
End Data.
format study N_E N_C weeks weekcat (f8.0).
*=========================================== .
COMPUTE n = n_e + n_c .
EXECUTE .
* The next four lines should be unstarred if you need to unbias the effect sizes.
* COMPUTE j = 1-(3/(4*(n - 2)-1)) .
* EXECUTE .
* COMPUTE t = t*j .
* EXECUTE .
* Here is the formula for calculating the individual variances v but we do not use it here
because V is read in.
* These are used in study-based confidence intervals, as well as in future WLS analyses.
* COMPUTE v = (n/(n_e * n_c)) + t**2/(2*n) .
* EXECUTE .
* Next we get limits for confidence intervals based on the within-study variance V.
COMPUTE llim = t- 1.96*sqrt(v) .
EXECUTE .
COMPUTE ulim = t+1.96*sqrt(v) .
EXECUTE .
* w is the inverse variance weight, used in many analyses.
COMPUTE w = 1/v .
EXECUTE .
* This gives us descriptive statistics for sample sizes and the outcome (here it is t).
* Also we get the mean of the variances (v) and the variance of the outcome,
for use in random-effects analysis.
DESCRIPTIVES
VARIABLES=n_e n_c n t v
/STATISTICS=MEAN VARIANCE SUM MIN MAX .
* We get the hi-low charts for fixed-effects confidence intervals.
GRAPH
/HILO(SIMPLE)=VALUE( ulim llim t ) BY study .
* Next, we compute components of the fixed-effects weighted mean, its SE,
and the homogeneity statistic Q, as well as components of the random-effects
weighted mean, its SE, and the homogeneity statistic Q (which we do not use).
COMPUTE WT = W*T.
COMPUTE WTT= W*T*T.
COMPUTE TT= T*T.
COMPUTE ww= w*w.
EXECUTE.
* Now that we've computed these useful variables we can save the new data set.
* If we use the asterisk in place of the file name, it will resave using our original file name.
SAVE OUTFILE='c:\spss\teacher.sav'
/COMPRESSED.
* The matrix procedures below calculate statistics such as Q,
the mean effect size (T_DOT) and its standard error,
and confidence limits for the mean.
matrix.
get tv /variables = t.
get v /variables = v.
get w /variables = w.
get wt /variables = wt.
get wtt /variables = wtt.
get ww /variables = ww.
* Unstar the next line to see the effect size vector .
*print tv .
* Here we sum the terms of the Q test, mean etc .
compute sw = csum(w).
compute swt = csum(wt).
compute swtt = csum(wtt).
compute sww = csum(ww).
*Next we get the mean t and v values .
compute k = nrow(w).
compute sumt = csum(tv).
compute sumv = csum(v).
compute vbar = sumv/k.
compute tbar = sumt/k.
*Here we compute Q and several indices of heterogeneity .
compute Q = swtt - swt**2/sw.
compute DF = k - 1.
compute P = 1 - chicdf(Q,DF).
compute birge = q/df .
compute I2 = (q-df)/q .
* Next we get the two variance component estimators - we use the larger of the two in the analyses.. here it will be SVAR .
compute tdev = tv - tbar .
compute s2 =cssq(tdev)/(k-1) .
compute svar = s2-vbar .
do if svar le 0 .
compute svar = 0.
end if.
compute revar = svar .
compute c = sw- (sww/sw) .
compute qvar = (q-df)/c .
do if qvar le 0 .
compute qvar=0.
end if.
* This sets REvar to the larger of svar and qvar.
do if qvar GT svar .
compute revar = qvar .
end if.
print Q /Title "Fixed-effects Homogeneity Test (Q)" /format=f8.4.
print P /Title "P-value for Homogeneity test (P)" /format=f8.4.
print birge /Title " Birge's ratio, ratio of Q/(k-1)" /format=f8.4.
Print I2 /Title " I-squared, ratio [Q-(k-1)]/Q" /format=f8.4.
print qvar /Title "Variance Component based on Homogeneity Test (QVAR)" /format=f8.4.
print svar /Title "Variance Component based on S^2 and v-bar (SVAR)" /format=f8.4.
*This adds the larger of the variances to v .
compute vstar = v+revar.
compute wstar = 1/vstar.
compute wtstar = tv/vstar.
compute wttstar = T(tv)*wtstar .
compute swre = csum(wstar).
compute swtre = csum(wtstar).
compute swttre = csum(wttstar).
compute QRE = swttre - swtre**2/swre.
compute P = 1 - chicdf(QRE,DF).
compute T_DOT = swtre/swre.
compute V_T_DOT = 1/swre.
compute SE_TDOT = SQRT(1/swre).
compute L_T_DOT = T_DOT - 1.96*SE_TDOT.
compute U_T_DOT = T_DOT + 1.96*SE_TDOT.
compute resids = tv - T_DOT.
compute zresids = resids/sqrt(v).
* We print the results for analysis of all effects.
print QRE /Title "Random-effects value of Q [DON'T USE AS TEST!!!]" /format=f8.4.
print P /Title "P-value for Homogeneity test (P) [Only for instructional purposes!!!]" /format=f8.4.
print L_T_DOT /Title "RE Lower Conf Limit for T_Dot (L_T_DOT)" /format=f8.4.
print T_DOT /Title "Weighted random-effects average of effect size (T_DOT)" /format=f8.4.
print U_T_DOT /Title "RE Upper Conf Limit for T_Dot (U_T_DOT)" /format=f8.4.
print V_T_DOT /Title "RE Variance of T_Dot (V_T_DOT)" /format=f8.4.
print SE_TDOT /Title "RE Standard error of T_Dot (SE_TDOT)" /format=f8.4.
print k /Title "Number of studies" /format=f8.0.
print {resids,zresids} /Title "Residuals" /clabels="resids","zresids" /format=f8.4.
*We will save the new variances and weights to a data file .
compute vw = {vstar, wstar, resids, zresids} .
Save vw /OUTFILE=* /variables = vstar wstar resids zresids.
end matrix.
MATCH FILES /FILE='c:\spss\teacher.sav'
/FILE=*.
execute.
* Next we get limits for confidence intervals based on the new random-effects within-study variance vstar.
* These random-effects intervals will always be at least as wide as the original confidence intervals.
COMPUTE llimre = t- 1.96*sqrt(vstar) .
COMPUTE ulimre = t+1.96*sqrt(vstar) .
EXECUTE .
GRAPH
/HILO(SIMPLE)=VALUE( ulimre llimre t ) BY study .
* Summarize can be used to print out the data and to compare the
fixed-effects and random-effects components.
SUMMARIZE
/TABLES= N_E N_C T V llimre LLIM ULIM ulimre W wstar
/FORMAT=VALIDLIST NOCASENUM TOTAL LIMIT=100
/TITLE='Case Summaries' /FOOTNOTE ''
/MISSING=VARIABLE
/CELLS=COUNT MEAN VARIANCE SUM.