- 最后登录
- 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# p. E" h) \: P; C) F5 b
2 ]' C$ s/ |1 k0 _5 V8 ~*****************.# X* Z, Z0 V8 Y4 [
desc b1 b2/save.
/ i0 ~0 c( v5 }" B: ?4 ~compute idv = zb1." u- W5 U5 p0 l( h
compute mod = zb2. n3 p3 ^% n# K% y$ i, u0 Y2 M
compute x = idv * mod.
( k1 e6 f3 F$ ^+ Vcompute dv = b3.+ M% L D. V1 E4 v
7 {* E% l" f( J* M
regression
* S, h: Y0 _+ b. q /matrix out ('filename') 6 `2 N0 T7 C$ Y9 x
/var= idv mod x dv
( T; s2 X& W* y* M) X /statistics=defaults zpp bcov
; u0 W+ r0 ^# Q1 O& x4 i6 F /dependent=dv. X1 R p6 x: O0 J, G
/enter idv mod
1 S& M+ ^( p1 j0 Q+ b7 n4 Q /test (x) .- ?2 x- y* u2 J+ d% L! y7 G- V' o
+ Q) _" \+ G, x4 |5 Z2 U2 ]set mxloops=65.) I$ ` l, S0 z
matrix.! B, b# h/ ` E" m q8 V
3 ~. C9 }$ e* k5 j+ c: C4 }1 ^
compute multiMOD = 1.0 .; C0 V; \; b2 u" a
compute multiIDV = 1.0 .5 z; \, v4 n/ I! F
compute dichotom = 0 .
5 E! G+ Y; V( t2 Acompute dichotLo = 1 ., K3 t* B8 Y( \' }5 N' e6 M
compute dichotHi = 2 ./ k$ ^) H2 r- _5 N: q
mget /file='filename'.
; M& }! Q$ Z! j4 Q/ I( v) J
4 @8 q5 Q/ D7 d$ r* Overall regression coeffs.
% C+ X( R$ C/ o; n" u4 b' Vcompute beta = inv(cr(1:3,1:3)) * cr(1:3,4) .) G" U, W+ N) ^5 i
compute b = (sd(1,4) &/ sd(1,1:3)) &* t(beta) .
' H- N( r6 K/ ~- i; Scompute a = mn(1,4) - ( rsum ( mn(1,1:3) &* b ) ) .& `3 o; e" g% u+ K& |: z* i' @3 Q
compute r2all = t(beta) * cr(1:3,4) .
. _/ w( m$ v! [. ^: Pcompute r2main = t(inv(cr(1:2,1:2))*cr(1:2,4))*cr(1:2,4).
$ ~8 T, ^2 F7 l) H( g. T# Ncompute r2chXn = r2all - r2main., y v6 D) b3 c7 ?, w, ]
compute fsquare = (r2all - r2main) / (1 - r2all) .
' g4 S8 l# z( Q& P2 ocompute F = (r2all-r2main) / ((1-r2all)/(nc(1,1)-3-1))., J8 x5 v: \# N3 ]& ^" j( n/ x
compute dferror = nc(1,1) - 3 - 1.
- g* Q5 N9 H6 J% N8 g6 T2 H/ R; M9 zcompute pF = 1 - fcdf(F,1,dferror) .
2 @% b1 _" K5 ?3 [ I# m# k2 x: f! l: c: {% L
print {r2chXn,F,{1},dferror,fsquare,pF} /title="Coefficients for the Interaction"
; l; L; e! F0 Q; ~4 g4 o; J. u /clabels="Rsq. ch." "F" "df num." "df denom." "f-squared" "Sig. F". `( N+ ?9 o* d, q- d0 d' j; G$ I
print {t(b),beta} /title="Beta weights for the full equation:"4 X) K& T5 v# |: N/ w; Q/ I1 w
/rlabels="idv" "mod" "Xn" /clabels="raw b" "std.beta" .8 z* ?/ ]' i/ N0 I, ~
print a /title="The intercept is:" .' ~! K- Q% a, t* h* b4 K
. b- G& `# v+ k" w. n9 @1 E
/ S4 |5 i# Z% L5 g6 P8 Q6 `* simple slopes info .
3 r. U/ p: D/ B+ a( H) l7 xcompute modlo = mn(1,2) - (sd(1,2) * multiMOD) .
W; Q2 e! c+ @+ Xcompute modmd = mn(1,2).8 f' H" N$ i2 X Z
compute modhi = mn(1,2) + (sd(1,2) * multiMOD) .7 k- u* z9 n8 _
compute slopes={(b(1,1)+(b(1,3)*modlo)) ;
2 e( |) q4 K/ u4 Q# @+ H. s' ? (b(1,1)+(b(1,3)*modmd)) ; (b(1,1)+(b(1,3)*modhi)) }.9 z' k' l) q& R. k |/ W" ~
compute aslopes={ (b(1,2)*modlo+a) ; (b(1,2)*modmd+a) ; (b(1,2)*modhi+a) }.1 `5 s c T% m0 F+ I
compute mse = (nc(1,1)/(nc(1,1)-3))*(sd(1,4)**2)*(1-r2all).
: t0 F: z5 k4 R' @0 B- gcompute Sb=mse*inv((mdiag(sd(1,1:3))*cr(1:3,1:3)*mdiag(sd(1,1:3)))*(nc(1,1)-1)).
- b3 m) c- u% Wcompute SEslopes={ (sqrt ( {1,0,modlo} * Sb * t({1,0,modlo}) )) ;1 x7 B% ?) J- ^3 I4 U% F
(sqrt ( {1,0,modmd} * Sb * t({1,0,modmd}) )) ;- M" b" T0 J X6 R: h! H5 C6 r
(sqrt ( {1,0,modhi} * Sb * t({1,0,modhi}) )) }.! {3 y$ e5 u+ B
compute tslopes = slopes &/ SEslopes .
; r$ Y/ I( `" @ J! L# X* kcompute df = { (nc(1,1)-3-1) ; (nc(1,1)-3-1) ; (nc(1,1)-3-1) }.
! q* e$ |- I. ~) U- Dcompute zslopes = slopes &* (sd(1,1)/sd(1,4)).. F0 F w- [# w
compute zSE = SEslopes &* (sd(1,1)/sd(1,4)) .
; X( r. _/ J& p8 |# d( d# L6 ~compute dfs = nc(1,1)-3-1 .5 [4 r' J3 D( t
compute pslopes = (1 - tcdf(abs(tslopes),dfs)) * 2.3 f$ W1 a1 c( L4 @
( S1 {, l( {2 s. ]
* df & t values -- from Darlington p 516 & Howell 87 p 586 -- p = 05 two-tailed .! Z9 v5 m4 f" d9 n
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, A Y; t3 f- X, K+ {/ Z
30,32,34,36,38,40,43,46,49,52,56,60,65,70,75,80,85,90,95,100,110,120,130,* o* m9 h& M4 M* X# M
150,175,200,250,300,400,500,600,700,800,900,1000,1000000000;
5 n& R% _. G5 P- T) X; p 12.706,4.303,3.182,2.776,2.571,2.447,2.365,2.306,2.262,2.228,2.201,2.179,6 q3 R: ?: W/ [ A" H$ t- m
2.160,2.145,2.131,2.120,2.110,2.101,2.093,2.086,2.074,2.064,2.056,2.048,9 h) n. j4 l6 F
2.042,2.037,2.032,2.028,2.024,2.021,2.017,2.013,2.010,2.007,2.003,2.000,& ~: ~( m' V; V9 W6 E( n/ l. v
1.997,1.994,1.992,1.990,1.988,1.987,1.985,1.984,1.982,1.980,1.978,1.976,
$ t2 z ^! R* t) u0 S. b0 N9 } 1.974,1.972,1.969,1.968,1.966,1.965,1.964,1.963,1.963,1.963,1.962,1.962 }.% q3 @1 Y" t2 K- N; _ b+ a
compute tabledT = 0.
( o/ t* H+ H E; J) {loop #a = 1 to 59 .0 r- L7 @8 N3 h1 r8 I ]
do if (dfs ge dft(1,#a) and dfs < dft(1,#a+1) ).
3 E* `! a1 f' {6 U. _/ o8 q* Gcompute tabledT = dft(2,#a) .
: x. m: L1 F. J' l& d& Q& R6 k: j( \end if.0 F; r1 R9 p7 M0 H
end loop if (tabledT > 0).
, S# X7 U! {' z, J# Gcompute confidLo = (zslopes - (tabledT &* zSE)) .6 |' N! X' ^* D8 V
compute confidHi = (zslopes + (tabledT &* zSE)) .
, j5 n$ I' F8 v, q
+ ^+ g7 R; @8 C, x' {print { aslopes , slopes , tslopes , df , pslopes} ( t) B/ l, A! X* r
/title="Simple Slope Coefficients for the DV on the IDV at 3"
) J! c7 r I5 H/ g* P; T% ^+ " levels of the Moderator:"
0 x4 X/ o# s6 K /rlabels="Mod=low" "Mod=med" "Mod=high"
6 B: \" ], m4 B /clabels="a" "raw b" "t-test" "df" "Sig. T"." F! b( U1 u- i
print { zslopes , zSE , confidLO, confidHI } & i7 Z# a# P+ X! x: ~# z* _2 F
/title="Standardized Simple Slopes & 95% Confidence Intervals: "" A0 A$ s( a( d( v9 U3 ^) I9 E9 ~
/rlabels="Mod=low" "Mod=med" "Mod=high" 6 T( K* E2 v$ |$ Z
/clabels="std. beta" "SE" "95% Low" "95% Hi".
- b' F( H% B: Gprint ((b(1,1)/b(1,3))*-1)/title="The simple slope for the DV on the IDV"
3 ~! k4 T' _, q; o% W) T! z+ " is zero (flat) at Moderator =".% }2 e, f/ g" D6 D' V5 c, h
print ((b(1,2)/b(1,3))*-1)/title="The simple regression lines at "
; q8 w5 R' N5 ]- y: M4 z+ "Mod=high and Mod=low intersect at IDV =".& O) G7 C% O) d) k
* n# y3 J- m1 W* y
/ V0 [8 r, a* ?7 a
* data for plot.
9 h3 M4 t" q4 Q2 }' N' x2 D' s. h3 Pcompute idvlo = mn(1,1) - (sd(1,1) * multiIDV).
9 g1 H* ?9 ^/ ^3 ^. K2 y( L' Mcompute idvhi = mn(1,1) + (sd(1,1) * multiIDV) .
0 X+ |2 V+ R$ jcompute idv = { idvlo; idvhi; idvlo; idvhi; idvlo; idvhi } .7 t2 f( Y' u7 z/ W: @ m1 `2 r& z" b
do if (dichotom = 1).
+ S4 n9 [% r5 m( ~; d6 Fcompute idv = { dichotLO;dichotHi; dichotLO;dichotHi; dichotLO;dichotHi }.% i( Y! u/ ~1 k
end if.
6 a- i0 i* a# K3 w5 [compute moder = { modlo;modlo;modmd;modmd;modhi;modhi }.
7 n, U( t& ~6 D3 V$ _9 A Ocompute dv = (b(1,1)&*idv)+(b(1,2)&*moder)+(b(1,3)&*idv&*moder)+a.
% K6 S" o$ ~' o" W( Gcompute data = { idv , moder , dv }.4 |0 T! \& C1 z
4 O G4 n2 {0 ^* ]2 o8 M0 J& K
print data /title="Data for simple slope plots:" /clabels="IV" "Moderator" "DV" .
3 y* s; f' J" g% M! i4 {6 X1 D1 ~* V& K
save data /outfile=* / var=zb1 zb2 b3.
, j6 L1 z2 F- C. h, V; G" L9 _4 d6 g5 ]* G! P
end matrix.
$ g$ s& d7 d0 m8 y( G, t* ]& [8 }* ^
plot vsize=15 / hsize=50 / format=contour(3) / plot=b3 with zb1 by zb2.
# {7 H- J" B% W5 n3 n# |graph / line = mean (b3) by b1 by b2.
9 i. r/ {. K7 G6 B% S; [ |
|