- 最后登录
- 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的名称就可以了。 d* b$ Y" I Z
S8 ^% A6 _: e! M*****************.
9 R3 K; Q# q! [desc b1 b2/save.! X3 J, M# ]- x8 ~# @, c
compute idv = zb1.( |( j) o( v4 L7 D7 l
compute mod = zb2.
# P+ }5 i& V9 ncompute x = idv * mod.1 X9 x2 g4 j( P$ E* W0 Y7 k
compute dv = b3.
, r* A. Y; ^7 T& {' @: O& `) g) W+ l! C& z; M( o
regression
; P# j/ N# q- y* u, k [ /matrix out ('filename') ' S/ W( b' Z% ~2 | X
/var= idv mod x dv
3 {/ G4 v$ u& x2 `2 K- x4 C% H /statistics=defaults zpp bcov 8 K3 C; a$ M' ^- Z
/dependent=dv0 }5 e" f" C2 I/ D, ?6 }
/enter idv mod ( A/ A( b# Y5 Q2 u6 `( ]0 I
/test (x) .
: [4 T) e+ G) F5 V8 S9 V9 l% W- p% t3 j1 J3 |1 S+ l
set mxloops=65.' w% e; o* U$ x! u. n
matrix.
& l/ S, R4 Y# f& h$ t G$ t/ [( E' ]5 M1 N( n8 L ^6 R' B
compute multiMOD = 1.0 .7 J. I7 L/ y( ? Y" @9 b) q
compute multiIDV = 1.0 .3 ~! `% E$ {, N9 K! J9 G/ s! i
compute dichotom = 0 .2 M) a O; P# d5 a3 _, U# y, Y3 |$ \
compute dichotLo = 1 .
4 O# X0 G) S: y' C3 ncompute dichotHi = 2 .! U/ I+ E, M* v- g) G: a. X* U$ P
mget /file='filename'.
/ Y3 d8 V: @% i1 D g1 g; ~8 I" E3 @% [
* Overall regression coeffs.
~% ^% k) s X) w8 Fcompute beta = inv(cr(1:3,1:3)) * cr(1:3,4) ./ V: L5 N/ u- d' K% h1 w
compute b = (sd(1,4) &/ sd(1,1:3)) &* t(beta) .
, U: Y8 F. a- `+ I) u( }9 ?compute a = mn(1,4) - ( rsum ( mn(1,1:3) &* b ) ) .0 {& M7 R0 G! o) r
compute r2all = t(beta) * cr(1:3,4) .8 |; D% e$ P/ |8 |
compute r2main = t(inv(cr(1:2,1:2))*cr(1:2,4))*cr(1:2,4).
2 I+ f* b/ k" d+ acompute r2chXn = r2all - r2main.
+ {1 `- N3 O$ }, q `compute fsquare = (r2all - r2main) / (1 - r2all) .+ J% J6 j' `' C- ?) `2 Y8 I* j0 W
compute F = (r2all-r2main) / ((1-r2all)/(nc(1,1)-3-1)).0 ~) O! V. g& `; `: f! `$ u
compute dferror = nc(1,1) - 3 - 1.! k2 P+ x @) F2 p
compute pF = 1 - fcdf(F,1,dferror) .
. C1 S, `/ o+ p2 T- r1 y4 n
& U1 ~* w% O1 Dprint {r2chXn,F,{1},dferror,fsquare,pF} /title="Coefficients for the Interaction"* m9 U# \7 ?+ |6 `4 C" H2 T0 c
/clabels="Rsq. ch." "F" "df num." "df denom." "f-squared" "Sig. F".
% h1 G. F5 c9 _8 B8 }print {t(b),beta} /title="Beta weights for the full equation:"8 h' p) J" r8 H1 y
/rlabels="idv" "mod" "Xn" /clabels="raw b" "std.beta" .
- E9 O1 _4 G" l3 K2 b) Oprint a /title="The intercept is:" .
! S1 U& a0 b/ p4 C& j* G! h. h
9 Q0 H! r9 D, J2 @* simple slopes info .8 H0 S- T9 f3 _" H4 `
compute modlo = mn(1,2) - (sd(1,2) * multiMOD) .
2 f6 q1 n6 J& S7 b0 _compute modmd = mn(1,2).- F! \1 b9 a: f
compute modhi = mn(1,2) + (sd(1,2) * multiMOD) .$ u, R; ]; O- o0 Q; o) r
compute slopes={(b(1,1)+(b(1,3)*modlo)) ;+ B! Q/ R& r3 t! c
(b(1,1)+(b(1,3)*modmd)) ; (b(1,1)+(b(1,3)*modhi)) }.( c+ X7 s% \. j
compute aslopes={ (b(1,2)*modlo+a) ; (b(1,2)*modmd+a) ; (b(1,2)*modhi+a) }.0 ~; A7 ]- j _0 e9 g# v! v0 h
compute mse = (nc(1,1)/(nc(1,1)-3))*(sd(1,4)**2)*(1-r2all).7 A% q+ n' [4 |2 ?6 n
compute Sb=mse*inv((mdiag(sd(1,1:3))*cr(1:3,1:3)*mdiag(sd(1,1:3)))*(nc(1,1)-1)).
* T, G; r3 i8 Y: A0 d4 Zcompute SEslopes={ (sqrt ( {1,0,modlo} * Sb * t({1,0,modlo}) )) ;8 W: l/ c" @7 M4 x' g: P
(sqrt ( {1,0,modmd} * Sb * t({1,0,modmd}) )) ;
, W$ y" u' J( ^6 H& t$ C (sqrt ( {1,0,modhi} * Sb * t({1,0,modhi}) )) }.# x4 k0 V( w$ E, i
compute tslopes = slopes &/ SEslopes .
# D2 H1 U6 P# l& W2 {4 r" d3 \compute df = { (nc(1,1)-3-1) ; (nc(1,1)-3-1) ; (nc(1,1)-3-1) }.0 F7 G6 X# ^1 x2 a6 W" Q
compute zslopes = slopes &* (sd(1,1)/sd(1,4)).
: w. D* ~, K# O" a- gcompute zSE = SEslopes &* (sd(1,1)/sd(1,4)) .) Y, }/ R/ w3 t6 {' f( T$ U
compute dfs = nc(1,1)-3-1 .: B; l: s+ G6 \% P! Z5 `
compute pslopes = (1 - tcdf(abs(tslopes),dfs)) * 2.: _& R8 h9 F8 y7 r, P
. m, W W5 \) m* [ J* df & t values -- from Darlington p 516 & Howell 87 p 586 -- p = 05 two-tailed . l! y0 x& B! z4 {6 J. S/ L
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,
2 q* D5 B( E, }" H! T 30,32,34,36,38,40,43,46,49,52,56,60,65,70,75,80,85,90,95,100,110,120,130,
* K/ a# t7 X: X 150,175,200,250,300,400,500,600,700,800,900,1000,1000000000;
* b" j, ` ~7 d6 i 12.706,4.303,3.182,2.776,2.571,2.447,2.365,2.306,2.262,2.228,2.201,2.179,8 T8 h% ?5 R. B( J5 U- X: B
2.160,2.145,2.131,2.120,2.110,2.101,2.093,2.086,2.074,2.064,2.056,2.048,
8 o, u1 ?3 F- 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,
! L. o7 R5 K& ^, G0 j, W 1.997,1.994,1.992,1.990,1.988,1.987,1.985,1.984,1.982,1.980,1.978,1.976,3 F; o) ?* S% W1 r; T' f
1.974,1.972,1.969,1.968,1.966,1.965,1.964,1.963,1.963,1.963,1.962,1.962 }.4 I* a* u7 ?: r5 H* w* A
compute tabledT = 0.
9 t4 Y/ h& A4 D; R6 Lloop #a = 1 to 59 .
" K* e% |5 ?7 ~% z+ H& M4 \% rdo if (dfs ge dft(1,#a) and dfs < dft(1,#a+1) ).
+ ~: n$ M9 q4 M4 Y9 U4 O. Scompute tabledT = dft(2,#a) .
& y6 k3 L# ?5 g+ M* \* ?9 aend if.3 ?# q: W6 d1 s( ^6 n
end loop if (tabledT > 0).
( X# m5 |' k! Z1 g4 hcompute confidLo = (zslopes - (tabledT &* zSE)) .+ x0 Z2 N+ L( L0 U" T
compute confidHi = (zslopes + (tabledT &* zSE)) .: E& w" c, j/ o) A
# ^- c$ ~# Z4 k* \ ~5 D( V
print { aslopes , slopes , tslopes , df , pslopes} : S9 r. n9 e- Q4 V6 z+ f$ E; n
/title="Simple Slope Coefficients for the DV on the IDV at 3"
. B1 h- g$ p$ }& x& `/ U; B( m O6 F+ " levels of the Moderator:" 2 o' B3 q4 U* l: n1 p
/rlabels="Mod=low" "Mod=med" "Mod=high"
. }6 Y& @' z# d) R. x/ k5 f# D /clabels="a" "raw b" "t-test" "df" "Sig. T".0 ^- f7 `, ?5 O3 L2 s ]
print { zslopes , zSE , confidLO, confidHI }
4 \$ x. a1 L% ?5 p8 H /title="Standardized Simple Slopes & 95% Confidence Intervals: "+ B& U Q5 F S3 W* ^1 d! v7 p: S
/rlabels="Mod=low" "Mod=med" "Mod=high" % y; c8 V& e: I+ F
/clabels="std. beta" "SE" "95% Low" "95% Hi".
5 R& K4 c: O k# j" j2 uprint ((b(1,1)/b(1,3))*-1)/title="The simple slope for the DV on the IDV"2 i' b; D/ v) F, m" W+ S j1 K
+ " is zero (flat) at Moderator =".) f% c m X7 u4 S
print ((b(1,2)/b(1,3))*-1)/title="The simple regression lines at "
" h! S8 `3 C. B+ "Mod=high and Mod=low intersect at IDV =".
* x* l$ Z: R0 o: f% c/ o9 p- j3 e; `1 d' @# x$ L
# K r" b5 G F3 R' k
* data for plot.. {+ ?( d% s% W- ^
compute idvlo = mn(1,1) - (sd(1,1) * multiIDV).+ f1 |" `& L: k2 b7 _
compute idvhi = mn(1,1) + (sd(1,1) * multiIDV) .
( \; M5 o8 n- ^7 w% @8 b2 B2 M3 [compute idv = { idvlo; idvhi; idvlo; idvhi; idvlo; idvhi } .
1 e9 E) }. @# G' i5 c/ O \1 x7 D& Ldo if (dichotom = 1)." z3 M6 i8 F: X8 c
compute idv = { dichotLO;dichotHi; dichotLO;dichotHi; dichotLO;dichotHi }.
W! D% c9 l- }. i/ ~; o2 gend if.
! L, e' n% J- |9 z0 ~compute moder = { modlo;modlo;modmd;modmd;modhi;modhi }.
3 I/ M4 z1 Y0 k1 Vcompute dv = (b(1,1)&*idv)+(b(1,2)&*moder)+(b(1,3)&*idv&*moder)+a.( V, l( D9 i$ |5 C1 y, R9 K
compute data = { idv , moder , dv }.) l, z& j" u- ^, O' L6 O0 i( B
4 [$ T" b( d9 E1 J0 Z. W4 Wprint data /title="Data for simple slope plots:" /clabels="IV" "Moderator" "DV" .
, P9 g% g5 C1 D: h
+ I: i, s8 G6 `" r. k1 ^/ V" O$ qsave data /outfile=* / var=zb1 zb2 b3.+ x: P3 j; k& G0 `; r& {
% G5 w& z3 L6 I7 xend matrix.1 h6 S* l$ N+ ?1 ^
8 Q0 p' P X5 Q; xplot vsize=15 / hsize=50 / format=contour(3) / plot=b3 with zb1 by zb2.
$ o/ I; U+ d* c. A: U) ~graph / line = mean (b3) by b1 by b2.% {& P* `3 @9 W
|
|