. do "C:\Users\DEFAUL~1.SID\AppData\Local\Temp\STD00000000.tmp"

. * do-file for lecture 12 of VHM 802, Winter 2016
. version 14 /* works also with version 13 */

. set more off

. cd "h:\vhm\vhm802\data_csv"
h:\vhm\vhm802\data_csv

.
. import delimited guinea_long.csv, clear
(4 vars, 90 obs)

. * profile plots
. twoway (connected weight week), by(group  animal)

. overlay weight week, by(animal) c(l)

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
      weight |         90       559.1    58.90881        436        702

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
        week |         90    4.333333    1.983074          1          7

. overlay weight week if group==1, by(animal) c(l) /* similar for groups 2,3 */
(60 observations deleted)

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
      weight |         30    539.1333    57.39022        436        619

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
        week |         30    4.333333    2.005739          1          7

. * mean plot
. preserve /* run together with next 2 lines */

. collapse (mean) weight, by(group week)

. overlay weight week, by(group) c(l)

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
      weight |         18       559.1    44.83503      466.4        644

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
        week |         18    4.333333    2.029199          1          7

.
end of do-file

. do "C:\Users\DEFAUL~1.SID\AppData\Local\Temp\STD00000000.tmp"

. * disregarding repeated measures (wrong!)
. anova weight group##week

                         Number of obs =         90    R-squared     =  0.5532
                         Root MSE      =    43.7777    Adj R-squared =  0.4477

                  Source | Partial SS         df         MS        F    Prob>F
              -----------+----------------------------------------------------
                   Model |   170865.3         17     10050.9      5.24  0.0000
                         |
                   group |  18548.067          2   9274.0333      4.84  0.0107
                    week |   142554.5          5     28510.9     14.88  0.0000
              group#week |  9762.7333         10   976.27333      0.51  0.8781
                         |
                Residual |   137986.8         72   1916.4833
              -----------+----------------------------------------------------
                   Total |   308852.1         89   3470.2483

. * separate analyses for each week
. bysort week: oneway weight group

-------------
-> week = 1

                        Analysis of Variance
    Source              SS         df      MS            F     Prob > F
------------------------------------------------------------------------
Between groups          2969.2      2       1484.6      2.10     0.1651
 Within groups          8481.2     12   706.766667
------------------------------------------------------------------------
    Total              11450.4     14   817.885714

Bartlett's test for equal variances:  chi2(2) =   1.4766  Prob>chi2 = 0.478

-------------
-> week = 3

                        Analysis of Variance
    Source              SS         df      MS            F     Prob > F
------------------------------------------------------------------------
Between groups          2497.6      2       1248.8      0.87     0.4427
 Within groups         17170.4     12   1430.86667
------------------------------------------------------------------------
    Total                19668     14   1404.85714

Bartlett's test for equal variances:  chi2(2) =   0.4744  Prob>chi2 = 0.789

-------------
-> week = 4

                        Analysis of Variance
    Source              SS         df      MS            F     Prob > F
------------------------------------------------------------------------
Between groups      302.533333      2   151.266667      0.14     0.8710
 Within groups         12992.4     12       1082.7
------------------------------------------------------------------------
    Total           13294.9333     14   949.638095

Bartlett's test for equal variances:  chi2(2) =   0.5086  Prob>chi2 = 0.775

-------------
-> week = 5

                        Analysis of Variance
    Source              SS         df      MS            F     Prob > F
------------------------------------------------------------------------
Between groups           260.4      2        130.2      0.05     0.9476
 Within groups           28906     12   2408.83333
------------------------------------------------------------------------
    Total              29166.4     14   2083.31429

Bartlett's test for equal variances:  chi2(2) =   0.9006  Prob>chi2 = 0.637

-------------
-> week = 6

                        Analysis of Variance
    Source              SS         df      MS            F     Prob > F
------------------------------------------------------------------------
Between groups      8550.93333      2   4275.46667      1.39     0.2863
 Within groups           36898     12   3074.83333
------------------------------------------------------------------------
    Total           45448.9333     14   3246.35238

Bartlett's test for equal variances:  chi2(2) =   0.6487  Prob>chi2 = 0.723

-------------
-> week = 7

                        Analysis of Variance
    Source              SS         df      MS            F     Prob > F
------------------------------------------------------------------------
Between groups      13730.1333      2   6865.06667      2.46     0.1276
 Within groups         33538.8     12       2794.9
------------------------------------------------------------------------
    Total           47268.9333     14   3376.35238

Bartlett's test for equal variances:  chi2(2) =   1.1559  Prob>chi2 = 0.561


.
. * response features
. * mean
. preserve /* run together with next 2 lines */

. collapse (mean) weight, by(group animal)

. oneway weight group

                        Analysis of Variance
    Source              SS         df      MS            F     Prob > F
------------------------------------------------------------------------
Between groups      3091.34348      2   1545.67174      1.06     0.3782
 Within groups      17572.3646     12   1464.36372
------------------------------------------------------------------------
    Total           20663.7081     14   1475.97915

Bartlett's test for equal variances:  chi2(2) =   0.2914  Prob>chi2 = 0.864

.
end of do-file

. do "C:\Users\DEFAUL~1.SID\AppData\Local\Temp\STD00000000.tmp"

. * gain
. preserve /* run together with next 3 lines */

. import delimited guinea_wide.csv, clear
(7 vars, 15 obs)

. gen gain=w7-w5

. oneway gain group

                        Analysis of Variance
    Source              SS         df      MS            F     Prob > F
------------------------------------------------------------------------
Between groups      11286.5333      2   5643.26667     13.04     0.0010
 Within groups          5194.4     12   432.866667
