- 最后登录
- 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的名称就可以了。1 s% {% b1 h( @9 W5 Z5 B8 X
7 t% p1 `% p+ \& x
*****************.) G% k) M+ g: P6 @5 a2 ]
desc b1 b2/save.7 E n# z* Q9 y$ V' I' K
compute idv = zb1.% @! c- w6 N+ P" t6 q/ u. N
compute mod = zb2.
9 ^, ~) \% G# b) w! K1 X$ G5 bcompute x = idv * mod.' |, Y7 r" p4 F9 A6 X
compute dv = b3.
0 @7 J2 _( {; o% b. @+ E6 q8 ^: L3 w8 F' K
regression & G* u% ?( O- F
/matrix out ('filename')
( W, d7 h9 U: c! F7 q /var= idv mod x dv . C* T- H" h( k# A
/statistics=defaults zpp bcov
0 G6 W4 n; B7 h5 R' W. S /dependent=dv
4 D7 ?9 W5 A \" f# P& ?3 } /enter idv mod . P5 m' z: T; ]4 t6 G
/test (x) .' l+ W; ?) ~! r7 I- ^
: k/ Z- g0 m5 d6 ~
set mxloops=65.
: e, p; b0 L# {matrix.
$ g2 g' d" R) h+ i
, ?3 ~; a( F, N9 @compute multiMOD = 1.0 .
2 U. I9 i, D3 C) gcompute multiIDV = 1.0 .
7 W. J" T& N3 H0 Bcompute dichotom = 0 .$ V# h$ W1 }6 j# z) H. [
compute dichotLo = 1 .% d0 v; o. t6 O) L! `
compute dichotHi = 2 .
* d0 J- g0 y( {9 n0 mmget /file='filename'.9 Y0 j+ ]& N# Q$ S6 t
& D4 W; R7 Y9 X
* Overall regression coeffs.. P- C' u2 B& N$ b3 s$ x
compute beta = inv(cr(1:3,1:3)) * cr(1:3,4) .
" t6 S* g' z' P3 \, @9 v. C- Pcompute b = (sd(1,4) &/ sd(1,1:3)) &* t(beta) ." d: O7 Z+ F j4 x, V0 n U, W
compute a = mn(1,4) - ( rsum ( mn(1,1:3) &* b ) ) .
! e7 r9 h. `0 acompute r2all = t(beta) * cr(1:3,4) .- w' e0 L* r0 U, A2 x- ~' T* O
compute r2main = t(inv(cr(1:2,1:2))*cr(1:2,4))*cr(1:2,4).
7 b* r7 U$ R7 {+ bcompute r2chXn = r2all - r2main.1 C7 U1 T* ?3 [ d; O
compute fsquare = (r2all - r2main) / (1 - r2all) .9 `8 \1 m& u* |) r" e) p$ K2 \8 P1 f
compute F = (r2all-r2main) / ((1-r2all)/(nc(1,1)-3-1)).5 a- e2 b6 z. w# |
compute dferror = nc(1,1) - 3 - 1.
" _; g; t( H5 J9 Q! rcompute pF = 1 - fcdf(F,1,dferror) .
; f& ]3 F& ]+ \" C7 O9 E {: X2 v& Z8 ^9 x4 T' w, T
print {r2chXn,F,{1},dferror,fsquare,pF} /title="Coefficients for the Interaction"
) B+ g5 E: u6 g7 s4 N M: Z2 i /clabels="Rsq. ch." "F" "df num." "df denom." "f-squared" "Sig. F".
; _: L- r7 Z* a) vprint {t(b),beta} /title="Beta weights for the full equation:"# @1 W+ S2 B$ l3 G9 q* }
/rlabels="idv" "mod" "Xn" /clabels="raw b" "std.beta" .
4 t, { S! f. j; aprint a /title="The intercept is:" .3 X) n. G% d) W5 `
8 w$ |2 C0 | b; s: W& I' x) k) S7 Z% [! a
* simple slopes info ., g0 r- k K9 Y: u4 u
compute modlo = mn(1,2) - (sd(1,2) * multiMOD) .
' y+ W) i) v; d e% g( q8 Hcompute modmd = mn(1,2)./ \0 Z. @3 s: A. R' G# Z3 w0 e
compute modhi = mn(1,2) + (sd(1,2) * multiMOD) .7 i3 r G- m) D; A6 W( {! I1 c
compute slopes={(b(1,1)+(b(1,3)*modlo)) ;4 i: P* {# M- ?/ G" l
(b(1,1)+(b(1,3)*modmd)) ; (b(1,1)+(b(1,3)*modhi)) }.
' D+ R3 v) ?' i8 Y/ n0 jcompute aslopes={ (b(1,2)*modlo+a) ; (b(1,2)*modmd+a) ; (b(1,2)*modhi+a) }.+ K, y; M; H" W- E* P
compute mse = (nc(1,1)/(nc(1,1)-3))*(sd(1,4)**2)*(1-r2all).; |! m! C K" p( X+ i* z& A
compute Sb=mse*inv((mdiag(sd(1,1:3))*cr(1:3,1:3)*mdiag(sd(1,1:3)))*(nc(1,1)-1)).9 e+ ?, G, g& D! w( k! h. u
compute SEslopes={ (sqrt ( {1,0,modlo} * Sb * t({1,0,modlo}) )) ;, @5 ^( {/ C* x) e
(sqrt ( {1,0,modmd} * Sb * t({1,0,modmd}) )) ;- u5 J2 M/ U7 [9 o4 t& s9 \
(sqrt ( {1,0,modhi} * Sb * t({1,0,modhi}) )) }.
. q+ M* G' W' j9 q- V7 Bcompute tslopes = slopes &/ SEslopes .6 v; }2 [2 B& {, _- O$ k. H' _" o& c. z
compute df = { (nc(1,1)-3-1) ; (nc(1,1)-3-1) ; (nc(1,1)-3-1) }.# n. c+ h' Q4 m/ x, {! F% n5 _
compute zslopes = slopes &* (sd(1,1)/sd(1,4)).& E: ?7 ^# A! p1 Q! K4 O
compute zSE = SEslopes &* (sd(1,1)/sd(1,4)) .9 B1 `6 G: E/ Z& @
compute dfs = nc(1,1)-3-1 .
4 ~: e, N5 b8 O/ S+ _( scompute pslopes = (1 - tcdf(abs(tslopes),dfs)) * 2.: H: H% F" ~. b0 @
0 K9 w. V2 C; J& G& o. [: G- _1 T* df & t values -- from Darlington p 516 & Howell 87 p 586 -- p = 05 two-tailed .
% }. ?. x: 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,. {! x/ ?& ? `; q
30,32,34,36,38,40,43,46,49,52,56,60,65,70,75,80,85,90,95,100,110,120,130,2 j2 I1 s0 `6 C9 L
150,175,200,250,300,400,500,600,700,800,900,1000,1000000000;
# p1 g0 G7 q1 U0 q* I! Z+ s1 f3 [' D7 w 12.706,4.303,3.182,2.776,2.571,2.447,2.365,2.306,2.262,2.228,2.201,2.179,
7 n2 O: O, b- b# K7 k( | 2.160,2.145,2.131,2.120,2.110,2.101,2.093,2.086,2.074,2.064,2.056,2.048,. u- d5 T8 k6 ~) t# g$ i
2.042,2.037,2.032,2.028,2.024,2.021,2.017,2.013,2.010,2.007,2.003,2.000,1 |8 y0 `: f, V# R7 [, B, q l- y* d
1.997,1.994,1.992,1.990,1.988,1.987,1.985,1.984,1.982,1.980,1.978,1.976,
- f7 k2 g( C1 i3 B2 A6 E8 k 1.974,1.972,1.969,1.968,1.966,1.965,1.964,1.963,1.963,1.963,1.962,1.962 }.' `+ @) p f: b4 `( _) @. q0 u
compute tabledT = 0.
1 t7 A, y: ~4 Gloop #a = 1 to 59 .) n8 A0 b# n6 c5 j" R% I
do if (dfs ge dft(1,#a) and dfs < dft(1,#a+1) ).* r/ ?! T# u9 q: V
compute tabledT = dft(2,#a) .
' U- a8 j9 L* O7 ^! Q, k i3 y3 ?end if., H; f$ y9 z$ g" Q0 t3 f6 F8 s
end loop if (tabledT > 0).
1 z3 Z0 K: ]9 d- T7 ]compute confidLo = (zslopes - (tabledT &* zSE)) .
+ g# h1 X: h. W \6 a, f2 dcompute confidHi = (zslopes + (tabledT &* zSE)) .
% V: e* I+ i$ g* {' W; {, r+ u. c( F) Z/ o+ f0 _
print { aslopes , slopes , tslopes , df , pslopes}
' B0 X( J: U8 W% E/ n: U2 g: E- y /title="Simple Slope Coefficients for the DV on the IDV at 3": q% J# v0 V% R1 U1 w' n* ?% ]
+ " levels of the Moderator:" 0 m0 E. b! k) u8 {
/rlabels="Mod=low" "Mod=med" "Mod=high"
) o" {4 S: Q: E/ h$ }. l /clabels="a" "raw b" "t-test" "df" "Sig. T".: ?8 O: n+ F& ?
print { zslopes , zSE , confidLO, confidHI } " ` I) e5 u: x2 m& d' Z
/title="Standardized Simple Slopes & 95% Confidence Intervals: "
* k5 n/ L z6 t5 } /rlabels="Mod=low" "Mod=med" "Mod=high" ' T! X9 b; s0 ?- w2 G
/clabels="std. beta" "SE" "95% Low" "95% Hi".
: j6 {9 c; Y; ~: x$ E; O1 mprint ((b(1,1)/b(1,3))*-1)/title="The simple slope for the DV on the IDV"% Y' l- A) X. D
+ " is zero (flat) at Moderator =".
$ f5 {. c( z( A' A0 y7 [print ((b(1,2)/b(1,3))*-1)/title="The simple regression lines at "
5 N) a5 B) y& X1 L+ "Mod=high and Mod=low intersect at IDV =".2 h ~% y/ [! c1 @3 p5 R
7 n) l" M0 `3 Z) t
* S+ u; X/ T: `; i* data for plot.
1 f i: {+ z( b1 M7 ccompute idvlo = mn(1,1) - (sd(1,1) * multiIDV)." l* N5 N0 g8 z; V y7 T
compute idvhi = mn(1,1) + (sd(1,1) * multiIDV) .7 y5 ] c5 ?+ c' ] u4 e" `: y
compute idv = { idvlo; idvhi; idvlo; idvhi; idvlo; idvhi } .
" U8 D/ I ~. A$ edo if (dichotom = 1).( O$ T5 ~' p9 w4 Q7 }- K9 s0 H
compute idv = { dichotLO;dichotHi; dichotLO;dichotHi; dichotLO;dichotHi }.
) Q5 V% s& ~, [2 ^end if.
/ v* j/ p4 _! E$ K0 I- [, _compute moder = { modlo;modlo;modmd;modmd;modhi;modhi }.9 N. F4 ?) u7 z& J: _( x6 ^
compute dv = (b(1,1)&*idv)+(b(1,2)&*moder)+(b(1,3)&*idv&*moder)+a.
# J! p. o* H+ L( a% s2 Vcompute data = { idv , moder , dv }.
4 n. v/ V: I- u& ~" \1 g( B' k% C& {, Y9 w
print data /title="Data for simple slope plots:" /clabels="IV" "Moderator" "DV" .
. E, }! a" Z1 |# e( w4 Q& g; Q( l3 Y2 N
save data /outfile=* / var=zb1 zb2 b3.
1 t1 r a6 I- E+ v8 n' B2 C# [, N8 u0 i [! p
end matrix.1 K' |/ i- ]- C3 g# G
; J/ q4 J9 \0 r/ v5 I6 J- r
plot vsize=15 / hsize=50 / format=contour(3) / plot=b3 with zb1 by zb2.
0 m7 q0 O, C* Qgraph / line = mean (b3) by b1 by b2.
8 K0 w2 q5 m' p1 e+ g. Q |
|