SAS中的泊松回归GLM

时间:2015-02-15 17:58:09

标签: r sas regression poisson

我尝试在SAS中使用泊松回归通用线性模型。

我是R用户,所以我不知道如何在SAS中执行此操作。我将发布数据以及我已尝试过的代码:

  Game     Success     Attempts
  1        4             5 
  2        5             11
  3        5             14
  4        5             12
  5        2             7
  6        7             10
  7        6             14
  8        9             15
  9        4             12
 10        1              4
 11        13            27
 12        5             17
 13        6             12
 14        9              9
 15        7             12
 16        3             10
 17        8             12
 18        1              6
 19        18            39
 20        3             13
 21        10            17
 22        1              6 
 23        3             12

我已尝试在数据上使用多个不同的代码,但我一直收到错误。

此代码不适用于初始输入:

options nocenter;

data freethrows;

input $attempt $success;

datalines;

...(this is where I put each attempt and success for each game in each row     for 23 rows)

;

run;

SAS网站上的示例如下:

data insure;

      input n c car$ age;

      ln = log(n);

      datalines;

   500   42  small  1

   1200  37  medium 1

   100    1  large  1

   400  101  small  2

   500   73  medium 2

   300   14  large  2

   ;

   run;

GENMOD程序如下:

proc genmod data=insure;

      class car age;

      model c = car age / dist   = poisson

                      link   = log

                      offset = ln;

   run;

我想对freethrows进行类似的分析。

1 个答案:

答案 0 :(得分:1)

需要取出美元符号,因为那些迫使变量被视为"字符"而不是数字。将使用" Game"作为预测变量。试试这个:

data games;
  input Game Success Attempts;
  lnAtt = log(Attempts);
  datalines;
  1        4             5 
  2        5             11
  3        5             14
  4        5             12
  5        2             7
  6        7             10
  7        6             14
  8        9             15
  9        4             12
 10        1              4
 11        13            27
 12        5             17
 13        6             12
 14        9              9
 15        7             12
 16        3             10
 17        8             12
 18        1              6
 19        18            39
 20        3             13
 21        10            17
 22        1              6 
 23        3             12
;
run;

然后执行PROC:

proc genmod data=games;
      #  remove unless you have categorical variables; class car age;
      model Success = Game  / dist   = poisson
                      link   = log
                      offset = lnAtt;
   run;

这应该是对玩家体验的调整和某些成功的影响的测试,即对成功概率的线性趋势的测试。随着游戏数量的增加。作为对R的结果的检查:

    summary(glm(Success ~Game, offset=log(Attempts), family="poisson", data=games) )
#---------------------
Call:
glm(formula = Success ~ Game, family = "poisson", data = games, 
    offset = log(Attempts))

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-1.1957  -0.7962  -0.2722   0.6774   2.1110  

Coefficients:
             Estimate Std. Error z value Pr(>|z|)    
(Intercept) -0.679572   0.189074  -3.594 0.000325 ***
Game        -0.008375   0.013544  -0.618 0.536346    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for poisson family taken to be 1)

    Null deviance: 18.778  on 22  degrees of freedom
Residual deviance: 18.396  on 21  degrees of freedom
AIC: 100.72

Number of Fisher Scoring iterations: 4

所以系数接近于零(其中正值表示随着游戏数增加而成功的概率增加),并且实际上没有统计证据表明存在上升趋势。