------------------------------------------------------------------------
    Total           16480.9333     14   1177.20952

Bartlett's test for equal variances:  chi2(2) =  11.8859  Prob>chi2 = 0.003

.
end of do-file

. do "C:\Users\DEFAUL~1.SID\AppData\Local\Temp\STD00000000.tmp"

. * slope
. anova weight animal c.week#animal

                         Number of obs =         90    R-squared     =  0.8947
                         Root MSE      =    23.2769    Adj R-squared =  0.8439

                  Source | Partial SS         df         MS        F    Prob>F
             ------------+----------------------------------------------------
                   Model |  276343.16         29   9529.0744     17.59  0.0000
                         |
                  animal |  9525.4621         14   680.39015      1.26  0.2618
             animal#week |  152360.89         15   10157.393     18.75  0.0000
                         |
                Residual |  32508.943         60   541.81571
             ------------+----------------------------------------------------
                   Total |   308852.1         89   3470.2483

. regress

      Source |       SS           df       MS      Number of obs   =        90
-------------+----------------------------------   F(29, 60)       =     17.59
       Model |  276343.157        29  9529.07438   Prob > F        =    0.0000
    Residual |  32508.9429        60  541.815714   R-squared       =    0.8947
-------------+----------------------------------   Adj R-squared   =    0.8439
       Total |    308852.1        89  3470.24831   Root MSE        =    23.277

--------------+----------------------------------------------------------------
        weight |      Coef.    Std. Err.       t    P>|t|      [95% Con f. Interval]
--------------+----------------------------------------------------------------
       animal |
           2  |    24.82857    32.44488      0.77    0.447     -40.07086       89.728
           3  |         -30    32.44488     -0.92    0.359     -94.89943     34.89943
           4  |    7.157143    32.44488      0.22    0.826     -57.74229     72.05657
           5  |   -7.757143    32.44488     -0.24    0.812     -72.65657     57.14229
           6  |        41.6    32.44488      1.28    0.205     -23.29943     106.4994
           7  |   -50.97143    32.44488     -1.57    0.121     -115.8709       13.928
           8  |    4.628571    32.44488      0.14    0.887     -60.27086       69.528
           9  |    22.37143    32.44488      0.69    0.493       -42.528     87.27086
          10  |    .8142857    32.44488      0.03    0.980     -64.08515     65.71372
          11  |    9.271429    32.44488      0.29    0.776       -55.628     74.17086
          12  |    21.41429    32.44488      0.66    0.512     -43.48515     86.31372
          13  |   -11.44286    32.44488     -0.35    0.726     -76.34229     53.45657
          14  |        46.1    32.44488      1.42    0.161     -18.79943     110.9994
          15  |   -15.34286    32.44488     -0.47    0.638     -80.24229     49.55657
              |
animal#c.week |
           1  |    .2285714    4.818783      0.05    0.962     -9.410431     9.867573
           2  |    15.11429    4.818783      3.14    0.003      5.475284     24.75329
           3  |    27.22857    4.818783      5.65    0.000      17.58957     36.86757
           4  |        21.5    4.818783      4.46    0.000        11.861       31.139
           5  |    16.05714    4.818783      3.33    0.001      6.418141     25.69614
           6  |    9.128571    4.818783      1.89    0.063     -.5104305     18.76757
           7  |    21.41429    4.818783      4.44    0.000      11.77528     31.05329
           8  |    23.81429    4.818783      4.94    0.000      14.17528     33.45329
           9  |    29.64286    4.818783      6.15    0.000      20.00386     39.28186
          10  |    28.77143    4.818783      5.97    0.000      19.13243     38.41043
          11  |    27.74286    4.818783      5.76    0.000      18.10386     37.38186
          12  |    15.67143    4.818783      3.25    0.002      6.032427     25.31043
          13  |        20.6    4.818783      4.27    0.000        10.961       30.239
          14  |    18.12857    4.818783      3.76    0.000      8.489569     27.76757
          15  |          16    4.818783      3.32    0.002      6.360998       25.639
              |
        _cons |    470.8429      22.942     20.52    0.000       424.952     516.7337
--------------+----------------------------------------------------------------

. matrix parms_slp=e(b)'     /* creates a column of all estimates from */

. svmat parms_slp            /* which the relevant ones must be extracted */

. preserve /* run together with next 3 lines */

. drop if _n<16 | _n>30
(75 observations deleted)

. egen float group2 = seq(), from(1) to(3) block(5)

. oneway parms_slp1 group2

                        Analysis of Variance
    Source              SS         df      MS            F     Prob > F
------------------------------------------------------------------------
Between groups       106.93772      2   53.4688601      0.83     0.4608
 Within groups       775.75174     12   64.6459783
------------------------------------------------------------------------
    Total            882.68946     14   63.0492471

Bartlett's test for equal variances:  chi2(2) =   1.6927  Prob>chi2 = 0.429

.
end of do-file

. do "C:\Users\DEFAUL~1.SID\AppData\Local\Temp\STD00000000.tmp"

. * curvature
. anova weight animal c.week#animal c.week#c.week#animal

                         Number of obs =         90    R-squared     =  0.9275
                         Root MSE      =    22.3061    Adj R-squared =  0.8566

                  Source | Partial SS         df         MS        F    Prob>F
        -----------------+----------------------------------------------------
                   Model |  286461.82         44    6510.496     13.08  0.0000
                         |
                  animal |  9070.0298         14   647.85927      1.30  0.2439
             animal#week |  23997.013         15   1599.8009      3.22  0.0012
        animal#week#week |  10118.667         15   674.57778      1.36  0.2110
                         |
                Residual |  22390.276         45   497.56169
        -----------------+----------------------------------------------------
                   Total |   308852.1         89   3470.2483

