Finishing up with the Bang
. infile veloc dist using case0701.asc
'velocity' cannot be read as a number for veloc[1]
'distance' cannot be read as a number for dist[1]
(25 observations read)
. regress dist veloc, nocons
Source | SS df MS Number of obs = 24
---------+------------------------------ F( 1, 23) = 101.14
Model | 24.048893 1 24.048893 Prob > F = 0.0000
Residual | 5.46890204 23 .237778349 R-squared = 0.8147
---------+------------------------------ Adj R-squared = 0.8067
Total | 29.517795 24 1.22990813 Root MSE = .48763
------------------------------------------------------------------------------
dist | Coef. Std. Err. t P>|t| [95% Conf. Interval]
---------+--------------------------------------------------------------------
veloc | .0019218 .0001911 10.057 0.000 .0015265 .0023171
------------------------------------------------------------------------------
As derived in class, the conversion from megaparsecs/km/sec to years
(in billions) is obtained by multiplying the regression coefficient by
the product of 3.26 (the number of light-years per parsec) and
299.792 (the number of kilometers in one light-second x 10^{-3}).
. display 3.26 * 299.792 * .0019218
1.8782173
Designing a Screening Test (AFP)
. clear
. use afpnorm
. count
1411
. summarize afp
Variable | Obs Mean Std. Dev. Min Max
---------+-----------------------------------------------------
afp | 1407 40.46923 19.85923 4.669257 349.324
. count if afp>80
50
. di 50/1411
.03543586

graph afp, histogram saving(a)
. graph afp, histogram saving(a)

graph afp, histogram bin(50) saving(b)
. graph afp, histogram bin(50) saving(b)

graph afp, oneway saving(c)
. graph afp, oneway saving(c)

graph afp, oneway jitter(2) saving(d)
. graph afp, oneway jitter(2) saving(d)

graph afp, oneway jitter(2) box saving(f)
. graph afp, oneway jitter(2) box saving(f)
. summarize afp, detail
Alpha-fetoprotein
-------------------------------------------------------------
Percentiles Smallest
1% 13.17077 4.669257
5% 19.08685 6.820958
10% 22.53343 7.078061 Obs 1407
25% 28.61698 8.908448 Sum of Wgt. 1407
50% 36.78168 Mean 40.46923
Largest Std. Dev. 19.85923
75% 48.6183 136.5922
90% 61.2522 153.546 Variance 394.389
95% 70.59787 242.2572 Skewness 4.434543
99% 106.2718 349.324 Kurtosis 53.67288
. lookup percentile
[R] centile . . . . . . . . . . . Report centile and confidence interval
(help centile)
[R] codebook . . . . . Produce a codebook describing the contents of data
(help codebook)
[R] collapse . . . . . . . . . . . . Make dataset of means, medians, etc.
(help collapse)
[R] diagplots . . . . . . . . . . . . . . Distributional diagnostic plots
(help diagplots)
[R] egen . . . . . . . . . . . . . . . . . . . . . Extensions to generate
(help egen)
[R] lv . . . . . . . . . . . . . . . . . . . . . . . Letter-value displays
(help lv)
[R] pctile . . . . . . . . . . . . Create variable containing percentiles
(help pctile)
[R] qreg . . . . . . . . . . . . . Quantile (including median) regression
(help qreg)
[R] summarize . . . . . . . . . . . . . . . . . . . . Summary statistics
(help summarize)
[R] table . . . . . . . . . . . . . . . . . Tables of summary statistics
(help table)
. help centile
[ OUTPUT FROM THE help COMMAND has been omitted here ]
. centile afp, centile(50 75 95 97.5)
-- Binom. Interp. --
Variable | Obs Percentile Centile [95% Conf. Interval]
---------+-------------------------------------------------------------
afp | 1407 50 36.78168 35.61309 37.56226
| 75 48.6183 47.07178 49.95195
| 95 70.8102 67.62652 75.41453
| 97.5 83.78058 78.91603 89.77014

graph afp gestwk, saving(g)
. graph afp gestwk, saving(g)
. drop if gestwk<=14
(3 observations deleted)
. drop if gestwk>20
(3 observations deleted)
In order for the graph command to produce different figures
for each value of a grouping variable, the data set needs to be
sorted in order of that grouping variable first.
. sort gestwk

graph afp, box by(gestwk) saving(h)
. graph afp, box by(gestwk) saving(h)

graph lafp, box by(gestwk) saving(j)
. graph lafp, box by(gestwk) saving(j)
. regr lafp gestwk
Source | SS df MS Number of obs = 1401
---------+------------------------------ F( 1, 1399) = 211.20
Model | 31.8475509 1 31.8475509 Prob > F = 0.0000
Residual | 210.963012 1399 .150795577 R-squared = 0.1312
---------+------------------------------ Adj R-squared = 0.1305
Total | 242.810563 1400 .173436116 Root MSE = .38832
------------------------------------------------------------------------------
lafp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
---------+--------------------------------------------------------------------
gestwk | .1235966 .0085048 14.533 0.000 .1069131 .1402801
_cons | 1.552031 .1420225 10.928 0.000 1.273431 1.830631
------------------------------------------------------------------------------
. predict yhat
. gen cutoff = yhat + 1.96* 0.38832
. sort gestday

graph lafp cutoff gestday, s(oi) c(.l) saving(k)
. graph lafp cutoff gestday, s(oi) c(.l) saving(k)