Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • traj - issues with x-axis

    Hello,

    I'm using the user-written traj to plot trajectories of lung function. I have plotted the x-axis both using time of follow-up (0-25 years) and age (13-44 years) using the same data. My problem is that changing the x-axis is also changing the resulting plot, even though the code and the data are the same. I don't understand why, and I don't understand why the plot using age at the x-axis starts at 16, even though there are individuals aged 13 in the data set.

    FEV1_* is lung function measured at either time t_* or age age_*.
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(id t1 t2 t3 t4 t5 age1 age2 age3 age4 age5) double(FEV1_1 FEV1_2 FEV1_3 FEV1_4 FEV1_5)
      1   .7063655         .         .  12.36961  22.00137 19.7    .    . 31.4   41  92.704       .       .     . 100.213
      2    .421629         .         . 11.370295 22.707735 17.4    .    . 28.3 39.7  90.686       .       .  89.5  91.217
      3   .3449692  5.448323         .  12.72827 22.945927 13.8 18.7    . 26.2 36.4 105.186  99.618       .    94  98.176
      4  1.1882273         .         . 12.172484  23.98357 15.8 19.2    . 26.7 36.7 113.556       .       . 120.6  89.832
      5  1.6837783  5.448323         . 11.956194  23.26352 14.7 18.3    .   25 36.3  92.908  96.472       .     .   98.69
      6   .5229295         .         .         . 23.791924 18.8    .    .    . 40.4  89.062       .       .     .  85.342
      7          .         .  12.15058         .  22.21766    .    . 14.5    . 24.6       .       .  84.108     .   91.43
      8  1.3661876         .         .         .    22.141 19.5    .    .    . 40.3  90.749       .       .     .  93.446
      9   .4188912         .         .         . 23.304586 17.7    .    .    . 40.6  96.955       .       .     .  92.813
     10          .         .  12.57221         .  23.32923    .    . 15.5    . 26.2       .       .  95.618     .  89.931
     11          .         . 11.460644         .   23.8193    .    . 14.1    . 25.4       .       .  88.065     .  71.176
     12   1.670089         .         .  12.72553  23.32101 13.5    .    . 24.5 35.1  97.428       .       .  91.3   94.55
     13          .         .    12.282         .  22.21492    .    . 16.1    .   26       .       .  92.159     . 103.221
     14  1.5140315         .         .  12.35866         . 16.8    .    . 27.7    .  92.583       .       .  92.1       .
     15    .366872         .         .  11.27173 22.658453 17.2    .    . 28.1 39.5  89.706       .       . 101.8 100.688
     16  .59137577         .         .         .  22.15195 16.2    .    .    . 37.7  100.86       .       .     .  99.767
     17  1.3086927  5.119781         . 11.444217 23.304586 14.9 18.6    .   25 36.9 102.562 103.149       . 102.6 101.899
     18   .6132786         .         . 11.638604  23.79466 13.9    .    . 24.9 35.7  82.164       .       .  99.2  99.349
     19          .         . 12.073922         .  23.79466    .    . 14.9    . 25.2       .       . 101.657     .  99.281
     20  .13963039         .         . 11.652293 22.907597 16.4    .    . 27.9 39.1 119.802       .       . 120.8 120.316
     21   .2108145         .         .         .   21.9603 18.5    .    .    . 40.2 135.623       .       .     . 117.146
     22  1.0376455         .         .  12.09035  23.79466 17.5    .    . 28.5   39  99.539       .       .  97.5  95.063
     23  1.0978782         .         .  12.26831 22.286106 14.9 18.4    .   26   36  97.366       .       .     .  97.009
     24  1.1718001         .         . 12.041068  22.58179 13.2    .    . 24.1 34.6 108.389       .       . 115.5 113.149
     25          .         . 12.079397         . 22.017796    .    . 14.1    . 24.1       .       .  89.731     .  81.733
     26          .         . 11.676933         .  22.09719    .    . 13.9    . 24.3       .       . 120.272     . 105.205
     27   1.338809         .         .         .  22.30801 19.1    .    .    . 40.1  93.412       .       .     .   80.16
     28   .5722108         .         .         . 22.080767 16.8    .    .    . 38.3 101.883       .       .     .  89.176
     29   .5393566         .         .         . 22.691307   18    .    .    . 40.2  96.967       .       .     . 108.182
     30  1.3059548  5.119781         .         .  23.36482 13.6 17.3    .    . 35.7 112.254  101.64       .     .  84.547
     31  1.3251197  5.448323         . 11.485284         . 13.4 17.4    . 23.6 35.3  90.074  114.12       . 120.2       .
     32  1.0184805         .         . 11.373033 22.365503   15    .    . 25.3 36.3  84.883       .       .  93.5  89.529
     33   .2108145         .         .         . 22.017796 18.9    .    .    . 40.7 103.818       .       .     .  92.274
     34   1.670089         .         .    12.282         . 15.8 18.8    . 26.4 36.4  113.19       .       . 112.8       .
     35   .9390828         .         . 12.079397  23.93429 18.6    .    . 29.8 40.1 101.282       .       . 102.8 102.543
     36   .9965777         .         . 12.071184         . 17.2    .    . 28.3    . 101.763       .       . 107.5       .
     37          .         . 11.367557         .  23.78645    .    . 16.9    . 28.6       .       .  84.615     .   93.98
     38   .6899384         .         . 11.296372         . 15.1    .    . 25.7    .  85.266       .       .  89.2       .
     39          .         .    12.282         .  22.38193    .    . 16.6    . 26.7       .       .  88.969     .  84.389
     40  1.4428474         .         .  11.20876  23.00342 17.6    .    . 27.3 39.1 108.474       .       .  94.1  96.351
     41   .3449692  5.448323         . 12.646132         . 13.7 18.7    .   26    . 119.611 109.045       . 116.2       .
     42  1.1690623         .         .         .  23.33744   18    .    .    . 40.2 111.994       .       .     .   87.71
     43  1.3689255         .         . 12.670774         . 17.5    .    . 28.8 39.4  108.48       .       . 108.3       .
     44    .366872         .         . 11.635866         . 17.9    .    . 29.2    .  97.404       .       . 101.1       .
     45 .002737851         .         . 11.983573  22.00137 13.9    .    . 25.9 35.9 121.521       .       .     . 111.991
     46   .3285421         .         . 12.511978         . 16.7    .    . 28.9    . 106.373       .       .  95.6       .
     47   .9582478         .         .         .   22.3436 17.2    .    .    . 38.6  97.485       .       .     . 104.509
     48   .9965777         .         . 12.093087  22.65024 15.9    .    .   27 37.5 140.499       .       . 124.5 114.594
     49   .3531828         .         .  11.35113         . 14.4 18.7    . 25.4    .  87.984       .       .  88.6       .
     50   1.434634         .         .         . 23.060917 17.9    .    .    . 39.5 102.008       .       .     .  92.171
     51   .3340178         .         . 11.334702 22.973307 13.4    .    . 24.4   36  94.868       .       . 100.3  94.031
     52          .         . 11.036277         . 22.732374    .    . 16.1    . 27.8       .       . 105.428     .  99.342
     53  1.0896646         .         .         .  23.93429   14    .    .    . 35.4  87.612       .       .     .  95.821
     54          .         . 11.112936         . 22.691307    .    . 18.7    . 30.3       .       .  97.901     . 104.432
     55  1.4620123         .         . 12.629705         . 18.9    .    .   30 40.7  110.73       .       .  89.2       .
     56   1.672827   5.28679         . 12.271048         . 14.2 17.7    . 24.8    . 128.699 111.049       . 107.9       .
     57   .6516085         .         . 11.485284         . 13.9 17.7    . 24.8    .  89.462       .       .    86       .
     58   1.629021 4.4490075         .  11.87132         .   15 17.7    . 25.2    .  99.513 102.001       .  99.2       .
     59   .6707734 4.4490075         .         .  22.67214 15.6 19.3    .    . 37.6  79.025 106.679       .     . 101.083
     60          .         .  11.05818         . 23.307323    .    . 17.6    . 29.8       .       .  85.781     .  89.736
     61          .         . 11.523614         . 23.791924    .    . 15.2    . 25.8       .       .  91.617     . 113.524
     62          .         . 11.085558         . 22.020535    .    . 17.1    .   28       .       . 118.688     . 113.383
     63          .         . 12.350445         . 23.304586    .    . 16.4    . 27.3       .       . 117.227     .  116.85
     64  .03559206         .         .         . 22.045174 12.9    .    .    . 34.9 110.779       .       .     . 111.364
     65  1.0321697         .         . 12.574948 22.540726 15.3    .    . 26.8 36.8  72.797       .       .     .  80.818
     66  1.3086927 4.5338807         .  11.43874         . 14.7    .    . 24.8    . 109.405       .       . 111.3       .
     67   .3039014         .         .  11.38946 23.167694 15.9    .    .   27 38.7  91.237       .       . 109.6  90.134
     68   .6899384 4.4490075         . 11.329226         . 14.9 18.6    . 25.5    . 114.628 107.423       . 102.1       .
     69          .         .  11.27447         .  23.79466    .    . 13.6    . 24.7       .       .  95.503     . 102.833
     70  1.1526352         .         .  12.07666         . 15.7    .    . 26.6    . 102.699       .       . 111.4       .
     71   .9609856         .         .  11.69336         .   18    .    . 28.8    . 108.068       .       . 104.6       .
     72  .28473648         .         . 12.082135   21.9603 16.6    .    . 28.4 38.3  97.424       .       .     .  98.376
     73  .26557153         .         .         .  22.54346 18.5    .    .    . 40.8  93.618       .       .     .  82.982
     74    .440794         .         .  11.65503         . 17.3    .    . 28.5 39.3 111.885       .       . 114.3       .
     75   .5612594         .         . 12.665298         . 17.8    .    . 29.9    .  90.788       .       . 101.1       .
     76          .         .  11.27447         . 23.868584    .    . 15.6    . 27.3       .       . 106.532     .  91.975
     77  .57494867         .         .  12.15332 22.707735 17.1    .    . 28.7 39.2  92.089       .       .    89  82.025
     78  .12046544         .         .         .  22.99521 16.1    .    .    .   39  91.859       .       .     .   82.83
     79  .13141684         .         . 11.523614   22.7269 15.5    .    . 26.9 38.1 114.649       .       .     . 112.412
     80   .7118412         .         .  11.47707  22.68857 19.5    .    . 30.3 41.5 101.637       .       .  97.7 109.941
     81  1.5879534   5.28679         . 12.386037         . 14.4   18    . 25.2    . 109.945  100.59       . 104.9       .
     82  1.0321697         .         . 12.136892 22.696783 16.5    .    . 27.6 38.2 109.774       .       .  97.7  97.403
     83          .         . 12.323067         .  22.21492    .    . 17.5    . 27.4       .       .  64.993     .  76.751
     84          .         . 11.348392         . 23.931553    .    . 13.3    . 24.3       .       . 118.509     .  90.673
     85 .016427105         .         . 12.109514  22.00137 14.7    .    . 26.8 36.7  72.171       .       .     .  87.391
     86   .4626968         .         . 11.154004  24.21355 14.4 18.5    .   25 37.2  96.024       .       . 114.3 105.933
     87  1.1718001  5.119781         . 12.041068 22.554415 13.7 17.6    . 24.5   35 105.459 101.581       . 100.4 100.641
     88 .019164955         .         . 12.514716         .   14    .    . 26.5    . 117.517       .       .   103       .
     89          .         . 11.258042         .  23.78645    .    . 13.2    . 24.6       .       .  94.075     .  99.075
     90          .         .  11.54278         .  22.67488    .    .   16    . 27.1       .       . 109.742     .  112.57
     91          .         . 12.043806         .  24.75017    .    . 14.5    . 24.8       .       .  80.216     .  94.753
     92  .13963039         .         . 11.830254 23.022587 16.8    .    . 28.5 39.7  93.938       .       .     .  93.147
     93   .6570842         .         . 11.613963         . 13.7 17.5    . 24.7 35.6    93.2       .       .  76.6       .
     94   .3285421         .         .  11.47707         .   17    .    . 28.2    .  84.827       .       .    91       .
     95   .3504449         .         .  12.42163         . 15.7    .    . 27.8    .  105.99       .       . 111.9       .
     96   1.267625   5.28679         .  12.42163 21.982204 14.6 18.6    . 25.8 35.4 111.806  95.752       .  95.5 100.477
     97   1.434634         .         .  12.67625         . 18.1    .    . 29.4    . 116.016       .       . 109.9       .
     98  1.0924025         .         .         .  22.58179 13.7    .    .    . 35.2 103.556       .       .     .  83.587
     99   .3696099         .         . 11.329226  23.00342 18.9    .    . 29.9 41.6 102.585       .       . 110.4 103.578
    100   .4626968         .         .         .  22.72964 18.9    .    .    . 41.1  65.465       .       .     .  91.719
    end


    Code:
    ** Generate time variables from the first date in our data material (Oct 3 95) **
    gen t1 = PartDat_YH1BLM - 13059
    gen t2 = PartDat_YH2LuM - 13059
    gen t3 = PartDat_YH3LuM - 13059
    gen t4 = PartDat_NT3BLQ1 - 13059
    gen t5 = PartDat_NT4LuM - 13059
    
    forval i = 1/5 {
    replace t`i' = t`i'/365.25
    }

    Code:
    ** Rename age variables **
    gen age1 = PartAg_YH1BLQ
    gen age2 = PartAg_YH2BLQ
    gen age3 = PartAg_YH3BLQ
    gen age4 = PartAg_NT3BLQ1
    gen age5 = PartAg_NT4BLQ1
    Code:
    * Run -traj- using a censored normal approach *
    traj, var(FEV1_1 FEV1_2 FEV1_3 FEV1_4 FEV1_5) indep(t1-t5) risk (Sex) model(cnorm) min(-999) max(999) order(2 2 2 2 2 2 2)
    or (if age on x-axis):

    Code:
    * Run -traj- using a censored normal approach *
    traj, var(FEV1_1 FEV1_2 FEV1_3 FEV1_4 FEV1_5) indep(age1-age5) risk (Sex) model(cnorm) min(-999) max(999) order(2 2 2 2 2 2 2)
    Code:
    * Use -trajplot- to plot the trajectories *
    trajplot, xtitle(Time(years)) ytitle(ppFEV1) xlabel(0(1)25) ylabel(50(10)130)
    (image)

    or (if age on x-axis):

    Code:
    * Use -trajplot- to plot the trajectories *
    trajplot, xtitle(Time(years)) ytitle(ppFEV1) xlabel(13(1)34) ylabel(50(10)130)
    Click image for larger version

Name:	Graph1.jpg
Views:	1
Size:	86.7 KB
ID:	1730565






    Attached Files

  • #2
    I'm sorry, somehow the wrong picture file was posted in the end. Here are the resulting graphs (with the correct file format):

    Click image for larger version

Name:	Graph_age.png
Views:	1
Size:	78.8 KB
ID:	1731144
    Click image for larger version

Name:	Graph_time.png
Views:	1
Size:	82.0 KB
ID:	1731145

    Comment


    • #3
      I don't use this command, but I notice that you have a number of missing values in the dataset in #1. Have you checked whether the missing ages are present in the estimation sample? I am assuming that the command identifies this sample below:

      Code:
      * Run -traj- using a censored normal approach *
      traj, var(FEV1_1 FEV1_2 FEV1_3 FEV1_4 FEV1_5) indep(age1-age5) risk (Sex) model(cnorm) min(-999) max(999) order(2 2 2 2 2 2 2)
      sum age1-age5 if e(sample) 

      Comment

      Working...
      X