. regress

      Source |       SS           df       MS      Number of obs   =        90
-------------+----------------------------------   F(44, 45)       =     13.08
       Model |  286461.824        44    6510.496   Prob > F        =    0.0000
    Residual |  22390.2762        45  497.561693   R-squared       =    0.9275
-------------+----------------------------------   Adj R-squared   =    0.8566
       Total |    308852.1        89  3470.24831   Root MSE        =    22.306

---------------------+----------------------------------------------------------------
               weight |      Coef.    Std. Err.       t    P>|t|      [95% Con f. Interval]
---------------------+----------------------------------------------------------------
              animal |
                  2  |   -21.74286    51.69736     -0.42    0.676     -125.8667     82.38097
                  3  |   -37.71429    51.69736     -0.73    0.469     -141.8381     66.40954
                  4  |    15.87143    51.69736      0.31    0.760      -88.2524     119.9953
                  5  |    38.38571    51.69736      0.74    0.462     -65.73811     142.5095
                  6  |    94.45714    51.69736      1.83    0.074     -9.666686      198.581
                  7  |   -2.971429    51.69736     -0.06    0.954     -107.0953     101.1524
                  8  |    68.34286    51.69736      1.32    0.193     -35.78097     172.4667
                  9  |    67.51429    51.69736      1.31    0.198     -36.60954     171.6381
                 10  |        54.1    51.69736      1.05    0.301     -50.02383     158.2238
                 11  |    26.84286    51.69736      0.52    0.606     -77.28097     130.9667
                 12  |    52.12857    51.69736      1.01    0.319     -51.99526     156.2524
                 13  |    27.84286    51.69736      0.54    0.593     -76.28097     131.9667
                 14  |    114.5286    51.69736      2.22    0.032      10.40474     218.6524
                 15  |    38.37143    51.69736      0.74    0.462      -65.7524     142.4953
                     |
       animal#c.week |
                  1  |    31.37143    20.01046      1.57    0.124     -8.931716     71.67457
                  2  |    77.30476    20.01046      3.86    0.000      37.00162     117.6079
                  3  |    63.51429    20.01046      3.17    0.003      23.21114     103.8174
                  4  |    46.83333    20.01046      2.34    0.024      6.530189     87.13648
                  5  |     16.4381    20.01046      0.82    0.416     -23.86505     56.74124
                  6  |    5.033333    20.01046      0.25    0.803     -35.26981     45.33648
                  7  |    20.55714    20.01046      1.03    0.310       -19.746     60.86029
                  8  |    12.48095    20.01046      0.62    0.536     -27.82219      52.7841
                  9  |    30.69048    20.01046      1.53    0.132     -9.612668     70.99362
                 10  |    24.39048    20.01046      1.22    0.229     -15.91267     64.69362
                 11  |    47.17143    20.01046      2.36    0.023      6.868284     87.47457
                 12  |     26.3381    20.01046      1.32    0.195     -13.96505     66.64124
                 13  |    25.55238    20.01046      1.28    0.208     -14.75076     65.85553
                 14  |    3.652381    20.01046      0.18    0.856     -36.65076     43.95553
                 15  |    11.33333    20.01046      0.57    0.574     -28.96981     51.63648
                     |
animal#c.week#c.week |
                  1  |   -3.892857    2.433794     -1.60    0.117      -8.79477     1.009056
                  2  |    -7.77381    2.433794     -3.19    0.003     -12.67572    -2.871897
                  3  |   -4.535714    2.433794     -1.86    0.069     -9.437627     .3661986
                  4  |   -3.166667    2.433794     -1.30    0.200      -8.06858     1.735246
                  5  |    -.047619    2.433794     -0.02    0.984     -4.949532     4.854294
                  6  |    .5119048    2.433794      0.21    0.834     -4.390008     5.413818
                  7  |    .1071429    2.433794      0.04    0.965      -4.79477     5.009056
                  8  |    1.416667    2.433794      0.58    0.563     -3.485246      6.31858
                  9  |   -.1309524    2.433794     -0.05    0.957     -5.032865      4.77096
                 10  |     .547619    2.433794      0.23    0.823     -4.354294     5.449532
                 11  |   -2.428571    2.433794     -1.00    0.324     -7.330484     2.473341
                 12  |   -1.333333    2.433794     -0.55    0.587     -6.235246      3.56858
                 13  |   -.6190476    2.433794     -0.25    0.800      -5.52096     4.282865
                 14  |    1.809524    2.433794      0.74    0.461     -3.092389     6.711437
                 15  |    .5833333    2.433794      0.24    0.812      -4.31858     5.485246
                     |
               _cons |    424.1286    36.55555     11.60    0.000      350.5019     497.7552
---------------------+----------------------------------------------------------------

. matrix parms_crv=e(b)'     /* creates a column of all estimates from */

. svmat parms_crv            /* which the relevant ones must be extracted */

. preserve /* run together with next 3 lines */

. drop if _n<31 | _n>45
(75 observations deleted)

. egen float group2 = seq(), from(1) to(3) block(5)

. oneway parms_crv1 group2

                        Analysis of Variance
    Source              SS         df      MS            F     Prob > F
------------------------------------------------------------------------
Between groups      53.4485435      2   26.7242718      7.45     0.0079
 Within groups      43.0655887     12   3.58879906
------------------------------------------------------------------------
    Total           96.5141323     14   6.89386659

Bartlett's test for equal variances:  chi2(2) =   6.6432  Prob>chi2 = 0.036

.
end of do-file

. do "C:\Users\DEFAUL~1.SID\AppData\Local\Temp\STD00000000.tmp"

