楼主: Alfred_G
8526 8

[回归分析求助] 【gof】对数线性模型中拟合优度无法做出 [推广有奖]

已卖:1287份资源

教授

38%

还不是VIP/贵宾

-

威望
0
论坛币
21223 个
通用积分
362.9526
学术水平
256 点
热心指数
263 点
信用等级
167 点
经验
95320 点
帖子
905
精华
2
在线时间
1403 小时
注册时间
2013-12-19
最后登录
2025-11-9

初级学术勋章 初级热心勋章 中级学术勋章 中级热心勋章

楼主
Alfred_G 学生认证  发表于 2015-5-3 19:38:28 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
如题:
    在做一个对数线性模型,模型部分都比较顺利,到后边拟合优度检验时候,出现gof或者estat gof无法显示,求解?
    已经检查过gof的安装,这个没有问题,help文件中的例子也能做出来,但是我现在用的模型做不出,烦请各位帮忙看下!
二维码

扫码加我 拉你入群

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

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

关键词:拟合优度 线性模型 拟合优度检验 estat 请各位帮忙 模型

2.png (8.98 KB)

2.png

1.png (20.73 KB)

1.png

回帖推荐

蓝色 发表于2楼  查看完整内容

有gof命令吗?为什么帮助不是你写的那样 Title [R] estat gof -- Pearson or Hosmer-Lemeshow goodness-of-fit test Syntax estat gof [weight] [, options] gof_options Description -------------------------------------------------------------------------------------------------------------- Main group(#) perform Hosmer-Lemeshow goodnes ...
知识和能力是在交流中增加的,平淡做人,认真做事,不功利,不急躁~

沙发
蓝色 发表于 2015-5-3 20:31:29
有gof命令吗?为什么帮助不是你写的那样

Title

    [R] estat gof -- Pearson or Hosmer-Lemeshow goodness-of-fit test


Syntax

        estat gof [if] [in] [weight] [, options]

    gof_options           Description
    --------------------------------------------------------------------------------------------------------------
    Main
      group(#)            perform Hosmer-Lemeshow goodness-of-fit test using # quantiles
      all                 execute test for all observations in the data
      outsample           adjust degrees of freedom for samples outside estimation sample
      table               display table of groups used for test
    --------------------------------------------------------------------------------------------------------------
    fweights are allowed; see weight.
    estat gof is not appropriate after the svy prefix.


Menu for estat

    Statistics > Postestimation > Reports and statistics


Description

    estat gof reports the Pearson goodness-of-fit test or the Hosmer-Lemeshow goodness-of-fit test.

    estat gof requires that the current estimation results be from logistic, logit, or probit.  For estat gof
    after poisson, see [R] poisson postestimation.  For estat gof after sem, see [SEM] estat gof.


Options

        +------+
    ----+ Main +--------------------------------------------------------------------------------------------------

    group(#) specifies the number of quantiles to be used to group the data for the Hosmer-Lemeshow
        goodness-of-fit test.  group(10) is typically specified.  If this option is not given, the Pearson
        goodness-of-fit test is computed using the covariate patterns in the data as groups.

    all requests that the statistic be computed for all observations in the data, ignoring any if or in
        restrictions specified by the estimation command.

    outsample adjusts the degrees of freedom for the Pearson and Hosmer-Lemeshow goodness-of-fit tests for samples
        outside the estimation sample.  See Samples other than the estimation sample in [R] estat gof.

    table displays a table of the groups used for the Hosmer-Lemeshow or Pearson goodness-of-fit test with
        predicted probabilities, observed and expected counts for both outcomes, and totals for each group.


Examples

    Setup
        . webuse lbw

    Fit logistic regression to predict low birth weight
        . logistic low age lwt i.race smoke ptl ht ui

    Perform goodness-of-fit test
        . estat gof

    Same as above, but use 10 quantiles
        . estat gof, group(10)

    Same as above, but display table of groups used for test
        . estat gof, group(10) table

藤椅
rudi 发表于 2015-5-3 21:08:05
estat不能省啊

板凳
Alfred_G 学生认证  发表于 2015-5-3 21:42:36
蓝色 发表于 2015-5-3 20:31
有gof命令吗?为什么帮助不是你写的那样

Title
非常感谢蓝色版主!
我用的是Treiman在《量化数据分析》第十二章中的那个例子,在做这个模型时候,他的例题do文件和log文件都给了出来,在那里确实gof是可以跑出来的。但是他的do文件在我这里却弄不出来,而且,我也试过estat gof,弄不出来结果。我一会儿把那个也截下图,请版主帮忙再看下

报纸
Alfred_G 学生认证  发表于 2015-5-3 21:45:42
/*********************************************************************
2) Get goodness-of-fit statistics for Table 12.2, shown in Table 12.3.
**********************************************************************/

*Define s=stratification, t=technology, and p=political integration.

infile s t p count using tab12_2.raw , clear
list /*Confirm that I have read in the data correctly*/

*Estimate the baseline model (Table 12.3, Model 1).

xi : glm count i.t i.p i.s , family(poisson)

/*Create a scalar: baseline deviance (bd).  I will use this to get the
ratio of the deviance for each subsequent model to the deviance for
the baseline model.*/

scalar bd = e(deviance)

/*Get goodness-of-fit statistics for this model.  Since I am going to
invoke the same commands many times, I have written an -ado- file -gof.ado-,
to get all the statistics I need for Table 12.3 that are not shown in the
Stata output.*/

gof

*Now I get the corresponding statistics for the remaining models (Table 12.3).

/*Note that Stata now has a built in BIC function.  However, for our purposes
the BIC estimates from the -glm- command are misleading because they treat
the number of cells in the table rather than the total number of cases used
in the analysis as the sample.  However, it is possible to override the
default count.  For the first two models in the next set of models estimated,
I have used the -glm- postestimation command, -estat- to estimate BIC,
substituting the correct N, the number of cases in the table rather than the
number of cells.  -estat- yields estimates of BIC that are different from
the estimates I derive from -gof- (which follow the formula provided by
Raftery 1995).  However, as you can see, the difference between BICs for the
two models are identical regardless of which version of BIC is estimated.*/

*First get the total number of cases in the table.;

egen freq = total(count)
tab freq  

*Then estimate BIC as a -glm- postestimation command for the first two models.

xi : glm count i.t i.p*i.s , family(poisson)
estat ic , n(92)
gof
xi : glm count i.p i.t*i.s , family(poisson)
estat ic , n(92)
gof
xi : glm count i.s i.t*i.p , family(poisson)
gof
xi : glm count i.t*i.p i.t*i.s , family(poisson)
gof
xi : glm count i.t*i.p i.p*i.s , family(poisson)
gof
xi : glm count i.t*i.s i.p*i.s , family(poisson)
gof
xi : glm count i.t*i.p i.t*i.s i.p*i.s , family(poisson)
gof

3.png (17.91 KB)

3.png

知识和能力是在交流中增加的,平淡做人,认真做事,不功利,不急躁~

地板
Alfred_G 学生认证  发表于 2015-5-3 21:47:09
rudi 发表于 2015-5-3 21:08
estat不能省啊
嗯,谢谢层主的回复。
我这里也加上了estat,同样也是不行的

7
蓝色 发表于 2015-5-4 08:12:36
http://www.ccpr.ucla.edu/dtreiman/quantitative-data-analysis-stata-files-and-data-sets
你的这个gof是作者自己编写的
你下载拷贝到自己电脑上就可以了

8
Alfred_G 学生认证  发表于 2015-5-4 09:09:13
蓝色 发表于 2015-5-4 08:12
http://www.ccpr.ucla.edu/dtreiman/quantitative-data-analysis-stata-files-and-data-sets
你的这个gof是 ...
对,昨天晚上已经解决,找到ado文件。他在注释里写到了
/*Get goodness-of-fit statistics for this model.  Since I am going to
invoke the same commands many times, I have written an -ado- file -gof.ado-,
to get all the statistics I need for Table 12.3 that are not shown in the
Stata output.*/
之前没注意读,太大意了。
非常感谢版主的帮助!

9
未名湖的猫 发表于 2017-3-29 19:09:30
请问这个 estat gof 跑出的结果,prob>chi2,值是越大说明拟合度越好吗?谢谢啦

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-30 03:16