- 最后登录
- 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的名称就可以了。
) O+ u" q' ]8 Q: U: p
, Q5 n, J2 w: Z* h/ k/ y*****************.
, [ D) L6 o2 d& \) o) idesc b1 b2/save.6 t6 R# F+ l+ q
compute idv = zb1.0 ^ h( u* W, u% L
compute mod = zb2." R: K' l3 u: t# y
compute x = idv * mod.
0 B4 M- p! m# j/ f1 W \. Vcompute dv = b3.
( l9 ~8 u( {* U+ | `) l
$ \/ O% Z) L, K& {. D% n9 nregression 9 F9 p0 j I) Z
/matrix out ('filename')
* t5 J, x3 ?7 k e3 {; t/ `# Y /var= idv mod x dv
: i" \7 M, `0 s /statistics=defaults zpp bcov " i, B0 @/ P) X6 E- @
/dependent=dv; Q) x0 m2 t3 ^0 _- X- r1 J
/enter idv mod , Z/ r S8 _ ?- L8 z' L+ V
/test (x) .4 G* O9 e9 B, ~
2 t' ?2 c: E$ `3 d1 y3 N. ^: nset mxloops=65.
% t$ v) H! m, H7 c/ f9 n9 imatrix.
& _6 ]- j( r! p. l& A1 p2 c9 {$ i8 _8 B: l- n
compute multiMOD = 1.0 .
/ a+ m& Z' B+ E$ X6 l4 ]% h6 b% Jcompute multiIDV = 1.0 .% d; T* o( @+ N7 l- |) i
compute dichotom = 0 .
4 Q$ _/ L& k& S3 Gcompute dichotLo = 1 .
1 N' M) J' V* ?( d3 k* g: [. A2 @compute dichotHi = 2 .+ ^: l" M# w( C1 V1 b: ?
mget /file='filename'.- O6 A! P, T% P
/ E) j" q3 z9 `& E* Overall regression coeffs.
$ ^) S" V7 X; d! I- W. Vcompute beta = inv(cr(1:3,1:3)) * cr(1:3,4) .3 r: R& ^7 q/ v
compute b = (sd(1,4) &/ sd(1,1:3)) &* t(beta) .$ l- x& o6 G# E9 ~2 Z
compute a = mn(1,4) - ( rsum ( mn(1,1:3) &* b ) ) .# b: [1 j! \, U4 P" e
compute r2all = t(beta) * cr(1:3,4) .
% ?6 h2 K& h& ~6 a! mcompute r2main = t(inv(cr(1:2,1:2))*cr(1:2,4))*cr(1:2,4).
3 @( C" A9 O$ m" p: Dcompute r2chXn = r2all - r2main.
- V+ g9 [- d7 K6 gcompute fsquare = (r2all - r2main) / (1 - r2all) .: d0 I0 t, f) N2 k p
compute F = (r2all-r2main) / ((1-r2all)/(nc(1,1)-3-1)).7 B. U ?9 h3 p, B9 H2 l
compute dferror = nc(1,1) - 3 - 1. I6 {9 g1 F) J4 Q+ ]
compute pF = 1 - fcdf(F,1,dferror) .4 t; B, d' z& Z7 s; W
2 c/ B; i7 Q0 b, {& uprint {r2chXn,F,{1},dferror,fsquare,pF} /title="Coefficients for the Interaction"0 l ^; {; c! w1 X0 w
/clabels="Rsq. ch." "F" "df num." "df denom." "f-squared" "Sig. F".
- O1 o; S( m/ h: e! z! Lprint {t(b),beta} /title="Beta weights for the full equation:"# K' d0 R9 Y5 g6 k
/rlabels="idv" "mod" "Xn" /clabels="raw b" "std.beta" .
) J$ ?- t7 d; E% H7 S6 z) ?% Uprint a /title="The intercept is:" .% n h! c% f' d e# q% m+ I. M
1 l+ _. [ d( {( I$ M
( f7 B4 f; u+ s5 g* simple slopes info ." g+ { h( e9 v1 v
compute modlo = mn(1,2) - (sd(1,2) * multiMOD) .
, I; j5 F( K( G( {2 acompute modmd = mn(1,2).
: N1 _ }0 t: |: Z! _6 Jcompute modhi = mn(1,2) + (sd(1,2) * multiMOD) .. z- F2 a2 y, G- j. M- a/ e
compute slopes={(b(1,1)+(b(1,3)*modlo)) ;
" {5 y# g; g) B: f d9 ^& } (b(1,1)+(b(1,3)*modmd)) ; (b(1,1)+(b(1,3)*modhi)) }.2 L; D) k0 e& o
compute aslopes={ (b(1,2)*modlo+a) ; (b(1,2)*modmd+a) ; (b(1,2)*modhi+a) }.. S, g: Q; b, }1 R) N
compute mse = (nc(1,1)/(nc(1,1)-3))*(sd(1,4)**2)*(1-r2all).
% l( b c( c ^8 c7 A5 \compute Sb=mse*inv((mdiag(sd(1,1:3))*cr(1:3,1:3)*mdiag(sd(1,1:3)))*(nc(1,1)-1)).
5 T- }: f% t% ]! |( x9 xcompute SEslopes={ (sqrt ( {1,0,modlo} * Sb * t({1,0,modlo}) )) ;
/ X3 ~0 j0 Z3 f' [, ^ (sqrt ( {1,0,modmd} * Sb * t({1,0,modmd}) )) ;
, |/ f7 p5 a+ K6 e' A (sqrt ( {1,0,modhi} * Sb * t({1,0,modhi}) )) }.# T, Q1 J' \5 n4 ^( V$ [' _
compute tslopes = slopes &/ SEslopes .
+ w5 u+ r1 r7 L( s0 ycompute df = { (nc(1,1)-3-1) ; (nc(1,1)-3-1) ; (nc(1,1)-3-1) }.
; } O4 V5 W% h( C( G8 zcompute zslopes = slopes &* (sd(1,1)/sd(1,4)).. s& t9 K% u+ `4 D
compute zSE = SEslopes &* (sd(1,1)/sd(1,4)) .
! j) d! H* f3 d$ }# w5 tcompute dfs = nc(1,1)-3-1 .
4 \- a4 M& {+ Kcompute pslopes = (1 - tcdf(abs(tslopes),dfs)) * 2.
" i) K. y2 r4 u9 H3 B) N2 w- B% y, X9 u+ s
* df & t values -- from Darlington p 516 & Howell 87 p 586 -- p = 05 two-tailed .
1 y9 N- S) G C% k' }2 ycompute 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,
9 r- q3 d% `( _) r s' |, N 30,32,34,36,38,40,43,46,49,52,56,60,65,70,75,80,85,90,95,100,110,120,130,
& h) q: Q4 t% K4 R$ j 150,175,200,250,300,400,500,600,700,800,900,1000,1000000000;
% ]& c& j5 o1 }/ 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,5 [# U5 `6 J1 Q6 l( Q- `
2.160,2.145,2.131,2.120,2.110,2.101,2.093,2.086,2.074,2.064,2.056,2.048,
d- b! u# p& `2 K8 E; ` 2.042,2.037,2.032,2.028,2.024,2.021,2.017,2.013,2.010,2.007,2.003,2.000,( _1 J K! A- A q% E7 f
1.997,1.994,1.992,1.990,1.988,1.987,1.985,1.984,1.982,1.980,1.978,1.976,
7 _# g* O8 n4 E$ \3 \# u 1.974,1.972,1.969,1.968,1.966,1.965,1.964,1.963,1.963,1.963,1.962,1.962 }.( ^) Q! n; P% L* k& s7 T5 W4 R
compute tabledT = 0.1 R: l& D5 _5 b" s5 S
loop #a = 1 to 59 .
$ D6 T3 c; g' {% P/ `/ Gdo if (dfs ge dft(1,#a) and dfs < dft(1,#a+1) ).9 U# d) K/ ]: a
compute tabledT = dft(2,#a) .6 Q9 |7 ?. D' d8 {! V, o
end if. p- ^( j% }7 l
end loop if (tabledT > 0).% |+ G& f3 G% _& Y1 _
compute confidLo = (zslopes - (tabledT &* zSE)) .
: K6 ~8 r) v' D+ t( l7 P1 Y) Pcompute confidHi = (zslopes + (tabledT &* zSE)) ./ Y2 y4 [ L* _ B& N; H2 B
5 _! d- h6 Y, h9 m
print { aslopes , slopes , tslopes , df , pslopes}
; ~ G5 A; G. H3 t. `$ w /title="Simple Slope Coefficients for the DV on the IDV at 3"
: j0 M+ J$ l5 G; T n+ " levels of the Moderator:"
! u; ~% B- @0 i! S3 b9 j /rlabels="Mod=low" "Mod=med" "Mod=high"5 b+ S( j1 E) _% q# g1 Q, a
/clabels="a" "raw b" "t-test" "df" "Sig. T".0 J! z! f! K' S2 o4 j
print { zslopes , zSE , confidLO, confidHI }
% L! R2 f6 T6 O3 o3 l4 H /title="Standardized Simple Slopes & 95% Confidence Intervals: "! ]. \! \% }! p9 N. A: N) L
/rlabels="Mod=low" "Mod=med" "Mod=high"
% v9 m. f5 }6 O /clabels="std. beta" "SE" "95% Low" "95% Hi".
5 A$ j$ A, P H- Y3 {8 ~; |print ((b(1,1)/b(1,3))*-1)/title="The simple slope for the DV on the IDV"
$ W" L4 F9 z4 }+ " is zero (flat) at Moderator =".
" J5 ^/ @- A7 H! Q0 v8 @4 x3 Dprint ((b(1,2)/b(1,3))*-1)/title="The simple regression lines at "
8 M: R8 w# o8 v8 j% {7 K. ?) }+ "Mod=high and Mod=low intersect at IDV =".
' V1 J2 f* x1 j& t0 @5 X& j" t9 e; b) B5 A
* @2 t4 |1 V7 f* data for plot.5 S: t% b# O9 D0 S
compute idvlo = mn(1,1) - (sd(1,1) * multiIDV).2 S* l- a7 s9 R& [
compute idvhi = mn(1,1) + (sd(1,1) * multiIDV) .
8 a" z/ g5 x) g. b- Icompute idv = { idvlo; idvhi; idvlo; idvhi; idvlo; idvhi } .
3 u/ r& l$ f2 Kdo if (dichotom = 1).
- e& a0 S3 K ~5 q* `0 ]2 v. ecompute idv = { dichotLO;dichotHi; dichotLO;dichotHi; dichotLO;dichotHi }.
" v- H- v) j7 Pend if., X8 r7 w9 S9 J, u' |* t7 l8 @
compute moder = { modlo;modlo;modmd;modmd;modhi;modhi }.5 ^( `# q. d/ @$ Z/ G/ P+ r) d
compute dv = (b(1,1)&*idv)+(b(1,2)&*moder)+(b(1,3)&*idv&*moder)+a.; B( c6 \2 S) C7 t* L w" X
compute data = { idv , moder , dv }.
, r6 Z+ c: z3 [, _! ]
- I1 g! y q4 Q! ?' y+ n N3 s" p2 yprint data /title="Data for simple slope plots:" /clabels="IV" "Moderator" "DV" .
1 M! \4 V( ~0 }% f! V7 r& T
- I* c+ ^/ i6 E5 z0 K" E0 usave data /outfile=* / var=zb1 zb2 b3.5 |4 Z" h* I1 l8 G' J
8 Y1 K5 j v$ G- A& k8 g6 a# X
end matrix.
* n Q8 T" j1 Q" M0 Q& n
+ P( ?3 Y- m& M" n' [9 C7 `7 cplot vsize=15 / hsize=50 / format=contour(3) / plot=b3 with zb1 by zb2.
+ P4 b. q5 j+ S; y& ^2 t+ X$ Igraph / line = mean (b3) by b1 by b2.9 h# e7 x r; g" X
|
|