. * split-plot or hierarchical model
. anova weight group / animal|group week##group

                         Number of obs =         90    R-squared     =  0.8946
                         Root MSE      =    23.2926    Adj R-squared =  0.8437

                  Source | Partial SS         df         MS        F    Prob>F
            -------------+----------------------------------------------------
                   Model |   276299.5         29    9527.569     17.56  0.0000
                         |
                   group |  18548.067          2   9274.0333      1.06  0.3782
            animal|group |   105434.2         12   8786.1833
            -------------+----------------------------------------------------
                    week |   142554.5          5     28510.9     52.55  0.0000
              week#group |  9762.7333         10   976.27333      1.80  0.0801
                         |
                Residual |    32552.6         60   542.54333
            -------------+----------------------------------------------------
                   Total |   308852.1         89   3470.2483

. mixed weight group##week || animal:, reml

Performing EM optimization:

Performing gradient-based optimization:

Iteration 0:   log restricted-likelihood = -360.02217
Iteration 1:   log restricted-likelihood = -360.02217

Computing standard errors:

Mixed-effects REML regression                   Number of obs     =         90
Group variable: animal                          Number of groups  =         15

                                                Obs per group:
                                                              min =          6
                                                              avg =        6.0
                                                              max =          6

                                                Wald chi2(17)     =     282.86
Log restricted-likelihood = -360.02217          Prob > chi2       =     0.0000

-------------+----------------------------------------------------------------
       weight |      Coef.    Std. Err.       z    P>|z|      [95% Con f. Interval]
-------------+----------------------------------------------------------------
       group |
          2  |          28    27.68743      1.01    0.312     -26.26637     82.26637
          3  |        31.4    27.68743      1.13    0.257     -22.86637     85.66637
             |
        week |
          3  |          53    14.73151      3.60    0.000      24.12678     81.87322
          4  |       102.4    14.73151      6.95    0.000      73.52678     131.2732
          5  |        95.2    14.73151      6.46    0.000      66.32678     124.0732
          6  |        80.2    14.73151      5.44    0.000      51.32678     109.0732
          7  |       105.6    14.73151      7.17    0.000      76.72678     134.4732
             |
  group#week |
        2 3  |         3.6     20.8335      0.17    0.863      -37.2329      44.4329
        2 4  |       -22.6     20.8335     -1.08    0.278      -63.4329      18.2329
        2 5  |       -22.6     20.8335     -1.08    0.278      -63.4329      18.2329
        2 6  |        28.4     20.8335      1.36    0.173      -12.4329      69.2329
        2 7  |          44     20.8335      2.11    0.035      3.167097      84.8329
        3 3  |       -16.2     20.8335     -0.78    0.437      -57.0329      24.6329
        3 4  |       -20.4     20.8335     -0.98    0.327      -61.2329      20.4329
        3 5  |       -21.2     20.8335     -1.02    0.309      -62.0329      19.6329
        3 6  |        10.2     20.8335      0.49    0.624      -30.6329      51.0329
        3 7  |        19.8     20.8335      0.95    0.342      -21.0329      60.6329
             |
       _cons |       466.4    19.57797     23.82    0.000      428.0279     504.7721
-------------+----------------------------------------------------------------

-----------------------------+------------------------------------------------
  Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
animal: Identity             |
                  var(_cons) |   1373.942   598.0528      585.4031    3224.642
-----------------------------+------------------------------------------------
               var(Residual) |   542.5432   99.05438      379.3385    775.9643
-----------------------------+------------------------------------------------
LR test vs. linear model: chibar2(01) = 57.45         Prob >= chibar2 =  0.0000

. testparm group#week /* note: P-values smaller (too small) in chi^2-distrib */


 ( 1)  [weight]2.group#3.week = 0


 ( 2)  [weight]2.group#4.week = 0


 ( 3)  [weight]2.group#5.week = 0


 ( 4)  [weight]2.group#6.week = 0


 ( 5)  [weight]2.group#7.week = 0


 ( 6)  [weight]3.group#3.week = 0


 ( 7)  [weight]3.group#4.week = 0


 ( 8)  [weight]3.group#5.week = 0


 ( 9)  [weight]3.group#6.week = 0


 (10)  [weight]3.group#7.week = 0


           chi2( 10) =   17.99
         Prob > chi2 =    0.0551

. * repeated measures ANOVA
. anova weight group / animal|group week##group, repeated(week)

                         Number of obs =         90    R-squared     =  0.8946
                         Root MSE      =    23.2926    Adj R-squared =  0.8437

                  Source | Partial SS         df         MS        F    Prob>F
            -------------+----------------------------------------------------
                   Model |   276299.5         29    9527.569     17.56  0.0000
                         |
                   group |  18548.067          2   9274.0333      1.06  0.3782
            animal|group |   105434.2         12   8786.1833
            -------------+----------------------------------------------------
                    week |   142554.5          5     28510.9     52.55  0.0000
              week#group |  9762.7333         10   976.27333      1.80  0.0801
                         |
                Residual |    32552.6         60   542.54333
            -------------+----------------------------------------------------
                   Total |   308852.1         89   3470.2483


Between-subjects error term:  animal|group
                     Levels:  15        (12 df)
     Lowest b.s.e. variable:  animal
     Covariance pooled over:  group     (for repeated variable)

Repeated variable: week
                                          Huynh-Feldt epsilon        =  0.7191
                                          Greenhouse-Geisser epsilon =  0.4856
                                          Box's conservative epsilon =  0.2000

                                            ------------ Prob > F ------------
                  Source |     df      F    Regular    H-F      G-G      Box
            -------------+----------------------------------------------------
                    week |      5    52.55   0.0000   0.0000   0.0000   0.0000
              week#group |     10     1.80   0.0801   0.1103   0.1457   0.2073
                Residual |     60
            -------------+----------------------------------------------------

