楼主: Braveheartdeng
43143 70

[学习资料] 关于SPSS不能给出岭回归显著性检验(t,p)的解决方案   [推广有奖]

11
422028326 发表于 2011-5-23 16:03:24 |只看作者 |坛友微信交流群
请问楼主,VIF值可以一起输出吗

使用道具

12
nkunku 发表于 2011-5-26 09:08:05 |只看作者 |坛友微信交流群
422028326 发表于 2011-5-23 16:03
请问楼主,VIF值可以一起输出吗
我也非常想知道。楼主能不能为大家再作一些贡献?

使用道具

13
whitezc 发表于 2011-10-6 16:43:37 |只看作者 |坛友微信交流群
拜读,谢谢了。

使用道具

14
zhangsj913 发表于 2011-10-21 08:24:25 |只看作者 |坛友微信交流群
提示: 作者被禁止或删除 内容自动屏蔽

使用道具

15
温柔一cai刀 发表于 2011-12-7 19:33:08 |只看作者 |坛友微信交流群
完全正确的,这是我的程序:打开语法编辑器,复制下面代码,保存在桌面即可。
preserve.
set printback=off.
define ridgereg (enter=!charend('/')
                /dep = !charend('/')
                /start=!default(0) !charend('/')
                /stop=!default(1) !charend('/')
                /inc=!default(.05) !charend('/')
                /k=!default(999) !charend('/')
                /debug=!DEFAULT ('N')!charend('/')  ).
preserve.
!IF ( !DEBUG !EQ 'N') !THEN
set printback=off mprint off.                                                   
!ELSE
set printback on mprint on.
!IFEND .
SET mxloops=200.
*---------------------------------------------------------------------------.
* Save original active file to give back after macro is done.
*---------------------------------------------------------------------------.
!IF (!DEBUG !EQ 'N') !THEN
SET RESULTS ON.
DO IF $CASENUM=1.
PRINT / "NOTE: ALL OUTPUT INCLUDING ERROR MESSAGES HAVE BEEN TEMPORARILY"
      / "SUPPRESSED. IF YOU EXPERIENCE UNUSUAL BEHAVIOR, RERUN THIS"
      / "MACRO WITH AN ADDITIONAL ARGUMENT /DEBUG='Y'."  
      / "BEFORE DOING THIS YOU SHOULD RESTORE YOUR DATA FILE."
      / "THIS WILL FACILITATE FURTHER DIAGNOSIS OF ANY PROBLEMS.".
END IF.
!IFEND .
save outfile='rr__tmp1.sav'.
*---------------------------------------------------------------------------.
* Use CORRELATIONS to create the correlation matrix.
*---------------------------------------------------------------------------.
* DEFAULT:  SET RESULTS AND ERRORS OFF TO SUPPRESS CORRELATION PIVOT TABLE *.
!IF (!DEBUG='N') !THEN
set results off errors off.
!IFEND
correlations variables=!dep !enter /missing=listwise/matrix out(*).
set errors on results listing .
*---------------------------------------------------------------------------.
* Enter MATRIX.
*---------------------------------------------------------------------------.
matrix.
*---------------------------------------------------------------------------.
* Initialize k, increment, and  number of iterations. If k was not
* specified, it is 999 and looping will occur. Otherwise, just the one
* value of k will be used for estimation.
*---------------------------------------------------------------------------.
do if (!k=999).
. compute k=!start.
. compute inc=!inc.
. compute iter=trunc((!stop - !start ) / !inc ) + 1.
. do if (iter <= 0).
.   compute iter = 1.
. end if.
else.
. compute k=!k.
. compute inc=0.
. compute iter=1.
end if.
*---------------------------------------------------------------------------.
* Get data from working matrix file.
*---------------------------------------------------------------------------.
get x/file=*/names=varname/variable=!dep !enter.
*---------------------------------------------------------------------------.
* Third row of matrix input is the vector of Ns. Use this to compute number
* of variables.
*---------------------------------------------------------------------------.
compute n=x(3,1).
compute nv=ncol(x)-1.
*---------------------------------------------------------------------------.   
* Get variable names.
*---------------------------------------------------------------------------.
compute varname=varname(2:(nv+1)).
*---------------------------------------------------------------------------.
* Get X'X matrix (or R, matrix of predictor correlations) from input data
* Also get X'Y, or correlations of predictors with dependent variable.
*---------------------------------------------------------------------------.
compute xpx=x(5:(nv+4),2:(nv+1)).
compute xy=t(x(4,2:(nv+1))).
*---------------------------------------------------------------------------.
* Initialize the keep matrix for saving results, and the names vector.
*---------------------------------------------------------------------------.
compute keep=make(iter,nv+2,-999).
compute varnam2={'K','RSQ',varname}.
*---------------------------------------------------------------------------.
* Compute means and standard deviations. Means are in the first row of x and
* standard deviations are in the second row. Now that all of x has been
* appropriately stored, release x to maximize available memory.
*---------------------------------------------------------------------------.
compute xmean=x(1,2:(nv+1)).
compute ybar=x(1,1).
compute std=t(x(2,2:(nv+1))).
compute sy=x(2,1).
release x.
*---------------------------------------------------------------------------.
* Start loop over values of k, computing standardized regression
* coefficients and squared multiple correlations. Store results
*---------------------------------------------------------------------------.
loop l=1 to iter.
. compute b = inv(xpx+(k &* ident(nv,nv)))*xy.
. compute rsq= 2* t(b)*xy - t(b)*xpx*b.
. compute keep(l,1)=k.
. compute keep(l,2)=rsq.
. compute keep(l,3:(nv+2))=t(b).
. compute k=k+inc.
end loop.
*---------------------------------------------------------------------------.
* If we are to print out estimation results, compute needed pieces and
* print out header and ANOVA table.
*---------------------------------------------------------------------------.
do if (!k <> 999).
.!let !rrtitle=!concat('****** Ridge Regression with k = ',!k).
.!let !rrtitle=!quote(!concat(!rrtitle,' ****** ')).
. compute sst=(n-1) * sy **2.
. compute sse=sst * ( 1 - 2* t(b)*xy + t(b)*xpx*b).
. compute ssr = sst - sse.
. compute s=sqrt( sse / (n-nv-1) ).
. print /title=!rrtitle /space=newpage.
. print {sqrt(rsq);rsq;rsq-nv*(1-rsq)/(n-nv-1);s}
/rlabel='Mult R' 'RSquare' 'Adj RSquare' 'SE'
/title=' '.
. compute anova={nv,ssr,ssr/(nv);n-nv-1,sse,sse/(n-nv-1)}.
. compute f=ssr/sse * (n-nv-1)/(nv).
. print anova
   /clabels='df' 'SS','MS'
   /rlabel='Regress' 'Residual'
   /title='         ANOVA table'
   /format=f9.3.
