- 最后登录
- 2014-6-18
- 注册时间
- 2009-3-1
- 威望
- 0
- 金钱
- 274
- 贡献
- 215
- 阅读权限
- 20
- 积分
- 489
- 日志
- 0
- 记录
- 0
- 帖子
- 56
- 主题
- 7
- 精华
- 0
- 好友
- 0
![Rank: 3](static/image/common/star_level1.gif) ![Rank: 3](static/image/common/star_level1.gif) ![Rank: 3](static/image/common/star_level1.gif)
- 注册时间
- 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的名称就可以了。6 \1 d: D! D; L% k) s0 f( N
$ `+ e j4 h$ L! J, o% {$ b3 g*****************.
3 o" Z( e) ?1 d- idesc b1 b2/save.
& i. k6 m Z& `7 X: }6 J3 Vcompute idv = zb1.# g/ y( l! d! C- s0 R ~
compute mod = zb2.
3 D) y# x* ?$ g3 b9 w4 V; scompute x = idv * mod.
- S" g. ~2 w6 D3 V6 o4 Ocompute dv = b3." D: c, E. W* Z8 l4 p+ Z( i0 n
0 R, I, P3 i, X% a' v" c# ?regression 4 \$ C \8 t9 C; {+ l
/matrix out ('filename') 1 a" Z+ i( |/ t# g1 G
/var= idv mod x dv + R# W# _% Z8 ?9 N- G6 |/ j R
/statistics=defaults zpp bcov 0 _2 z7 I+ |' x
/dependent=dv
% e# e" g, S" v0 K. u% p /enter idv mod
0 ~ {$ q, U/ e5 g /test (x) .
# d1 j; A! n; t- v5 F' A7 P9 K$ v: R, Z7 E4 Q8 t: h4 n
set mxloops=65.4 U2 A9 [3 w8 B. g9 J
matrix.. n+ N9 ^) a; A! `( I
) f' K& h) w0 S; v0 ucompute multiMOD = 1.0 .
2 G' c: U; }. @, B B4 _$ x8 m$ [compute multiIDV = 1.0 .9 K) o% S- M6 y- p8 u/ S% r, B
compute dichotom = 0 ., l7 @1 v1 E" }9 h+ b% }* F
compute dichotLo = 1 ., l0 ^/ x) R8 y. G
compute dichotHi = 2 .6 |6 F1 Z* X2 }% S& c( i
mget /file='filename'.
1 [8 ^( p# F2 I9 F" W0 R% N9 ?3 J' [ W
* Overall regression coeffs.
# z8 c0 N! r* W9 R( k& w0 Ccompute beta = inv(cr(1:3,1:3)) * cr(1:3,4) .$ s. N- l5 N+ ^% ~; j$ q- b
compute b = (sd(1,4) &/ sd(1,1:3)) &* t(beta) .9 F. ^) I" Y: C6 d: F7 z
compute a = mn(1,4) - ( rsum ( mn(1,1:3) &* b ) ) .0 n& v, q9 q3 o6 Z3 b5 }' @
compute r2all = t(beta) * cr(1:3,4) .+ p# X/ |- B* a: r, N( E: z+ @
compute r2main = t(inv(cr(1:2,1:2))*cr(1:2,4))*cr(1:2,4).
* q' _( t k0 e" `& r% l3 i6 ^compute r2chXn = r2all - r2main.! C" g3 b3 i! T$ R ~4 g+ h
compute fsquare = (r2all - r2main) / (1 - r2all) .
: n0 t6 c9 m4 B n% qcompute F = (r2all-r2main) / ((1-r2all)/(nc(1,1)-3-1)).
" o; B& r) T4 E0 l# Ycompute dferror = nc(1,1) - 3 - 1.
0 i5 B% |- m2 y: L4 _: Qcompute pF = 1 - fcdf(F,1,dferror) .4 v Q( ?/ U. Z( M+ s( F1 P
; L, V/ w% v1 }print {r2chXn,F,{1},dferror,fsquare,pF} /title="Coefficients for the Interaction"
6 ]3 H0 u ?1 u, H /clabels="Rsq. ch." "F" "df num." "df denom." "f-squared" "Sig. F".
3 P8 h( B: r% O, h S& I& @print {t(b),beta} /title="Beta weights for the full equation:"
7 l5 k% J+ t( ~7 N; [! V* R; m7 g/ A /rlabels="idv" "mod" "Xn" /clabels="raw b" "std.beta" .
3 I( F8 _3 [9 @4 ~5 v2 Fprint a /title="The intercept is:" .
A% O7 C7 G. A" a0 k; L' |; ?& _9 ~7 E. K1 ?" j- j+ w3 K: \
3 y- b; z. ?! V* simple slopes info ., E& X2 E4 l, H! {. H% x1 b
compute modlo = mn(1,2) - (sd(1,2) * multiMOD) .
: O7 p4 w _0 mcompute modmd = mn(1,2).. }4 w1 F8 J! o$ Q( e; ~
compute modhi = mn(1,2) + (sd(1,2) * multiMOD) .. y w/ A% g4 k
compute slopes={(b(1,1)+(b(1,3)*modlo)) ;; q8 r {( o5 {0 j' F6 l; f
(b(1,1)+(b(1,3)*modmd)) ; (b(1,1)+(b(1,3)*modhi)) }.
$ d* ]0 A' h- z: K0 E' ncompute aslopes={ (b(1,2)*modlo+a) ; (b(1,2)*modmd+a) ; (b(1,2)*modhi+a) }.. Z+ ?" z9 r$ f3 s+ \' i+ ?, M' g
compute mse = (nc(1,1)/(nc(1,1)-3))*(sd(1,4)**2)*(1-r2all).
) z6 ?* m9 v6 {; |compute Sb=mse*inv((mdiag(sd(1,1:3))*cr(1:3,1:3)*mdiag(sd(1,1:3)))*(nc(1,1)-1)).
. n- L# i% u* w, c- ~7 fcompute SEslopes={ (sqrt ( {1,0,modlo} * Sb * t({1,0,modlo}) )) ;% C* |/ A, K+ T
(sqrt ( {1,0,modmd} * Sb * t({1,0,modmd}) )) ;! E; p/ ]: X! M E0 u" @! W
(sqrt ( {1,0,modhi} * Sb * t({1,0,modhi}) )) }.
% P* {5 @# Y/ i4 p: E6 f0 ^! }2 Qcompute tslopes = slopes &/ SEslopes .
8 _2 x" |0 o. y [# L/ Ycompute df = { (nc(1,1)-3-1) ; (nc(1,1)-3-1) ; (nc(1,1)-3-1) }.& m5 ]& ~. B0 Q' q: G- T
compute zslopes = slopes &* (sd(1,1)/sd(1,4)).( d& ?/ f& N# F: ~- @1 }6 l
compute zSE = SEslopes &* (sd(1,1)/sd(1,4)) .+ p" T) w9 j. o C) A
compute dfs = nc(1,1)-3-1 .
2 T; y3 N( \/ scompute pslopes = (1 - tcdf(abs(tslopes),dfs)) * 2.' W" S B3 l# X$ Q
$ I5 s3 I L3 A4 S: n$ x4 c' g# P
* df & t values -- from Darlington p 516 & Howell 87 p 586 -- p = 05 two-tailed .
5 i# i) `' Z% M5 D3 m+ h- q% 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,
. h& @4 d+ Z% u4 O' i+ K' i) h 30,32,34,36,38,40,43,46,49,52,56,60,65,70,75,80,85,90,95,100,110,120,130,4 K" v8 N. a F v- h: P
150,175,200,250,300,400,500,600,700,800,900,1000,1000000000;& q/ J/ I# ~8 N" |# f E
12.706,4.303,3.182,2.776,2.571,2.447,2.365,2.306,2.262,2.228,2.201,2.179,
' y, l5 }1 Q1 j& I 2.160,2.145,2.131,2.120,2.110,2.101,2.093,2.086,2.074,2.064,2.056,2.048,4 d0 z8 O4 R& n6 ~7 i/ X' g
2.042,2.037,2.032,2.028,2.024,2.021,2.017,2.013,2.010,2.007,2.003,2.000,. q" A l( U. H4 B( o
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* a2 B8 o- I& n. m$ ~. j. r 1.974,1.972,1.969,1.968,1.966,1.965,1.964,1.963,1.963,1.963,1.962,1.962 }.1 g$ `. z7 S6 j8 U
compute tabledT = 0.9 {; [! K$ F* x0 j3 l0 ?
loop #a = 1 to 59 .
p. K! g X( r' ?do if (dfs ge dft(1,#a) and dfs < dft(1,#a+1) ).
4 w# s+ Y: o* e- K8 Q/ mcompute tabledT = dft(2,#a) .; ?2 c/ G! m1 ~7 e2 f
end if.% t0 D2 z4 |; j8 C
end loop if (tabledT > 0).$ Y$ i+ f2 G3 X! s+ C1 w
compute confidLo = (zslopes - (tabledT &* zSE)) .
, {1 B* _0 E$ ^compute confidHi = (zslopes + (tabledT &* zSE)) ., @" K, t- F6 o R2 y
3 g9 l, T1 G. d+ T
print { aslopes , slopes , tslopes , df , pslopes} ) c2 j& ^$ y9 R7 }2 }
/title="Simple Slope Coefficients for the DV on the IDV at 3"
3 e4 ~* R) p3 Q) p* v: O+ " levels of the Moderator:"
7 C. g: s7 T) V$ r; F. h U& a /rlabels="Mod=low" "Mod=med" "Mod=high"; Y @4 Q: U. M7 t; G0 e
/clabels="a" "raw b" "t-test" "df" "Sig. T".
9 N% B" h9 j( n, N7 z" `print { zslopes , zSE , confidLO, confidHI } # w+ m$ \' d* u. ?$ t
/title="Standardized Simple Slopes & 95% Confidence Intervals: "8 s. \. I+ N) P# v% G3 f
/rlabels="Mod=low" "Mod=med" "Mod=high"
& T5 [( T& a9 M/ B: k a. G# u /clabels="std. beta" "SE" "95% Low" "95% Hi".
) `1 E9 |( L" T' W( wprint ((b(1,1)/b(1,3))*-1)/title="The simple slope for the DV on the IDV": l( M, E# E1 _" W
+ " is zero (flat) at Moderator =".5 m+ M1 K+ _9 F9 O
print ((b(1,2)/b(1,3))*-1)/title="The simple regression lines at "9 Z$ b+ |& A f. b% E0 P
+ "Mod=high and Mod=low intersect at IDV =".1 Q; X' H6 l. k
0 D" h6 R* y6 R$ r9 b0 f
% J& ?: ]8 A: o3 {% x* data for plot.
[) H& X* F+ F4 R: d2 A* v1 ocompute idvlo = mn(1,1) - (sd(1,1) * multiIDV).
0 i% ]4 N) @6 [" ]/ j, P7 Q8 ]compute idvhi = mn(1,1) + (sd(1,1) * multiIDV) .
$ Z9 q( H# M& }# ?* acompute idv = { idvlo; idvhi; idvlo; idvhi; idvlo; idvhi } .4 b% m* L" [5 }5 f$ T- F" u
do if (dichotom = 1).$ @1 Z/ }% x7 g8 P5 C, V) h; q( ~/ U
compute idv = { dichotLO;dichotHi; dichotLO;dichotHi; dichotLO;dichotHi }./ v; L, T! q9 V0 ^. g* d
end if.
- R; T8 c( B( N/ [2 E2 c9 c) ?* l0 Tcompute moder = { modlo;modlo;modmd;modmd;modhi;modhi }.
' A2 X6 |% I' e6 N* Z) Mcompute dv = (b(1,1)&*idv)+(b(1,2)&*moder)+(b(1,3)&*idv&*moder)+a.
0 \9 P; H# R* S: Icompute data = { idv , moder , dv }.! Y, Q# A6 i# G, w* H
9 @4 A% [# a" P# r9 ~
print data /title="Data for simple slope plots:" /clabels="IV" "Moderator" "DV" .
6 E2 } X. l! p0 C$ U
/ q6 z* }3 Z2 C6 |: E' vsave data /outfile=* / var=zb1 zb2 b3.
1 L% {7 x. F$ x
" L1 n0 N7 f$ }' [end matrix.
) `. R* V+ w' d/ K& j% E, |* h& B; h9 ^* B- |6 x) J
plot vsize=15 / hsize=50 / format=contour(3) / plot=b3 with zb1 by zb2.
3 s* f2 j* e8 j% K) vgraph / line = mean (b3) by b1 by b2.
! T3 J; t( d2 v4 F& U5 ? |
|