.
. * mixed models with correlation structure, assuming equidistant times
. gen weekeq=week+(week==1) /* equidistant time points 2-7*/

. * ar(1) autoregressive correlations
. mixed weight group##weekeq || animal:, res(ar 1, t(weekeq)) nocons reml

Obtaining starting values by EM:

Performing gradient-based optimization:

Iteration 0:   log restricted-likelihood = -388.74541  (not concave)
Iteration 1:   log restricted-likelihood =  -354.4239
Iteration 2:   log restricted-likelihood = -354.31402
Iteration 3:   log restricted-likelihood = -354.31239
Iteration 4:   log restricted-likelihood = -354.31239

Computing standard errors:

Mixed-effects REML regression                   Number of obs     =         90
Group variable: animal                          Number of groups  =         15

                                                Obs per group:
                                                              min =          6
                                                              avg =        6.0
                                                              max =          6

                                                Wald chi2(17)     =     162.42
Log restricted-likelihood = -354.31239          Prob > chi2       =     0.0000

-------------+----------------------------------------------------------------
       weight |      Coef.    Std. Err.       z    P>|z|      [95% Con f. Interval]
-------------+----------------------------------------------------------------
       group |
          2  |          28    27.20166      1.03    0.303     -25.31427     81.31427
          3  |        31.4    27.20166      1.15    0.248     -21.91427     84.71427
             |
      weekeq |
          3  |          53     11.6093      4.57    0.000      30.24619     75.75381
          4  |       102.4    15.65256      6.54    0.000      71.72154     133.0785
          5  |        95.2    18.30716      5.20    0.000      59.31863     131.0814
          6  |        80.2    20.22081      3.97    0.000      40.56794     119.8321
          7  |       105.6    21.66058      4.88    0.000      63.14605     148.0539
             |
group#weekeq |
        2 3  |         3.6    16.41803      0.22    0.826     -28.57874     35.77874
        2 4  |       -22.6    22.13606     -1.02    0.307     -65.98589     20.78589
        2 5  |       -22.6    25.89023     -0.87    0.383     -73.34392     28.14392
        2 6  |        28.4    28.59654      0.99    0.321     -27.64819     84.44819
        2 7  |          44    30.63268      1.44    0.151     -16.03895      104.039
        3 3  |       -16.2    16.41803     -0.99    0.324     -48.37874     15.97874
        3 4  |       -20.4    22.13606     -0.92    0.357     -63.78589     22.98589
        3 5  |       -21.2    25.89023     -0.82    0.413     -71.94392     29.54392
        3 6  |        10.2    28.59654      0.36    0.721     -45.84819     66.24819
        3 7  |        19.8    30.63268      0.65    0.518     -40.23895     79.83895
             |
       _cons |       466.4    19.23448     24.25    0.000      428.7011     504.0989
-------------+----------------------------------------------------------------

-----------------------------+------------------------------------------------
  Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
animal:              (empty) |
-----------------------------+------------------------------------------------
Residual: AR(1)              |
                         rho |   .8178534   .0563492      .6732989    .9021861
                      var(e) |   1849.826    528.377       1056.81     3237.91
-----------------------------+------------------------------------------------
LR test vs. linear model: chi2(1) = 68.87                 Prob > chi2 = 0.0000


Note: The reported degrees of freedom
assumes the null hypothesis is not on the
boundary of the parameter space.  If this is not
true, then the reported test is
conservative.


. estat wcor


Standard deviations and correlations
for animal = 7:


Standard deviations:


weekeq   | 2    3    4    5    6    7
-------------+------------------------------------------------
sd   | 43.010    43.010    43.010    43.010    43.010    43.010


Correlations:


weekeq   | 2    3    4    5    6    7
-------------+------------------------------------------------
2   |  1.000
3   |  0.818     1.000
4   |  0.669     0.818     1.000
5   |  0.547     0.669     0.818     1.000
6   |  0.447     0.547     0.669     0.818     1.000
7   |  0.366     0.447     0.547     0.669     0.818     1.000

. * random effects and ar(1) errors
. mixed weight group##weekeq || animal:, res(ar 1, t(weekeq)) reml

Obtaining starting values by EM:

Performing gradient-based optimization:

Iteration 0:   log restricted-likelihood = -360.02217
Iteration 1:   log restricted-likelihood =  -354.8883
Iteration 2:   log restricted-likelihood = -354.10492
Iteration 3:   log restricted-likelihood = -354.06675
Iteration 4:   log restricted-likelihood = -354.06643
Iteration 5:   log restricted-likelihood = -354.06643

Computing standard errors:

Mixed-effects REML regression                   Number of obs     =         90
Group variable: animal                          Number of groups  =         15

                                                Obs per group:
                                                              min =          6
                                                              avg =        6.0
                                                              max =          6

                                                Wald chi2(17)     =     191.08
Log restricted-likelihood = -354.06643          Prob > chi2       =     0.0000

-------------+----------------------------------------------------------------
       weight |      Coef.    Std. Err.       z    P>|z|      [95% Con f. Interval]
-------------+----------------------------------------------------------------
       group |
          2  |          28    27.22117      1.03    0.304     -25.35251     81.35251
          3  |        31.4    27.22117      1.15    0.249     -21.95251     84.75251
             |
      weekeq |
          3  |          53    11.64353      4.55    0.000       30.1791      75.8209
          4  |       102.4    14.97297      6.84    0.000      73.05352     131.7465
          5  |        95.2    16.79631      5.67    0.000      62.27984     128.1202
          6  |        80.2    17.88798      4.48    0.000       45.1402     115.2598
          7  |       105.6    18.56691      5.69    0.000      69.20952     141.9905
             |