.  compute test=ssr/sse * (n-nv-1)/nv.
.  compute sigf=1 - fcdf(test,nv,n-nv-1).
.  print {test,sigf} /clabels='F value' 'Sig F'/title=' '.
*---------------------------------------------------------------------------.
* Calculate raw coefficients from standardized ones, compute standard errors
* of coefficients, and an intercept term with standard error. Then print
* out similar to REGRESSION output.
*---------------------------------------------------------------------------
. compute beta={b;0}.
. compute b= ( b &/ std ) * sy.
. compute intercpt=ybar-t(b)*t(xmean).
. compute b={b;intercpt}.
. compute xpx=(sse/(sst*(n-nv-1)))*inv(xpx+(k &* ident(nv,nv)))*xpx*
                                 inv(xpx+(k &* ident(nv,nv))).
. compute xpx=(sy*sy)*(mdiag(1 &/ std)*xpx*mdiag(1 &/ std)).
. compute seb=sqrt(diag(xpx)).
. compute seb0=sqrt( (sse)/(n*(n-nv-1)) + xmean*xpx*t(xmean)).
. compute seb={seb;seb0}.
. compute rnms={varname,'Constant'}.
. compute ratio=b &/ seb.
. compute ppp=2*(1-tcdf(abs(ratio),n-nv-1)).
.compute bvec={b,seb,beta,ratio,ppp}.
. print bvec/title='--------------Variables in the Equation----------------'
  /rnames=rnms /clabels='B' 'SE(B)' 'Beta' 'T' 'sig'.  
. print /space=newpage.
end if.
*---------------------------------------------------------------------------.
* Save kept results into file. The number of cases in the file will be
* equal to the number of values of k for which results were produced. This
* will be simply 1 if k was specified.
*---------------------------------------------------------------------------.
save keep /outfile='rr__tmp2.sav' /names=varnam2.
*---------------------------------------------------------------------------.
* Finished with MATRIX part of job.
*---------------------------------------------------------------------------.
end matrix.
*---------------------------------------------------------------------------.
* If doing ridge trace, get saved file and produce table and plots.
*---------------------------------------------------------------------------.
!if (!k = 999) !then
get file='rr__tmp2.sav'.
print formats k rsq (f6.5) !enter (f8.6).
report format=list automatic
/vars=k rsq !enter
/title=center 'R-SQUARE AND BETA COEFFICIENTS FOR ESTIMATED VALUES OF K'.
graph
  /title = 'RIDGE TRACE'
  /footnote = 'K'
  /scatterplot(overlay) k with !enter.
graph
  /title = 'R-SQUARE VS. K'
  /scatterplot k with rsq.
!ifend.
*---------------------------------------------------------------------------.
* Get back original data set and restore original settings.
*---------------------------------------------------------------------------.
get file=rr__tmp1.sav.
restore.
!enddefine.
restore.

下面是运行

ridgereg dep=y/enter x2 x3 x4 x5/k=0.08.

的输出结果;跟书上完全一样

360截图20111207193311578.jpg (36.13 KB)

360截图20111207193311578.jpg

使用道具

16
chrisjin 发表于 2011-12-14 21:04:49 |只看作者 |坛友微信交流群
为什么我每次做岭回归的时候总是会出现这个错误>Error # 34 in column 20.  Text: rr__tmp2.sav
>PASW Statistics cannot access a file with the given file specification.  The
>file specification is either syntactically invalid, specifies an invalid
>drive, specifies a protected directory, specifies a protected file, or
>specifies a non-sharable file.
>Execution of this command stops.
好心人能给我解决一下嘛 ,万分感谢

使用道具

17
wddfly 在职认证  发表于 2011-12-16 12:29:40 |只看作者 |坛友微信交流群
实验一下

使用道具

18
luwei005 发表于 2012-8-21 13:58:06 |只看作者 |坛友微信交流群
真的可以 太谢谢楼主啦

使用道具

19
不懂的 发表于 2012-9-23 15:00:32 |只看作者 |坛友微信交流群
试过了,成功,大谢,居然顶的人这么少

使用道具

20
yjystr 发表于 2012-10-19 05:51:44 |只看作者 |坛友微信交流群
非常感谢楼主,准备用自己论文的数据算一下。
有个问题是:面板数据的岭回归该如何计算?

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-27 08:12