- 最后登录
- 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的名称就可以了。
+ } m. g9 f* O/ W& H3 O3 L, O3 _% k
2 s7 q3 |( R& d! T2 c*****************.. g. S/ ~$ _9 P5 ~
desc b1 b2/save.
2 T, Q+ B- ]! ~compute idv = zb1.5 N5 M- j( ?+ s: i
compute mod = zb2.# q; N# s t0 p
compute x = idv * mod.
4 }$ z! b# v* c/ Xcompute dv = b3.
5 P& M& l. V i
5 U# t9 I3 H4 m3 E6 e0 jregression
* G7 a" M6 Z Q$ _ W6 ^( | /matrix out ('filename') 5 d4 h4 a- l% c& F5 @2 {3 Q
/var= idv mod x dv , j' w) k) r( Y: Y9 x* J
/statistics=defaults zpp bcov . R, R! v: w. \" H; [2 b; J5 E
/dependent=dv
* Q8 E8 j5 X. U8 Z2 U! y8 B1 d /enter idv mod
/ l2 c$ q. d4 x. l0 b' q /test (x) .% ?; C x% J! a
& P, B! i& ^6 i- Z4 fset mxloops=65.
4 N6 P% D7 O4 h7 k" Bmatrix.
, V; W0 _! v! ^5 i! x7 X* E7 f2 w1 j7 N0 ~9 P$ u0 I4 [8 Y
compute multiMOD = 1.0 .
/ N! _+ j. _* P2 Z# h$ [. jcompute multiIDV = 1.0 .3 K- L- X$ q% r# j# Q
compute dichotom = 0 .
7 t" m; y) Q+ ?0 ^; A2 C/ lcompute dichotLo = 1 .
& z% _# j7 s9 U: r" P4 [compute dichotHi = 2 .4 c9 T( i) ^7 }% I
mget /file='filename'.. ^9 s$ l, D6 ~# c
2 ^. b/ ^4 ~5 {/ y+ v S$ f* Overall regression coeffs.1 C; }- w9 S/ s- a2 x! M8 \) D' Q% {
compute beta = inv(cr(1:3,1:3)) * cr(1:3,4) .$ c9 ~( X( c+ L' V+ k3 ]/ O1 z8 q* {
compute b = (sd(1,4) &/ sd(1,1:3)) &* t(beta) ./ f# [: B/ T- _0 g. P1 U
compute a = mn(1,4) - ( rsum ( mn(1,1:3) &* b ) ) .# d0 p4 z; I2 f- d6 ~3 h
compute r2all = t(beta) * cr(1:3,4) .
+ C" |2 z, B; s6 l6 q8 t/ bcompute r2main = t(inv(cr(1:2,1:2))*cr(1:2,4))*cr(1:2,4).
) v' y9 l, @8 B0 ^8 Pcompute r2chXn = r2all - r2main.
4 D4 |& k M) i+ \( k4 J2 k9 x+ }compute fsquare = (r2all - r2main) / (1 - r2all) . C+ A0 R _8 N+ Q: ]4 v, F
compute F = (r2all-r2main) / ((1-r2all)/(nc(1,1)-3-1)).
( e4 b& V5 ?: ]" Y* _1 A ycompute dferror = nc(1,1) - 3 - 1.
: j; S9 k5 ]( q1 x0 D9 l9 qcompute pF = 1 - fcdf(F,1,dferror) .% E J! c; U7 s6 l, @5 F
$ i: }( }% I6 F: L' Xprint {r2chXn,F,{1},dferror,fsquare,pF} /title="Coefficients for the Interaction"
6 z- |/ ~% a1 R, d6 W /clabels="Rsq. ch." "F" "df num." "df denom." "f-squared" "Sig. F".
- s! ^0 b- ?7 R iprint {t(b),beta} /title="Beta weights for the full equation:"
/ p% D( ?) j# I9 t /rlabels="idv" "mod" "Xn" /clabels="raw b" "std.beta" .4 {/ k9 `- @/ a5 h) q8 M W. _
print a /title="The intercept is:" .8 Y) W, o1 x/ @, w- L
5 F4 f% i* T7 z% X% M' S6 ]! p, B
$ c0 H4 ]0 i: H7 _2 l) t
* simple slopes info .' a. t+ `% ^9 g6 ~0 `
compute modlo = mn(1,2) - (sd(1,2) * multiMOD) .
4 j2 O: f% a; a# ^/ C* W0 jcompute modmd = mn(1,2).
; k5 k# C& S: f& M1 v J& Scompute modhi = mn(1,2) + (sd(1,2) * multiMOD) .( A1 d/ A$ [9 ?0 T7 @/ a0 H
compute slopes={(b(1,1)+(b(1,3)*modlo)) ;
* L6 C2 M1 Z. H* H7 h) A5 n% s (b(1,1)+(b(1,3)*modmd)) ; (b(1,1)+(b(1,3)*modhi)) }.1 z, W0 K+ i5 @7 P& q. d
compute aslopes={ (b(1,2)*modlo+a) ; (b(1,2)*modmd+a) ; (b(1,2)*modhi+a) }.
0 @) T1 k) `+ \1 H, Scompute mse = (nc(1,1)/(nc(1,1)-3))*(sd(1,4)**2)*(1-r2all).
! I4 ^: d% ~5 n( @) t4 r+ ?compute Sb=mse*inv((mdiag(sd(1,1:3))*cr(1:3,1:3)*mdiag(sd(1,1:3)))*(nc(1,1)-1)).: F2 ]% h0 K F( v
compute SEslopes={ (sqrt ( {1,0,modlo} * Sb * t({1,0,modlo}) )) ;
) a: c6 ?: ?& m0 A4 H2 J+ } (sqrt ( {1,0,modmd} * Sb * t({1,0,modmd}) )) ;
2 L# a- V2 p* z- s1 R (sqrt ( {1,0,modhi} * Sb * t({1,0,modhi}) )) }.
, [& h" K$ f* [# n% Gcompute tslopes = slopes &/ SEslopes .
, ?2 N3 b$ H& C" o7 s tcompute df = { (nc(1,1)-3-1) ; (nc(1,1)-3-1) ; (nc(1,1)-3-1) }.
% h5 s J5 J: @5 p' c! `' i" qcompute zslopes = slopes &* (sd(1,1)/sd(1,4)).
. L$ A) m3 U, T7 z" {compute zSE = SEslopes &* (sd(1,1)/sd(1,4)) .6 A8 P& H* c# @* N( I: J% H
compute dfs = nc(1,1)-3-1 .
$ w6 }( ~; b7 W# ^# G9 T/ Y) U Acompute pslopes = (1 - tcdf(abs(tslopes),dfs)) * 2.
6 j) T; U3 q/ {4 E/ `( D2 o0 u# |9 B; g6 B- |3 e8 R1 \# Q% a& ?* t
* df & t values -- from Darlington p 516 & Howell 87 p 586 -- p = 05 two-tailed .! c5 q( W) i' |1 o( D. {1 e
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,6 Q, Z* c! G0 s# S* r
30,32,34,36,38,40,43,46,49,52,56,60,65,70,75,80,85,90,95,100,110,120,130,
' t% r* D) Q9 ^ 150,175,200,250,300,400,500,600,700,800,900,1000,1000000000;
9 U" f8 D/ j- y, L4 k5 ? Y 12.706,4.303,3.182,2.776,2.571,2.447,2.365,2.306,2.262,2.228,2.201,2.179," [# a! y+ `, 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,0 o$ Z! o- S! h% ~4 j
2.042,2.037,2.032,2.028,2.024,2.021,2.017,2.013,2.010,2.007,2.003,2.000,
8 h& A2 \5 r" F& @4 m1 i5 R 1.997,1.994,1.992,1.990,1.988,1.987,1.985,1.984,1.982,1.980,1.978,1.976,
+ u" n) [4 S( u0 s/ v* d 1.974,1.972,1.969,1.968,1.966,1.965,1.964,1.963,1.963,1.963,1.962,1.962 }.
) T) i9 E9 J( O5 B L; C$ X% k. rcompute tabledT = 0." C1 Q& ^# E6 Z" W7 p7 L/ I! s
loop #a = 1 to 59 .; \4 [) x/ x$ Y+ f
do if (dfs ge dft(1,#a) and dfs < dft(1,#a+1) ).+ c, y# h; B3 g, J7 s& X) M
compute tabledT = dft(2,#a) .
, J7 U* S. F5 m& Z" _end if.6 w4 @% O7 k- j( Q6 t1 }! \2 p
end loop if (tabledT > 0).
/ t- A6 [6 w# X2 h& U S' [compute confidLo = (zslopes - (tabledT &* zSE)) .
- u) K* j! o o- p2 q( j7 x5 }+ i3 gcompute confidHi = (zslopes + (tabledT &* zSE)) .
3 M8 u1 J+ r, Y1 A' T7 K/ u2 n9 }8 }
" v3 Z6 t' C0 I% a2 o0 ^print { aslopes , slopes , tslopes , df , pslopes}
" R6 d6 D. w. Z' w0 q$ A /title="Simple Slope Coefficients for the DV on the IDV at 3", c# G/ a' e4 A
+ " levels of the Moderator:" ! N! {. f x; a2 ~4 D
/rlabels="Mod=low" "Mod=med" "Mod=high"
4 y6 C: b' I* Q" {- c: t! d/ q /clabels="a" "raw b" "t-test" "df" "Sig. T".
& H( Y+ N& F" t0 n' Rprint { zslopes , zSE , confidLO, confidHI } 1 b* ~' H+ a$ q, ]" q8 b: w% M
/title="Standardized Simple Slopes & 95% Confidence Intervals: "! c$ s4 D3 m8 |
/rlabels="Mod=low" "Mod=med" "Mod=high" # b+ ^% L( }9 Q' l1 c. s
/clabels="std. beta" "SE" "95% Low" "95% Hi".: h. Q8 e" }8 K7 C& T
print ((b(1,1)/b(1,3))*-1)/title="The simple slope for the DV on the IDV"
$ d. J6 n* n4 h; T x+ " is zero (flat) at Moderator =".8 y0 r# k+ u' s# l! F8 c
print ((b(1,2)/b(1,3))*-1)/title="The simple regression lines at "
; r: V* f4 u' c+ "Mod=high and Mod=low intersect at IDV ="., O5 f7 b5 R! t; y3 y1 }
; ?; x( |9 P* R! ^
% P" h) y! A! m* m
* data for plot.( r$ q" W' y; J; r
compute idvlo = mn(1,1) - (sd(1,1) * multiIDV).
8 p+ `1 D2 p# E ocompute idvhi = mn(1,1) + (sd(1,1) * multiIDV) .9 {6 N b" o/ m% S
compute idv = { idvlo; idvhi; idvlo; idvhi; idvlo; idvhi } .
0 v' y' h2 p4 sdo if (dichotom = 1).; Q3 o+ Q% M# ?' Y C4 _0 x# F
compute idv = { dichotLO;dichotHi; dichotLO;dichotHi; dichotLO;dichotHi }.2 ^5 G) O: W' R9 L4 E& Y
end if.
' ~" a/ |; A+ ?3 L6 Lcompute moder = { modlo;modlo;modmd;modmd;modhi;modhi }.2 D; v: H2 d$ Z, J
compute dv = (b(1,1)&*idv)+(b(1,2)&*moder)+(b(1,3)&*idv&*moder)+a.: C* R5 \5 p+ b3 Q
compute data = { idv , moder , dv }.
* _' o: }+ W) p4 X$ H! H1 h9 _ Q, M4 Z8 i! K# n: L
print data /title="Data for simple slope plots:" /clabels="IV" "Moderator" "DV" .6 J* k5 j) G: K( K; e( I R$ c9 e
. N8 l3 k8 l& X6 P# z/ J$ [
save data /outfile=* / var=zb1 zb2 b3.
$ Y. I2 T8 a h6 E
$ s* V2 H& C3 K5 z$ U5 gend matrix.
7 `6 v, x2 v1 T7 c. U2 p4 p
8 d0 |* n: @) Hplot vsize=15 / hsize=50 / format=contour(3) / plot=b3 with zb1 by zb2.8 {+ a2 H: u+ `
graph / line = mean (b3) by b1 by b2.6 I. O- j1 y- D7 Z4 D4 e! t. `0 @
|
|