- 最后登录
- 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的名称就可以了。
7 T6 l# V8 i/ k" x& h* s. u
: m. w/ O# c( ?, ^*****************. n- W: R# T8 w
desc b1 b2/save.
% ?4 x" e3 }4 v6 E% x% r, Ncompute idv = zb1.
: t, P! ^2 y) {' U0 P% a2 [& mcompute mod = zb2.
( q. p2 @8 V1 ]* bcompute x = idv * mod.+ z7 T6 t/ K5 ?
compute dv = b3.
5 o* p1 ?# w& p( _! o0 B+ \ o+ A7 ?& }# {
regression ) `0 j+ ?7 g* O9 L! J4 `3 Q
/matrix out ('filename') 7 m a: h0 n9 Y3 I8 [3 r: p) x
/var= idv mod x dv & B1 _) t/ z; z* L [
/statistics=defaults zpp bcov
3 K) T' w9 t0 [1 ^5 q /dependent=dv2 @9 X! ^# X7 f9 ?
/enter idv mod
4 W# ~! I! p" e& R /test (x) .
' ?0 V; @7 ~3 u5 q: V9 j1 f
7 [% J+ J3 M uset mxloops=65.
( w# w1 E) P& ` {matrix.
6 S! o& K: O1 ]2 X: c' Q8 A! n3 l G. W* _3 b. r
compute multiMOD = 1.0 .
$ g) J! Y. O9 `; z/ b1 lcompute multiIDV = 1.0 .
$ ]5 Y6 f6 `$ P2 ]& bcompute dichotom = 0 .0 k) C# V# D7 Z( y/ m& k0 z' h
compute dichotLo = 1 .$ R( K9 \; ~; q8 n U' O' z
compute dichotHi = 2 .
; B+ o% i3 A$ K4 s' _4 z1 A( Amget /file='filename'.
0 v) @1 C4 e5 X5 R* ?% E6 D) l$ r/ y
; I1 w, [$ B* B: l* Overall regression coeffs.
8 [0 ^# J1 v, S: T& H# Ycompute beta = inv(cr(1:3,1:3)) * cr(1:3,4) .
* ~2 Q; s2 e. u c; E' Tcompute b = (sd(1,4) &/ sd(1,1:3)) &* t(beta) .4 M Q% s5 `. |1 J
compute a = mn(1,4) - ( rsum ( mn(1,1:3) &* b ) ) .
+ ]$ f& I3 a) x( f* u7 U! ccompute r2all = t(beta) * cr(1:3,4) .
s8 Z7 Q' s% }2 Z5 vcompute r2main = t(inv(cr(1:2,1:2))*cr(1:2,4))*cr(1:2,4).
7 C4 E# I) H+ s- v) ]& acompute r2chXn = r2all - r2main.
1 ]$ `% v. R4 K; a& M' z8 K! ]compute fsquare = (r2all - r2main) / (1 - r2all) .# J& |' x, s8 Z2 X2 X2 x6 [
compute F = (r2all-r2main) / ((1-r2all)/(nc(1,1)-3-1)).9 L( ^! h! I S
compute dferror = nc(1,1) - 3 - 1.% X; j5 U, w, O$ a; V4 o( e
compute pF = 1 - fcdf(F,1,dferror) .
v7 q# k% `9 ^4 A6 ]$ b2 R! d& b7 ~
print {r2chXn,F,{1},dferror,fsquare,pF} /title="Coefficients for the Interaction"* g: i5 Z3 N8 H1 ?7 @8 @3 z' ?
/clabels="Rsq. ch." "F" "df num." "df denom." "f-squared" "Sig. F".8 R' m+ X! p4 l1 o
print {t(b),beta} /title="Beta weights for the full equation:"
. p* M& W* V8 h1 U /rlabels="idv" "mod" "Xn" /clabels="raw b" "std.beta" .
' r; H5 T/ I6 Oprint a /title="The intercept is:" .
4 Y, r: p$ q7 [; B2 j
0 m1 x' Z7 _ ?3 {4 Q) m9 K' i' |4 l5 ^3 ?* K& b
* simple slopes info .
K+ m/ q9 W: N0 U! ]compute modlo = mn(1,2) - (sd(1,2) * multiMOD) .
1 B( N9 h7 v% Q$ C, ~4 |: |3 mcompute modmd = mn(1,2).
0 e1 B- p! m0 z* E+ X/ P, J! H( o3 [compute modhi = mn(1,2) + (sd(1,2) * multiMOD) .& J+ @/ W+ S4 [5 q
compute slopes={(b(1,1)+(b(1,3)*modlo)) ;
* Q, L# J1 h0 R& O9 w0 \9 _ (b(1,1)+(b(1,3)*modmd)) ; (b(1,1)+(b(1,3)*modhi)) }. {$ E$ i& @0 m! P& i
compute aslopes={ (b(1,2)*modlo+a) ; (b(1,2)*modmd+a) ; (b(1,2)*modhi+a) }.2 G3 w3 D$ [+ {& b, B
compute mse = (nc(1,1)/(nc(1,1)-3))*(sd(1,4)**2)*(1-r2all).
M$ k6 s" S: f6 ^compute Sb=mse*inv((mdiag(sd(1,1:3))*cr(1:3,1:3)*mdiag(sd(1,1:3)))*(nc(1,1)-1)).
$ A9 L8 ]- I' F* \( ^$ ecompute SEslopes={ (sqrt ( {1,0,modlo} * Sb * t({1,0,modlo}) )) ;( f# O) m5 T2 u" v# }+ D
(sqrt ( {1,0,modmd} * Sb * t({1,0,modmd}) )) ;
' H+ f" p1 R6 h3 P8 l" b (sqrt ( {1,0,modhi} * Sb * t({1,0,modhi}) )) }./ C6 E/ w9 g: _5 V
compute tslopes = slopes &/ SEslopes .
3 t# I$ w" A- i3 bcompute df = { (nc(1,1)-3-1) ; (nc(1,1)-3-1) ; (nc(1,1)-3-1) }.
1 ^3 q3 g/ \# Fcompute zslopes = slopes &* (sd(1,1)/sd(1,4)).
w' W3 ^- V. P2 `5 ^2 Ecompute zSE = SEslopes &* (sd(1,1)/sd(1,4)) .
1 t4 @1 |1 }8 O) fcompute dfs = nc(1,1)-3-1 .! w4 o) w! Z9 l/ M& c' m
compute pslopes = (1 - tcdf(abs(tslopes),dfs)) * 2., J' A1 P/ X' U
' x5 A4 a! p) y% o# s* m5 x( Q# g* df & t values -- from Darlington p 516 & Howell 87 p 586 -- p = 05 two-tailed .
& x$ Z M9 s6 X0 G" \; O0 Y: vcompute 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,
! {& F: f5 m( Y; i8 v1 u- A 30,32,34,36,38,40,43,46,49,52,56,60,65,70,75,80,85,90,95,100,110,120,130,
$ q- K+ {: _. M9 {. X! G7 |1 z8 D 150,175,200,250,300,400,500,600,700,800,900,1000,1000000000;. ~2 D' a& @' j0 O* o
12.706,4.303,3.182,2.776,2.571,2.447,2.365,2.306,2.262,2.228,2.201,2.179,
# F- C0 |. @! a6 g- ]' B g 2.160,2.145,2.131,2.120,2.110,2.101,2.093,2.086,2.074,2.064,2.056,2.048,
6 \$ k# v% E- W% l. M 2.042,2.037,2.032,2.028,2.024,2.021,2.017,2.013,2.010,2.007,2.003,2.000,
+ D2 v0 ~) B8 b 1.997,1.994,1.992,1.990,1.988,1.987,1.985,1.984,1.982,1.980,1.978,1.976,
& j# h% X( U3 b* `7 s7 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 }.' |) T3 {3 }7 |. i6 z/ ~- D
compute tabledT = 0.
$ X# n$ F q1 ^+ ~# Bloop #a = 1 to 59 .! r9 @1 i t$ u5 d8 \
do if (dfs ge dft(1,#a) and dfs < dft(1,#a+1) ).! M% e! L9 N; G- ?
compute tabledT = dft(2,#a) .
: U1 W# K: o b' ]+ ~. |end if.: u) J$ s9 j& i
end loop if (tabledT > 0). U7 r: y! z: X+ Z
compute confidLo = (zslopes - (tabledT &* zSE)) .
- Z; d {7 K8 u5 Z9 R7 i" e8 K& Ecompute confidHi = (zslopes + (tabledT &* zSE)) .
6 d% d8 g4 p" l- A; h; Z% u! n4 k; Y7 I8 A
print { aslopes , slopes , tslopes , df , pslopes}
0 @$ M3 p% J* l: b /title="Simple Slope Coefficients for the DV on the IDV at 3"; ?' C) @* G% q
+ " levels of the Moderator:"
% P3 g# s1 e: D /rlabels="Mod=low" "Mod=med" "Mod=high"# x8 O. s) k( {. p% J, |8 @- y( t0 e' v: X
/clabels="a" "raw b" "t-test" "df" "Sig. T".
+ q! L) q! @ g- f) F' E' Yprint { zslopes , zSE , confidLO, confidHI }
6 _+ }6 u7 w" g$ `; ` /title="Standardized Simple Slopes & 95% Confidence Intervals: "
. ?$ t& d- p9 a, |" y) M8 W /rlabels="Mod=low" "Mod=med" "Mod=high" & ^1 j$ w* `+ h$ p9 s
/clabels="std. beta" "SE" "95% Low" "95% Hi".; T! U4 Y6 D1 R1 _1 e9 V/ v
print ((b(1,1)/b(1,3))*-1)/title="The simple slope for the DV on the IDV"; Q7 Z& N W' F+ j0 y: u
+ " is zero (flat) at Moderator =".' F' f. c, a: N$ v N5 t
print ((b(1,2)/b(1,3))*-1)/title="The simple regression lines at "* [3 R4 h; h P- k# w, C
+ "Mod=high and Mod=low intersect at IDV =".
$ Q, N$ u' W" o! ~+ j6 i
W5 s" P# G+ ]- v* \; I
" Q: D. O; R( f1 e1 o7 K* data for plot.7 X1 a8 P! g k7 }) a. R
compute idvlo = mn(1,1) - (sd(1,1) * multiIDV).
+ r; n* `5 `! I4 M/ s; j+ hcompute idvhi = mn(1,1) + (sd(1,1) * multiIDV) .
6 d5 b& B" f9 ~" zcompute idv = { idvlo; idvhi; idvlo; idvhi; idvlo; idvhi } .
1 d- a6 F( ^/ t2 ado if (dichotom = 1).
1 [9 w4 T) X1 s" Y5 I5 Wcompute idv = { dichotLO;dichotHi; dichotLO;dichotHi; dichotLO;dichotHi }.6 c3 {0 `& Y \6 F
end if.2 S/ Z, F! ~$ X0 D7 p( S. g6 Q' ?
compute moder = { modlo;modlo;modmd;modmd;modhi;modhi }.
9 X) f, I+ {- l" @. y/ e6 ]compute dv = (b(1,1)&*idv)+(b(1,2)&*moder)+(b(1,3)&*idv&*moder)+a.; j( Y3 c( \- B% F) c
compute data = { idv , moder , dv }.
6 ]& T( j, u0 s, T
8 }5 q" F/ i- R- z: a5 C" x8 R" Kprint data /title="Data for simple slope plots:" /clabels="IV" "Moderator" "DV" .
8 p5 o: t/ G* O* B8 y/ k
$ g5 Y+ c y7 u* ksave data /outfile=* / var=zb1 zb2 b3.$ G) E% z W/ B+ u% H
# J. `6 ?! w+ e2 L# ~% |, M* n6 ?end matrix.2 [; J6 ~% ]8 N% Z. i0 t
8 E/ u/ [! s1 k5 Q7 d
plot vsize=15 / hsize=50 / format=contour(3) / plot=b3 with zb1 by zb2.
. Z8 m- w" W, n3 p ^# G" |graph / line = mean (b3) by b1 by b2.- |) [# K/ p; R, z
|
|