楼主: qzyanmo
16183 15

[问答] 用SPSS做岭回归时,在进行语法编辑时遇到问题 [推广有奖]

  • 0关注
  • 1粉丝

初中生

71%

还不是VIP/贵宾

-

威望
0
论坛币
30 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
198 点
帖子
12
精华
0
在线时间
9 小时
注册时间
2014-5-17
最后登录
2014-5-20

楼主
qzyanmo 发表于 2014-5-18 16:20:13 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
INCLUDE 'F:\Samples\English\Ridge regerssion.sps'.
ridgereg enter=L E F
/dep=Y
/inc=0.01
输入此段代码后,遇到:
线    命令            信息
1     INCLUDE      文件未找到
2     ridgereg        行中第一个单词未被识别为an spss statistics 命令
想请教一下各位这个是什么情况,急啊!!!!!!!!

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:SPSS 岭回归 PSS Statistics statistic English 单词 信息

沙发
ReneeBK 发表于 2014-5-19 07:07:42
The reason is 文件未找到. You can try to place  the file"Ridge regerssion.sps" at C:\Program Files\IBM\SPSS\Statistics.

藤椅
ReneeBK 发表于 2014-5-19 07:08:18
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 bvec={b,seb,beta,ratio}.
. print bvec/title='--------------Variables in the Equation----------------'
  /rnames=rnms /clabels='B' 'SE(B)' 'Beta' 'B/SE(B)'.
. 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'.

plot
  /format=overlay /title='RIDGE TRACE'
  /horizontal 'K'
  /vertical 'RR Coefficients'
  /plot !enter with k
  /title='R-SQUARE VS. K'
  /horizontal 'K'
  /vertical 'R-Square'
  /plot rsq with k.

!ifend.

*---------------------------------------------------------------------------.
* Get back original data set and restore original settings.
*---------------------------------------------------------------------------.

get file=rr__tmp1.sav.
restore.
!enddefine.
restore.

板凳
qzyanmo 发表于 2014-5-19 14:02:36
好人啊,不过我已经解决这个问题了哈,非常感谢哈

报纸
fandi1994 发表于 2015-4-25 13:12:52
qzyanmo 发表于 2014-5-19 14:02
好人啊,不过我已经解决这个问题了哈,非常感谢哈
你好!我也遇到了和你同样的问题,请问你是怎么解决的?

地板
浅丶忆 发表于 2016-4-27 17:35:40
fandi1994 发表于 2015-4-25 13:12
你好!我也遇到了和你同样的问题,请问你是怎么解决的?
spss17.0做岭回归分析语法输入后老是提示错误,或是文件找不到,是为什么啊

7
wang_wanjun1988 发表于 2016-5-1 10:05:49
浅丶忆 发表于 2016-4-27 17:35
spss17.0做岭回归分析语法输入后老是提示错误,或是文件找不到,是为什么啊
您好,我也是总提示语法错误和找不到文件,我和同学都用的22,我是win8系统,他是win7系统,他的能用。您解决了吗?可否赐教。

8
yang1204 发表于 2016-6-20 14:58:50
qzyanmo 发表于 2014-5-19 14:02
好人啊,不过我已经解决这个问题了哈,非常感谢哈
请问楼主最后是咋解决的啊 我现在也遇到   ridgereg   行中第一个单词未被识别为an spss statistics 命令。麻烦了

9
yang1204 发表于 2016-6-20 15:01:36
wang_wanjun1988 发表于 2016-5-1 10:05
您好,我也是总提示语法错误和找不到文件,我和同学都用的22,我是win8系统,他是win7系统,他的能用。您 ...
请问同学这个问题现在解决了吗 我也遇到同样的问题

10
小小心窝 发表于 2016-10-10 11:54:58
qzyanmo 发表于 2014-5-19 14:02
好人啊,不过我已经解决这个问题了哈,非常感谢哈
您好,请问您是怎么解决的,我也出现了首字母识别不了的情况,非常感谢

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-20 03:42