- 最后登录
- 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的名称就可以了。
& S: h1 p7 L5 \% Q0 Q% K3 g
7 c5 Z3 W2 y/ Q2 m6 f& F*****************.
! w% H1 u" e0 t( b% \desc b1 b2/save.
z5 C$ e0 X% h2 ?1 S Tcompute idv = zb1.2 |! d3 b$ P3 o# ~1 E3 r2 ^% _0 T
compute mod = zb2.
B9 D, I2 }+ ccompute x = idv * mod.# R. P6 d( Q& a* u* t4 f6 n; V
compute dv = b3.
8 j& A/ n2 F9 A9 v& P& k' R0 x4 p2 ~' [0 S2 q- V+ T w; K
regression ; E y" _- a* V6 R3 f" n
/matrix out ('filename') 2 P. k. U' [4 N3 y
/var= idv mod x dv
9 K9 K& V s8 O" ]7 |0 d" {9 j /statistics=defaults zpp bcov
" r- M7 ^3 M" }' V /dependent=dv
% |* W7 P K+ g5 J /enter idv mod
+ q4 ~* D5 s1 O9 ` /test (x) .
, l3 z! b" o+ ^2 j& d+ u3 |/ t
" O* Q+ g9 K) k- V+ i5 [5 kset mxloops=65.
5 N' \1 i' j# ?8 M# Cmatrix.- _7 e8 u$ l8 o1 _
8 {% G$ t' N- g" s" Qcompute multiMOD = 1.0 .4 W, A2 A |% L5 C
compute multiIDV = 1.0 .4 s# D5 O# N0 k d5 ^6 Z& J# Y' f' |. ^
compute dichotom = 0 .
8 n! g# j, u; Scompute dichotLo = 1 .
5 y- a, a x, E' }$ O% Hcompute dichotHi = 2 .
$ l6 [1 ^' h- [* I9 X' imget /file='filename'.
; p! k, u) E3 P, i5 U2 {
* |* d7 x" Q4 U. I0 X1 v4 }! B1 \* Overall regression coeffs.
7 y% w5 V! P6 ]% A: a8 ucompute beta = inv(cr(1:3,1:3)) * cr(1:3,4) .
2 L/ ~* G) \. Z& J Rcompute b = (sd(1,4) &/ sd(1,1:3)) &* t(beta) .
$ Z2 j1 w4 b e2 }- _) a8 A& ~ E2 Xcompute a = mn(1,4) - ( rsum ( mn(1,1:3) &* b ) ) .
2 P. d- P# @6 k* Z; ycompute r2all = t(beta) * cr(1:3,4) .7 I3 v" N$ `- R. `" W" [
compute r2main = t(inv(cr(1:2,1:2))*cr(1:2,4))*cr(1:2,4).# L% o- ?4 |: C4 q
compute r2chXn = r2all - r2main.
( z: F4 M- D* |/ Zcompute fsquare = (r2all - r2main) / (1 - r2all) . [7 R t: h, n9 ~1 g1 A" {
compute F = (r2all-r2main) / ((1-r2all)/(nc(1,1)-3-1)).
7 |6 ]+ |% X' ?8 W+ S7 Acompute dferror = nc(1,1) - 3 - 1.* I: u0 W! W4 y) L# E
compute pF = 1 - fcdf(F,1,dferror) .: J. H+ M6 P7 Y8 K/ s2 M
1 f! V( u" r: O2 @
print {r2chXn,F,{1},dferror,fsquare,pF} /title="Coefficients for the Interaction"
) ?6 m/ Q% Z/ D+ v: K& _ /clabels="Rsq. ch." "F" "df num." "df denom." "f-squared" "Sig. F".
! t" B' q6 f( A N& S- \print {t(b),beta} /title="Beta weights for the full equation:"! s2 m- p9 H6 X- x
/rlabels="idv" "mod" "Xn" /clabels="raw b" "std.beta" .% B/ S0 L* X) n! h; i. F
print a /title="The intercept is:" .6 k" Y6 \! y4 }' _% G3 h
" g$ o' B n& B8 i
. |. X, P, a) C3 A* simple slopes info .& P/ O& m7 W6 N0 f
compute modlo = mn(1,2) - (sd(1,2) * multiMOD) .
, c: `1 }* l+ D' ccompute modmd = mn(1,2).9 N4 P4 W% o/ P7 ]2 u. l
compute modhi = mn(1,2) + (sd(1,2) * multiMOD) .7 t% Q3 D% x8 e
compute slopes={(b(1,1)+(b(1,3)*modlo)) ;
/ h0 @4 X# g( C" V (b(1,1)+(b(1,3)*modmd)) ; (b(1,1)+(b(1,3)*modhi)) }.
6 N. z9 {- f0 K2 y% ~7 O4 L" pcompute aslopes={ (b(1,2)*modlo+a) ; (b(1,2)*modmd+a) ; (b(1,2)*modhi+a) }.2 a0 J P% V0 W' o# J5 P
compute mse = (nc(1,1)/(nc(1,1)-3))*(sd(1,4)**2)*(1-r2all).
! q5 B3 Q* O7 J2 ^3 F0 Wcompute Sb=mse*inv((mdiag(sd(1,1:3))*cr(1:3,1:3)*mdiag(sd(1,1:3)))*(nc(1,1)-1)).
7 V9 L7 Y: c3 { ncompute SEslopes={ (sqrt ( {1,0,modlo} * Sb * t({1,0,modlo}) )) ;
% d8 G3 w, U8 P( m (sqrt ( {1,0,modmd} * Sb * t({1,0,modmd}) )) ;6 o. _' o; J: l6 m
(sqrt ( {1,0,modhi} * Sb * t({1,0,modhi}) )) }.
# j7 d% z( [9 v, W/ M) lcompute tslopes = slopes &/ SEslopes .
8 ^% {; r* B+ rcompute df = { (nc(1,1)-3-1) ; (nc(1,1)-3-1) ; (nc(1,1)-3-1) }.
: |% c9 U+ {* W1 Pcompute zslopes = slopes &* (sd(1,1)/sd(1,4)).
% O! W- K! \- P+ Vcompute zSE = SEslopes &* (sd(1,1)/sd(1,4)) .. W& z( |4 f0 y6 @
compute dfs = nc(1,1)-3-1 .
4 y; W) m: G9 r0 L* J6 V3 Wcompute pslopes = (1 - tcdf(abs(tslopes),dfs)) * 2.
0 I+ W6 U0 T( p' _
, o- f% A$ p" M3 \7 f. h8 H3 m* df & t values -- from Darlington p 516 & Howell 87 p 586 -- p = 05 two-tailed .
, y0 y6 m& G! {6 [, a# D+ w7 ?$ Tcompute 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,7 Q5 k6 e! ~1 s- I% P6 e/ P
30,32,34,36,38,40,43,46,49,52,56,60,65,70,75,80,85,90,95,100,110,120,130,0 {* |& c4 c; W& w/ h; A5 |
150,175,200,250,300,400,500,600,700,800,900,1000,1000000000;. f4 K1 n3 A8 f: |7 u% N2 _( |: v3 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,+ ]. s5 C% R9 q9 X
2.160,2.145,2.131,2.120,2.110,2.101,2.093,2.086,2.074,2.064,2.056,2.048, l( G& J- d9 h% ?& o2 u9 k
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 y# j7 A$ c, E. W7 S
1.997,1.994,1.992,1.990,1.988,1.987,1.985,1.984,1.982,1.980,1.978,1.976,
+ h }7 y/ G3 ~- B7 l/ P; \ 1.974,1.972,1.969,1.968,1.966,1.965,1.964,1.963,1.963,1.963,1.962,1.962 }.
* `; |0 @* c; V8 S! }compute tabledT = 0.
7 v. k0 Z6 B! c! Y9 o/ N8 \" ^( oloop #a = 1 to 59 .
1 }4 @( v4 S, Bdo if (dfs ge dft(1,#a) and dfs < dft(1,#a+1) ).
1 P* c2 P# U S' I$ g) Kcompute tabledT = dft(2,#a) .
9 i# J3 u6 |1 ~/ k) {end if.: _ i2 ^( d$ F- C/ V( [" W! [0 B
end loop if (tabledT > 0).
% ]/ s9 o7 T/ {4 ^/ f8 ~; pcompute confidLo = (zslopes - (tabledT &* zSE)) .( ]4 a: L' O4 _4 H9 [/ i
compute confidHi = (zslopes + (tabledT &* zSE)) .3 i$ _9 n5 e( B# U) k# }
% _* `% ^7 R1 k' h% ~* @5 B& G9 Oprint { aslopes , slopes , tslopes , df , pslopes} 7 f7 H) J3 ~ Y8 S$ E5 J
/title="Simple Slope Coefficients for the DV on the IDV at 3"
5 B. {& y# _" H$ h$ U5 e+ " levels of the Moderator:" " Y0 k3 j. l- T* y. k* s/ p
/rlabels="Mod=low" "Mod=med" "Mod=high"/ s. M$ ^/ }( f9 Q0 e3 F1 V" p4 M, u
/clabels="a" "raw b" "t-test" "df" "Sig. T".4 Z% j! X4 w8 R& @
print { zslopes , zSE , confidLO, confidHI } ; ^, Y5 q) X' t0 y0 Q- }. {4 S- {: G; \
/title="Standardized Simple Slopes & 95% Confidence Intervals: "
: L7 _8 ], u" o# ~: O /rlabels="Mod=low" "Mod=med" "Mod=high"
" h8 [. k4 i8 @( V: } /clabels="std. beta" "SE" "95% Low" "95% Hi".
7 s1 m7 V3 Z) v" ?: `: Aprint ((b(1,1)/b(1,3))*-1)/title="The simple slope for the DV on the IDV"
; ` w9 u+ E1 c* f+ " is zero (flat) at Moderator =".! \$ S4 n: @& Q
print ((b(1,2)/b(1,3))*-1)/title="The simple regression lines at "7 Z1 S* j8 I! C# T; z$ {
+ "Mod=high and Mod=low intersect at IDV =".
' c- x- A8 L5 @3 L" t E; S- G3 A+ D, u+ p% W; |
7 G+ ?, r( U, R) {: S
* data for plot.
0 H9 G9 B# e0 e" dcompute idvlo = mn(1,1) - (sd(1,1) * multiIDV).
u$ d# i, m! }& Q7 k3 n! t, Ucompute idvhi = mn(1,1) + (sd(1,1) * multiIDV) .
2 f/ \: ` c9 x) @/ W1 g+ Ycompute idv = { idvlo; idvhi; idvlo; idvhi; idvlo; idvhi } .
3 r" z+ }/ j+ i; z6 bdo if (dichotom = 1).
f/ J7 y( \& W. jcompute idv = { dichotLO;dichotHi; dichotLO;dichotHi; dichotLO;dichotHi }.
/ G; g% j K! R4 N& dend if.. I( U5 C6 t. y
compute moder = { modlo;modlo;modmd;modmd;modhi;modhi }.5 J* `6 x8 U* `; \
compute dv = (b(1,1)&*idv)+(b(1,2)&*moder)+(b(1,3)&*idv&*moder)+a.
Z. K2 S- u7 n! E6 bcompute data = { idv , moder , dv }.
+ \3 w4 s# ~6 |' I1 x5 [
: o' U+ }: p0 q. f! Y% uprint data /title="Data for simple slope plots:" /clabels="IV" "Moderator" "DV" .
; ]0 M/ R# C1 p- c1 r+ o1 P J* F: J) o* t! e9 k* V% S7 R
save data /outfile=* / var=zb1 zb2 b3.
( T& R: t, h& E( M: ~8 V/ S9 t
; e8 {0 J8 r5 m' Y" x1 Jend matrix.
' l) ?! ]) u. e0 V1 q% y, \9 H( q) @1 U
plot vsize=15 / hsize=50 / format=contour(3) / plot=b3 with zb1 by zb2.7 [! b+ U% ^0 t: x
graph / line = mean (b3) by b1 by b2.
1 @" {. i7 k" z& q" }6 t |
|