group#weekeq |
        2 3  |         3.6    16.46644      0.22    0.827     -28.67363     35.87363
        2 4  |       -22.6    21.17498     -1.07    0.286     -64.10219     18.90219
        2 5  |       -22.6    23.75357     -0.95    0.341     -69.15613     23.95613
        2 6  |        28.4    25.29743      1.12    0.262     -21.18205     77.98205
        2 7  |          44    26.25758      1.68    0.094     -7.463908     95.46391
        3 3  |       -16.2    16.46644     -0.98    0.325     -48.47363     16.07363
        3 4  |       -20.4    21.17498     -0.96    0.335     -61.90219     21.10219
        3 5  |       -21.2    23.75357     -0.89    0.372     -67.75613     25.35613
        3 6  |        10.2    25.29743      0.40    0.687     -39.38205     59.78205
        3 7  |        19.8    26.25758      0.75    0.451     -31.66391     71.26391
             |
       _cons |       466.4    19.24827     24.23    0.000      428.6741     504.1259
-------------+----------------------------------------------------------------

-----------------------------+------------------------------------------------
  Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
animal: Identity             |
                  var(_cons) |   873.8739   771.5022      154.8685    4930.995
-----------------------------+------------------------------------------------
Residual: AR(1)              |
                         rho |   .6536608   .2213377      .0242068    .9119718
                      var(e) |    978.606   607.2897      289.9887    3302.438
-----------------------------+------------------------------------------------
LR test vs. linear model: chi2(2) = 69.36                 Prob > chi2 = 0.0000


Note: LR test is conservative and provided only for reference.


. estat wcor


Standard deviations and correlations
for animal = 7:


Standard deviations:


weekeq   | 2    3    4    5    6    7
-------------+------------------------------------------------
sd   | 43.040    43.040    43.040    43.040    43.040    43.040


Correlations:


weekeq   | 2    3    4    5    6    7
-------------+------------------------------------------------
2   |  1.000
3   |  0.817     1.000
4   |  0.697     0.817     1.000
5   |  0.619     0.697     0.817     1.000
6   |  0.568     0.619     0.697     0.817     1.000
7   |  0.535     0.568     0.619     0.697     0.817     1.000

. * Toeplitz
. mixed weight group##weekeq || animal:, res(toeplitz, t(weekeq)) nocons reml

Obtaining starting values by EM:

Performing gradient-based optimization:

Iteration 0:   log restricted-likelihood = -388.74541  (not concave)
Iteration 1:   log restricted-likelihood = -377.15901  (not concave)
Iteration 2:   log restricted-likelihood =   -370.597  (not concave)
Iteration 3:   log restricted-likelihood =  -366.6394  (not concave)
Iteration 4:   log restricted-likelihood = -363.07347  (not concave)
Iteration 5:   log restricted-likelihood = -361.39529  (not concave)
Iteration 6:   log restricted-likelihood = -359.88913
Iteration 7:   log restricted-likelihood = -355.00099  (not concave)
Iteration 8:   log restricted-likelihood = -353.35211
Iteration 9:   log restricted-likelihood = -351.18936
Iteration 10:  log restricted-likelihood = -349.84522
Iteration 11:  log restricted-likelihood =  -349.1903
Iteration 12:  log restricted-likelihood = -349.18007
Iteration 13:  log restricted-likelihood = -349.18002
Iteration 14:  log restricted-likelihood = -349.18002

Computing standard errors:

Mixed-effects REML regression                   Number of obs     =         90
Group variable: animal                          Number of groups  =         15

                                                Obs per group:
                                                              min =          6
                                                              avg =        6.0
                                                              max =          6

                                                Wald chi2(17)     =     178.00
Log restricted-likelihood = -349.18002          Prob > chi2       =     0.0000

-------------+----------------------------------------------------------------
       weight |      Coef.    Std. Err.       z    P>|z|      [95% Con f. Interval]
-------------+----------------------------------------------------------------
       group |
          2  |          28    26.79561      1.04    0.296     -24.51843     80.51843
          3  |        31.4    26.79561      1.17    0.241     -21.11843     83.91843
             |
      weekeq |
          3  |          53    11.72339      4.52    0.000      30.02259     75.97741
          4  |       102.4    13.27407      7.71    0.000      76.38329     128.4167
          5  |        95.2    17.23542      5.52    0.000      61.41919     128.9808
          6  |        80.2    18.37799      4.36    0.000      44.17981     116.2202
          7  |       105.6    22.88712      4.61    0.000      60.74207     150.4579
             |
group#weekeq |
        2 3  |         3.6    16.57937      0.22    0.828     -28.89497     36.09497
        2 4  |       -22.6    18.77238     -1.20    0.229     -59.39318     14.19318
        2 5  |       -22.6    24.37457     -0.93    0.354     -70.37328     25.17328
        2 6  |        28.4     25.9904      1.09    0.275     -22.54024     79.34024
        2 7  |          44    32.36728      1.36    0.174      -19.4387     107.4387
        3 3  |       -16.2    16.57937     -0.98    0.329     -48.69497     16.29497
        3 4  |       -20.4    18.77238     -1.09    0.277     -57.19318     16.39318
        3 5  |       -21.2    24.37457     -0.87    0.384     -68.97328     26.57328
        3 6  |        10.2     25.9904      0.39    0.695     -40.74024     61.14024
        3 7  |        19.8    32.36728      0.61    0.541      -43.6387      83.2387
             |
       _cons |       466.4    18.94736     24.62    0.000      429.2639     503.5361
-------------+----------------------------------------------------------------

-----------------------------+------------------------------------------------
  Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
