- 最后登录
- 2014-6-18
- 注册时间
- 2009-3-1
- 威望
- 0
- 金钱
- 274
- 贡献
- 215
- 阅读权限
- 20
- 积分
- 489
- 日志
- 0
- 记录
- 0
- 帖子
- 56
- 主题
- 7
- 精华
- 0
- 好友
- 0
- 注册时间
- 2009-3-1
- 最后登录
- 2014-6-18
- 积分
- 489
- 精华
- 0
- 主题
- 7
- 帖子
- 56
|
我来分享一个计算simple slope effect和画图的SPSS macro (https://people.ok.ubc.ca/brioconn/simple/simple.html)。大家只要自行修改下面Macro中b1,b2,b3的名称就可以了。# P$ C. Y5 X: t
8 Z6 b) [' V% Z3 T$ _7 T- F*****************.
! ~* V5 C; {4 y+ [desc b1 b2/save.; `1 t5 b" q3 C/ L1 d }
compute idv = zb1.- X8 `( i" R3 p
compute mod = zb2.
* f2 P# F# j% Q# bcompute x = idv * mod./ F- p! H1 N$ c R* i
compute dv = b3./ n/ U9 B1 E9 H+ y/ H
9 M- L h6 K% e% [/ |" Dregression
$ ]5 X) [* S+ f6 a1 E# i1 } /matrix out ('filename')
% J- w2 m3 q/ t8 w8 e /var= idv mod x dv
* T4 [: q% p( u& x/ I' O /statistics=defaults zpp bcov
; i. a) h& T. O; x /dependent=dv! B5 B1 Z$ C$ F/ [, q7 E3 Q* T
/enter idv mod " D, Z+ r. Y0 A0 K! S. Q0 }" s
/test (x) .3 B* ~* M, `2 _0 D, C
% u9 q, ^. p7 n `/ U1 S. x
set mxloops=65.
0 q4 P/ j( Z& g( y7 U* ?matrix.' E, y1 R9 ~- p0 D1 N
0 I5 O) |6 D, }1 s* T2 u" b8 {
compute multiMOD = 1.0 .
, c6 b# R6 @- Gcompute multiIDV = 1.0 .( X( W7 Y: d+ g7 H# R
compute dichotom = 0 .0 E' R! C& J* E8 L" x4 R0 q2 C1 z
compute dichotLo = 1 .
4 k6 R g0 U0 o* P) mcompute dichotHi = 2 ., `% q$ A S( U) l& m2 n9 W# |7 s
mget /file='filename'.
9 v) X, l. c$ J8 m
9 J7 m; G, ^- U2 ^9 b5 J, E* Overall regression coeffs.
( k; c0 c9 d5 F- m4 h& Jcompute beta = inv(cr(1:3,1:3)) * cr(1:3,4) .
1 q& A- M0 s. ~- [) rcompute b = (sd(1,4) &/ sd(1,1:3)) &* t(beta) .. f+ t: o/ [0 z' H2 `" A
compute a = mn(1,4) - ( rsum ( mn(1,1:3) &* b ) ) .
j+ |& k) e9 M- e& d* @, L: Acompute r2all = t(beta) * cr(1:3,4) .
1 b( H, M: n# {; P/ Rcompute r2main = t(inv(cr(1:2,1:2))*cr(1:2,4))*cr(1:2,4).
i: H) x( q" Z& e7 E. W2 Q% i# Tcompute r2chXn = r2all - r2main.9 a7 \) L4 m; a2 p6 {
compute fsquare = (r2all - r2main) / (1 - r2all) .
* O. D9 o- L( y& T) x4 Y5 ^compute F = (r2all-r2main) / ((1-r2all)/(nc(1,1)-3-1)).. I% o. F* C% {. v; h+ p3 S0 I
compute dferror = nc(1,1) - 3 - 1.
* j4 \4 O& y: L$ O5 ^. N. Ucompute pF = 1 - fcdf(F,1,dferror) .' h e* Y6 }/ \# M) m9 H$ ^. H1 ]
2 M& o! a5 w8 m) }" z* x2 q
print {r2chXn,F,{1},dferror,fsquare,pF} /title="Coefficients for the Interaction"
* `- j6 R+ ?+ y- d( ` /clabels="Rsq. ch." "F" "df num." "df denom." "f-squared" "Sig. F".
8 h3 n1 F* R2 {print {t(b),beta} /title="Beta weights for the full equation:". P1 Z% a# `# C/ |! W2 h% v
/rlabels="idv" "mod" "Xn" /clabels="raw b" "std.beta" .
9 A" u7 Z7 H8 }; }9 Dprint a /title="The intercept is:" .
+ a$ W- R9 {) P- G! ], d
8 A+ n6 M2 E+ k8 \9 u
# Z5 _1 x& V2 ~$ a- _) v; U' I4 w" ?* simple slopes info .
6 V9 v& E( ^* z7 _compute modlo = mn(1,2) - (sd(1,2) * multiMOD) .
K+ ^( T# @& E. W7 Y; ]compute modmd = mn(1,2).0 | Y" E0 |( p2 m/ B1 Y t4 Q
compute modhi = mn(1,2) + (sd(1,2) * multiMOD) .
; W. a9 m9 ?" X/ t) J; E6 o& Rcompute slopes={(b(1,1)+(b(1,3)*modlo)) ;
+ {$ O. w" o- T, l" x (b(1,1)+(b(1,3)*modmd)) ; (b(1,1)+(b(1,3)*modhi)) }.! o. Y: B7 e5 {/ N, w* L
compute aslopes={ (b(1,2)*modlo+a) ; (b(1,2)*modmd+a) ; (b(1,2)*modhi+a) }.2 u4 g( L+ a. x3 |. \ F6 d
compute mse = (nc(1,1)/(nc(1,1)-3))*(sd(1,4)**2)*(1-r2all).+ v% K: t' k0 e9 m+ W! y
compute Sb=mse*inv((mdiag(sd(1,1:3))*cr(1:3,1:3)*mdiag(sd(1,1:3)))*(nc(1,1)-1)).
H0 e0 D# G4 L2 {9 ocompute SEslopes={ (sqrt ( {1,0,modlo} * Sb * t({1,0,modlo}) )) ;
& G7 N' u: D6 s& ~& v (sqrt ( {1,0,modmd} * Sb * t({1,0,modmd}) )) ;' i7 [0 f4 J1 { n6 ?$ c
(sqrt ( {1,0,modhi} * Sb * t({1,0,modhi}) )) }.
7 S" } T* _- ?6 @: P1 w) X( d* [compute tslopes = slopes &/ SEslopes .; V. ?; ^! v8 ~/ Q
compute df = { (nc(1,1)-3-1) ; (nc(1,1)-3-1) ; (nc(1,1)-3-1) }.
/ ~ `% w+ t& z2 ]" }0 d8 f" h' mcompute zslopes = slopes &* (sd(1,1)/sd(1,4)).8 o' f: S3 E. P
compute zSE = SEslopes &* (sd(1,1)/sd(1,4)) .' u" ^$ B$ [1 f0 Z; o Z) S3 e
compute dfs = nc(1,1)-3-1 .
6 ]; ]7 g" B& \2 w- b, J \compute pslopes = (1 - tcdf(abs(tslopes),dfs)) * 2./ V: ]; I8 A+ \
4 |0 g: [$ T, Q. M
* df & t values -- from Darlington p 516 & Howell 87 p 586 -- p = 05 two-tailed .2 _, }$ J5 m4 `$ i/ Z8 U0 S
compute dft={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,22,24,26,28,
X0 f" O0 l5 J' M1 f9 W/ o; m 30,32,34,36,38,40,43,46,49,52,56,60,65,70,75,80,85,90,95,100,110,120,130,
8 _* g6 M; c! N* A8 ]& m# r 150,175,200,250,300,400,500,600,700,800,900,1000,1000000000;. T2 ?& u' w% k
12.706,4.303,3.182,2.776,2.571,2.447,2.365,2.306,2.262,2.228,2.201,2.179,- G/ O& x- s9 E- P: |9 E+ W
2.160,2.145,2.131,2.120,2.110,2.101,2.093,2.086,2.074,2.064,2.056,2.048,
5 T( R7 Y" S. w( I$ h 2.042,2.037,2.032,2.028,2.024,2.021,2.017,2.013,2.010,2.007,2.003,2.000,4 |% _' O5 A1 n! W7 T# @0 T
1.997,1.994,1.992,1.990,1.988,1.987,1.985,1.984,1.982,1.980,1.978,1.976,
6 Q8 S; ~0 `& K6 L9 T) \& h 1.974,1.972,1.969,1.968,1.966,1.965,1.964,1.963,1.963,1.963,1.962,1.962 }.
5 i( [, e8 w' | F% y4 Vcompute tabledT = 0./ K; T* a, F0 l4 D
loop #a = 1 to 59 .8 [; _6 k" z% k' j/ G& Y/ v) X, c
do if (dfs ge dft(1,#a) and dfs < dft(1,#a+1) ).
) w5 C$ e6 i7 ~4 H* u# R+ r# E$ ocompute tabledT = dft(2,#a) .
2 _( p4 d$ o2 n+ P, Uend if.7 N3 R0 [! D1 R+ j' C# \
end loop if (tabledT > 0).
+ q. b, e3 k. H( J& W b+ X! Rcompute confidLo = (zslopes - (tabledT &* zSE)) .
' u+ h5 q) R$ r6 w6 O( Icompute confidHi = (zslopes + (tabledT &* zSE)) .
4 `' B" I2 S: Q5 w" j4 d C0 ~8 `' |, }9 j; e7 }. o7 r
print { aslopes , slopes , tslopes , df , pslopes} ' Z3 }# y) p" D! H& v A
/title="Simple Slope Coefficients for the DV on the IDV at 3"" W% G: c+ h9 [, k, b
+ " levels of the Moderator:" ! r9 C- h9 G& [3 _
/rlabels="Mod=low" "Mod=med" "Mod=high"0 n) K4 ^# g1 F3 M
/clabels="a" "raw b" "t-test" "df" "Sig. T".
# d* u% u, F4 D4 {$ L9 X Jprint { zslopes , zSE , confidLO, confidHI } 0 L5 G2 k& W }) G% j
/title="Standardized Simple Slopes & 95% Confidence Intervals: "* m2 s4 Q0 z+ O# C2 J; x" L5 u
/rlabels="Mod=low" "Mod=med" "Mod=high"
6 m4 J: j3 n& ]: h3 V /clabels="std. beta" "SE" "95% Low" "95% Hi".
& K- _* T* O: {1 d2 o' Sprint ((b(1,1)/b(1,3))*-1)/title="The simple slope for the DV on the IDV"
7 ~7 @0 k: r% A; y7 A. B+ " is zero (flat) at Moderator =".
9 K0 U/ L' C2 Wprint ((b(1,2)/b(1,3))*-1)/title="The simple regression lines at "
# E2 r }/ K; g3 x+ "Mod=high and Mod=low intersect at IDV =".
+ d; _1 f6 K; y' b
/ s+ f# O% Z7 l2 N' W4 {# E. `' Q' Q) k' b/ i6 L k i
* data for plot.7 E' `$ p% W, B% j
compute idvlo = mn(1,1) - (sd(1,1) * multiIDV).
; I8 e& o. G# Scompute idvhi = mn(1,1) + (sd(1,1) * multiIDV) .
+ |- B+ d: d" A5 a9 Q( i" r+ Xcompute idv = { idvlo; idvhi; idvlo; idvhi; idvlo; idvhi } .
$ L# c0 S+ j& a7 F1 e0 l$ xdo if (dichotom = 1).
" H+ W2 k+ h, w, u* q3 X& zcompute idv = { dichotLO;dichotHi; dichotLO;dichotHi; dichotLO;dichotHi }.! W! [5 ]& i* u3 {# e5 W0 b% w
end if.
, D, P, h5 ~/ a. Q" Gcompute moder = { modlo;modlo;modmd;modmd;modhi;modhi }.& a/ z' M" P+ \. i; ?; x
compute dv = (b(1,1)&*idv)+(b(1,2)&*moder)+(b(1,3)&*idv&*moder)+a.& C7 a( R% [) J2 Z2 o% E0 M
compute data = { idv , moder , dv }.
0 ]8 N# H: F$ ~/ e8 K. W6 i0 g4 ?( Z* P/ c4 w
print data /title="Data for simple slope plots:" /clabels="IV" "Moderator" "DV" .
) ]& l ?8 {3 R- G0 A' j
" [' e" N x" m8 i! p$ c3 isave data /outfile=* / var=zb1 zb2 b3.
u3 }; I" I+ M% D/ e5 t! ?1 G6 E
$ N* R0 r' A; ?end matrix.* P7 {% \6 j4 X- Y, d8 m7 d; w
# r4 X" l9 }7 }! I+ K5 U. `plot vsize=15 / hsize=50 / format=contour(3) / plot=b3 with zb1 by zb2.& W4 I O9 ^9 A$ H! v
graph / line = mean (b3) by b1 by b2.% ]) C/ n) x2 [, P" B
|
|