全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
8030 4
2006-02-22
急用啊,各位xdjm,请多多帮助啊!如何用sas或者stata对数据进行boxcox正态性变换?对原始数据有何要求?数据是不是不能为零啊?

[此贴子已经被作者于2006-2-22 16:51:20编辑过]

二维码

扫码加我 拉你入群

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

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

全部回复
2006-2-23 03:25:00

%macro boxcox(phimin=,phimax=, steps=, model=, class=, stmts=, data=, response=);

/***********************************************************/

/* This macro performs thr Box-Cox-Power Transformation */

/* Box, G. E. P. and Cox, D. R. (1964) An analysis of */

/* transformations (with discussion). */

/* J. R. Statist. Soc. B., 26, 211-246. */

/* */

/* phimin = smallest phi */

/* phimax = largest phi */

/* steps = number of steps in grid search */

/* class = list of variables for class statment */

/* model = list of terms in model statement */

/* stmts = %str(other mixed statements, incl. random) */

/* data = dataset with original data */

/* response = name of response variable in dataset */

/* */

/***********************************************************/

data t;

set &data;

phi=&phimin;

size=(&phimax-&phimin)/&steps;

do i=0 to &steps;

if phi ne 0 then _y_=(&response**phi-1)/phi;

if abs(phi)<1e-10 then _y_=log(&response);

jac=(phi-1)*log(&response);

output;

phi=phi+size;

end;

proc sort data=t out=t;

by phi;

run;

ods output fitstatistics=fit;

proc mixed data=t method=ml;

class &class;

model _y_=&model;

&stmts;

by phi;

run;

data fit2;

set fit;

if descr='-2 Log Likelihood';

loglik=-value/2;

proc means data=t;

var jac;

output out=jac sum=;

by phi;

run;

data loglik;

merge jac fit2;

loglik=loglik+jac;

proc print data=loglik;

run;

symbol value=dot i=join;

proc gplot data=loglik;

plot loglik*phi;

run;

proc means data=loglik;

var loglik;

id phi;

output out=max max=max;

run;

data r;

if _n_=1 then set max;

set loglik;

if loglik=max;

title 'Optimal value of phi';

proc print data=r;

var phi loglik;

run;

title ' ';

%mend;

二维码

扫码加我 拉你入群

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

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

2006-4-14 05:39:00

Stata help for boxcox

help boxcox dialog: boxcox also see: boxcox postestimation -------------------------------------------------------------------------------

Title

[R] boxcox -- Box-Cox regression models

Syntax

boxcox depvar [indepvars] [if] [in] [weight] [, options]

options description ------------------------------------------------------------------------- Model noconstant suppress constant term model(lhsonly) left-hand-side Box-Cox model; the default model(rhsonly) right-hand-side Box-Cox model model(lambda) both sides Box-Cox model with same parameter model(theta) both sides Box-Cox model with different parameters notrans(varlist) nontransformed independent variables

Reporting level(#) set confidence level; default is level(95) lrtest perform likelihood-ratio test

Max options nolog suppress full-model iteration log nologlr suppress restricted-model lrtest iteration log maximize_options control the maximization process; seldom used ------------------------------------------------------------------------- depvar and indepvars may contain time-series operators; see tsvarlist. bootstrap, by, jackknife, rolling, statsby, and xi are allowed; see prefix. fweights and iweights are allowed; see weight. See boxcox postestimation for features available after estimation.

Description

boxcox finds the maximum likelihood estimates of the parameters of the Box-Cox transform, the coefficients on the independent variables, and the standard deviation of the normally distributed errors for a model in which depvar is regressed on indepvars. The user has the option of transforming either the depvar, some of the indepvars, both the depvar and some of the indepvars with the same transformation parameter, or both the depvar and some of the indepvars with different transformation parameters. Any transformed variable must be strictly positive.

Options

+-------+ ----+ Model +------------------------------------------------------------

noconstant; see estimation options.

model(lhsonly|rhsonly|lambda|theta) specifies which of the four models to fit.

model(lhsonly) applies the Box-Cox transform to depvar only. model(lhsonly) is the default.

model(rhsonly) applies the transform to the indepvars only.

model(lambda) applies the transform to both depvar and indepvars, and they are transformed by the same parameter.

model(theta) applies the transform to both depvar and indepvars, but this time, each side is transformed by a separate parameter.

notrans(varlist) specifies that the variables in varlist be included as nontransformed independent variables.

+-----------+ ----+ Reporting +--------------------------------------------------------

level(#); see estimation options.

lrtest specifies that a likelihood-ratio test of significance be performed and reported for each independent variable.

+-------------+ ----+ Max options +------------------------------------------------------

nolog suppresses the iteration log when fitting the full model.

nologlr suppresses the iteration log when fitting the restricted models required by the lrtest option.

maximize_options: iterate(#) and from(init_specs); see maximize.

Model Initial value specification --------------------------------------- lhsonly from(#_t, copy) rhsonly from(#_l, copy) lambda from(#_l, copy) theta from(#_l #_t, copy) ---------------------------------------

Examples

. boxcox mpg weight price, notrans(foreign) model(theta) lrtest

. boxcox mpg weight price foreign, model(lhs) lrtest nolog nologlr

. boxcox mpg weight price, model(lambda) lrtest

. boxcox mpg weight price, notrans(foreign) model(rhs)

. boxcox mpg weight price, notrans(foreign) model(lhsonly) lrtest

Also see

Manual: [R] boxcox

Online: boxcox postestimation; lnskew0, regress

二维码

扫码加我 拉你入群

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

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

2015-7-9 15:26:52
可以在SAS帮助中键入BOXCOX搜索,会得到说明;
建议读一下陈峰的《现代医学统计学与Stata应用》,实际上,用Stata做要便捷许多,几乎是自动化完成参数寻找的。SAS很繁琐,帮助中有例子。
二维码

扫码加我 拉你入群

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

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

2015-8-5 00:31:42
matlab-007 发表于 2015-7-9 15:26
可以在SAS帮助中键入BOXCOX搜索,会得到说明;
建议读一下陈峰的《现代医学统计学与Stata应用》,实际上, ...
https://bbs.pinggu.org/forum.php?mod=viewthread&tid=3839105&extra=
大神能不能帮忙看一下,然后陈锋的书是在案例中描述的boxcox转换么?
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群