animal:              (empty) |
-----------------------------+------------------------------------------------
Residual: Toeplitz(5)        |
                        cov1 |   1451.417   503.0803      465.3977    2437.436
                        cov2 |   1354.509   491.8142      390.5707    2318.447
                        cov3 |   1052.362   478.1299      115.2444    1989.479
                        cov4 |   950.6354   472.6153      24.32647    1876.944
                        cov5 |   485.4607   524.4629     -542.4678    1513.389
                      var(e) |   1795.011    510.734      1027.721    3135.157
-----------------------------+------------------------------------------------
LR test vs. linear model: chi2(5) = 79.13                 Prob > chi2 = 0.0000


Note: The reported degrees of freedom
assumes the null hypothesis is not on the
boundary of the parameter space.  If this is not
true, then the reported test is
conservative.


. estat wcor


Standard deviations and correlations
for animal = 7:


Standard deviations:


weekeq   | 2    3    4    5    6    7
-------------+------------------------------------------------
sd   | 42.368    42.368    42.368    42.368    42.368    42.368


Correlations:


weekeq   | 2    3    4    5    6    7
-------------+------------------------------------------------
2   |  1.000
3   |  0.809     1.000
4   |  0.755     0.809     1.000
5   |  0.586     0.755     0.809     1.000
6   |  0.530     0.586     0.755     0.809     1.000
7   |  0.270     0.530     0.586     0.755     0.809     1.000

. * unstructured (not in lecture)
. mixed weight group##weekeq || animal:, res(uns, t(weekeq)) nocons reml

Obtaining starting values by EM:

Performing gradient-based optimization:

Iteration 0:   log restricted-likelihood = -388.74541  (not concave)
Iteration 1:   log restricted-likelihood = -364.29311  (not concave)
Iteration 2:   log restricted-likelihood = -358.15621  (not concave)
Iteration 3:   log restricted-likelihood =  -353.6126  (not concave)
Iteration 4:   log restricted-likelihood = -346.69775  (not concave)
Iteration 5:   log restricted-likelihood = -340.44418  (not concave)
Iteration 6:   log restricted-likelihood = -336.85397  (not concave)
Iteration 7:   log restricted-likelihood = -335.45781
Iteration 8:   log restricted-likelihood = -334.38419
Iteration 9:   log restricted-likelihood = -331.29317
Iteration 10:  log restricted-likelihood = -330.71346
Iteration 11:  log restricted-likelihood = -330.68088
Iteration 12:  log restricted-likelihood = -330.68074
Iteration 13:  log restricted-likelihood = -330.68074

Computing standard errors:

Mixed-effects REML regression                   Number of obs     =         90
Group variable: animal                          Number of groups  =         15

                                                Obs per group:
                                                              min =          6
                                                              avg =        6.0
                                                              max =          6

                                                Wald chi2(17)     =     354.56
Log restricted-likelihood = -330.68074          Prob > chi2       =     0.0000

-------------+----------------------------------------------------------------
       weight |      Coef.    Std. Err.       z    P>|z|      [95% Con f. Interval]
-------------+----------------------------------------------------------------
       group |
          2  |          28     16.8138      1.67    0.096     -4.954449     60.95445
          3  |        31.4     16.8138      1.87    0.062     -1.554449     64.35445
             |
      weekeq |
          3  |          53    11.95408      4.43    0.000      29.57043     76.42957
          4  |       102.4    14.04398      7.29    0.000      74.87431     129.9257
          5  |        95.2    18.42101      5.17    0.000      59.09547     131.3045
          6  |        80.2    21.58675      3.72    0.000      37.89076     122.5092
          7  |       105.6    20.44653      5.16    0.000      65.52554     145.6745
             |
group#weekeq |
        2 3  |         3.6    16.90563      0.21    0.831     -29.53442     36.73442
        2 4  |       -22.6    19.86118     -1.14    0.255      -61.5272      16.3272
        2 5  |       -22.6    26.05125     -0.87    0.386     -73.65951     28.45951
        2 6  |        28.4    30.52827      0.93    0.352     -31.43431     88.23431
        2 7  |          44    28.91576      1.52    0.128     -12.67385     100.6738
        3 3  |       -16.2    16.90563     -0.96    0.338     -49.33442     16.93442
        3 4  |       -20.4    19.86118     -1.03    0.304      -59.3272      18.5272
        3 5  |       -21.2    26.05125     -0.81    0.416     -72.25951     29.85951
        3 6  |        10.2    30.52827      0.33    0.738     -49.63431     70.03431
        3 7  |        19.8    28.91576      0.68    0.494     -36.87385     76.47385
             |
       _cons |       466.4    11.88915     39.23    0.000      443.0977     489.7023
-------------+----------------------------------------------------------------

-----------------------------+------------------------------------------------
  Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
animal:              (empty) |
-----------------------------+------------------------------------------------
Residual: Unstructured       |
                     var(e2) |     706.76   287.9053      318.0731    1570.424
                     var(e3) |    1430.86   578.8167      647.5393    3161.756
                     var(e4) |   1082.699   439.1876      488.9054    2397.675
                     var(e5) |   2408.829    975.396      1089.263    5326.955
                     var(e6) |   3074.831    1248.37      1387.511    6814.062
                     var(e7) |   2794.896   1132.279       1263.35    6183.119
                  cov(e2,e3) |   711.5599    352.514      20.64519    1402.475
                  cov(e2,e4) |   401.6462   274.2313     -135.8373    939.1297
                  cov(e2,e5) |   709.4599   423.5298     -120.6432    1539.563
                  cov(e2,e6) |   725.8264   468.3629      -192.148    1643.801
                  cov(e2,e7) |   705.6766   447.8352     -172.0642    1583.417
                  cov(e3,e4) |   1107.747   476.4334      173.9542    2041.539
                  cov(e3,e5) |   1623.027   704.2989      242.6266    3003.428
                  cov(e3,e6) |    1419.51   721.3132      5.762214    2833.258
                  cov(e3,e7) |   1669.611   743.2281      212.9103    3126.311
                  cov(e4,e5) |   1423.114   616.0996      215.5807    2630.647
                  cov(e4,e6) |   1440.647   665.1582      136.9612    2744.333
                  cov(e4,e7) |   1474.764   652.4671      195.9518    2753.576
                  cov(e5,e6) |   2185.529    998.295      228.9062    4142.151
                  cov(e5,e7) |   2385.429    1008.51      408.7858    4362.072
                  cov(e6,e7) |    2625.48   1127.343      415.9283    4835.031
-----------------------------+------------------------------------------------
LR test vs. linear model: chi2(20) = 116.13               Prob > chi2 = 0.0000


Note: The reported degrees of freedom
assumes the null hypothesis is not on the
boundary of the parameter space.  If this is not
true, then the reported test is
conservative.


. estat wcor


Standard deviations and correlations
for animal = 7:


Standard deviations:


weekeq   | 2    3    4    5    6    7
-------------+------------------------------------------------
sd   | 26.585    37.827    32.904    49.080    55.451    52.867


Correlations:


weekeq   | 2    3    4    5    6    7
-------------+------------------------------------------------
2   |  1.000
3   |  0.708     1.000
4   |  0.459     0.890     1.000
5   |  0.544     0.874     0.881     1.000
6   |  0.492     0.677     0.790     0.803     1.000
7   |  0.502     0.835     0.848     0.919     0.896     1.000

. * models with non-equidistant time points: replace weekeq by week
. * example: ar(1) (not in lecture)
. mixed weight group##week || animal:, res(ar 1, t(week)) nocons reml


Note: time gaps exist in the
estimation data


Obtaining starting values by EM:

Performing gradient-based optimization:

Iteration 0:   log restricted-likelihood = -388.74541  (not concave)
Iteration 1:   log restricted-likelihood = -355.13854
Iteration 2:   log restricted-likelihood = -354.73193
Iteration 3:   log restricted-likelihood = -354.69208
Iteration 4:   log restricted-likelihood = -354.69198
Iteration 5:   log restricted-likelihood = -354.69198

Computing standard errors:

Mixed-effects REML regression                   Number of obs     =         90
Group variable: animal                          Number of groups  =         15

                                                Obs per group:
                                                              min =          6
                                                              avg =        6.0
                                                              max =          6

                                                Wald chi2(17)     =     150.10
Log restricted-likelihood = -354.69198          Prob > chi2       =     0.0000

-------------+----------------------------------------------------------------
       weight |      Coef.    Std. Err.       z    P>|z|      [95% Con f. Interval]
-------------+----------------------------------------------------------------
       group |
          2  |          28    26.75228      1.05    0.295     -24.43351     80.43351
          3  |        31.4    26.75228      1.17    0.241     -21.03351     83.83351
             |
        week |
          3  |          53    15.00046      3.53    0.000      23.59964     82.40036
          4  |       102.4    17.58992      5.82    0.000      67.92438     136.8756
          5  |        95.2    19.47517      4.89    0.000      57.02936     133.3706
          6  |        80.2    20.90792      3.84    0.000      39.22124     121.1788
          7  |       105.6    22.02381      4.79    0.000      62.43412     148.7659
             |
  group#week |
        2 3  |         3.6    21.21385      0.17    0.865     -37.97838     45.17838
        2 4  |       -22.6    24.87591     -0.91    0.364     -71.35588     26.15588
        2 5  |       -22.6    27.54205     -0.82    0.412     -76.58143     31.38143
        2 6  |        28.4    29.56826      0.96    0.337     -29.55272     86.35272
        2 7  |          44    31.14638      1.41    0.158     -17.04577     105.0458
        3 3  |       -16.2    21.21385     -0.76    0.445     -57.77838     25.37838
        3 4  |       -20.4    24.87591     -0.82    0.412     -69.15588     28.35588
        3 5  |       -21.2    27.54205     -0.77    0.441     -75.18143     32.78143
        3 6  |        10.2    29.56826      0.34    0.730     -47.75272     68.15272
        3 7  |        19.8    31.14638      0.64    0.525     -41.24577     80.84577
             |
       _cons |       466.4    18.91672     24.66    0.000      429.3239     503.4761
-------------+----------------------------------------------------------------

-----------------------------+------------------------------------------------
  Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
animal:              (empty) |
-----------------------------+------------------------------------------------
Residual: AR(1)              |
                         rho |   .8280075   .0531303      .6913597    .9074657
                      var(e) |   1789.211   500.2773       1034.33    3095.025
-----------------------------+------------------------------------------------
LR test vs. linear model: chi2(1) = 68.11                 Prob > chi2 = 0.0000


Note: The reported degrees of freedom
assumes the null hypothesis is not on the
boundary of the parameter space.  If this is not
true, then the reported test is
conservative.


. estat wcor


Standard deviations and correlations
for animal = 7:


Standard deviations:


week   | 1    3    4    5    6    7
-------------+------------------------------------------------
sd   | 42.299    42.299    42.299    42.299    42.299    42.299


Correlations:


week   | 1    3    4    5    6    7
-------------+------------------------------------------------
1   |  1.000
3   |  0.686     1.000
4   |  0.568     0.828     1.000
5   |  0.470     0.686     0.828     1.000
6   |  0.389     0.568     0.686     0.828     1.000
7   |  0.322     0.470     0.568     0.686     0.828     1.000

.
end of do-file

. exit, clear