Code for  Decision Theory for Statistical Problems
                (N.T. Longford)  SpringerBrief 2012


Chap0.an1   --  Elementary/auxiliary functions used in several chapters
Chap0.an2   --  Functions for optimisation:  Newton and Newton-Raphson algorithms


CHAPTER 2
Chap1.an1  --  Newton-Raphson algorithm for minimising the expected loss
                         (piecewise quadratic loss function;  Example 1)
Function  Chap1 --  result objects  Chap1R  (Table 2.1, page 23) and Chap1S

Chap1.an2  --   Graphics for the result  Chap1S from Chap1.an1  (Figure 2.2, page 24)
Function  Chap1G  --  using  Chap1S  

Chap1.an3  --  Illustration of the LINEX loss  --  Figure 2.3, page 27 
Function  LNX

Chap2.an0  --  Illustration of quadratic loss functions  --  Figure 2.1, page 20
Function  Ch2qua  --  piecewise quadratic function

Chap2.an1  --  Decision about the sign of the expectation of a normal random sample
                         (piecewise quadratic loss)
Function  Ch2sgn  --  result objects  Ch2sgnR  (single application), 
                                    Ch2sgnS  (application en masse)

Chap2.an2  --  Decision about the sign of the expectation of a normal random sample
                         (piecewise linear loss)
Function  Ch2sgnL  --  result objects  Ch2sgnLR  (single application), 
                                      Ch2sgnLS  (application en masse)

Chap2.an3   --  Graphics for the results in Chap2.an1 and Chap2.an2  
(Figure 2.4, page 31)
Function Ch2Gra 

CHAPTER 3
Chap3.an1  --  Function  H_n  and the MSEs of alternative estimators
Vectors  Ch3Hn and Ch3MSE  (Figure 3.1, page 35)

Chap3.an2  --  Estimating $\sigma^2$ with piecewise linear loss; page 36
Function  Ch3VL
List Ch3VLs  (application of Ch3VL en masse)
Vectors  Ch3ptr and Ch3ptn  --  the values of  R  and  n  for evaluation of Ch3VLs

Chap3.an4  --  Graphics for Ch3VLS  (Figure 3.2, page 37)
Matrix  Ch3VL1  --  an extract from  Ch3VLs

Chap3.an5  --  Newton method for estimating $\sigma$ with quadratic loss
Function:  Ch3VQ;  auxiliary function  Ch3H  ($Hn$)
Objects  Ch3VQr  --  single application;  Ch3VQr (overwrite)  --  application en masse

Chap3.an6  --  Application of  Ch3VQ  en masse
Object  Ch3VQs  --  results for Ch3ptr ($R$)  and  Ch3ptn  ($n$)

Chap3.an7  --  Graphics for Ch3VQs (Chap3.an6,  Figure 3.3, page 39) 

Chap3.an8  --  Graphics for Ch3VLs and Ch3VQs  (Figure 3.4, page 39)
Comparison of the coefficients for the linear and quadratic loss
Matrix Ch3cd  --  extract from Ch3VLs and Ch3VQs


Chap3A.an1  --  Newton-Raphson alg. for the equilibrium with multiplicative loss
Variance vs. constant, Sect. 3.3, page 40
Function  Ch3MA   (an alternative in  Chap3A.anA)
Matrix Ch3MAr  --  Single application of  Ch3MA (detailed output)

Chap3A.an2  --  Application of Ch3MA en masse
Vectors Ch3MAn and Ch3MAp --  settings of the values of  n  and  R
List  Ch3MAs  --  all the results

Chap3A.an3  --  Graphics for  Cha3MAs  (Figure 3.5, page 43)

Chap3B.an1  --  Check on the expression for c*, page 43, bottom 
Function  Ch3Fshr  --  output  Ch3FshrR  (a short vector) and a diagram


CHAPTER 4
Chap4.an1 -- Illustration of an equilibrium function and a set of priors
Figure 4.1, page 54

Chap4E.an1  --  Comparing two normal random samples 
Equilibrium priors  --  quadratic kernel loss
Function  Chap4EQ
Settings (vectors) RR, si2s;  results list  Chap4EQr

Chap4E.an2  --  Comparing two normal random samples 
Equilibrium priors  --  linear kernel loss
Function  Chap4EL
Settings (vectors) RR, si2s;  results list  Chap4ELr

Chap4E.an3  --  Comparing two normal random samples 
Equilibrium priors  --  absolute kernel loss
Function  Chap4EA
Settings (vectors) RR, si2s;  results list  Chap4EAr

Chap4E.an4  --  Graphics for the output of Chap4E.an1  --  .an3
Figure 4.2, page 55
Equilibrium functions with the three kernel losses 
Function Chap4EG

Chap4E.an6  --  Comparing two t-distributed random samples 
Finding the equilibrium priors  --  quadratic kernel loss
Function  Chap4TQ  --  the t-distribution version of Chap4EQ
Results list  Chap4TQr  (setting vector  RR)

Chap4E.an7  --  Comparing two t-distributed random samples 
Finding the equilibrium priors  --  linear kernel loss
Function  Chap4TL  --  the t-distribution version of Chap4EQ
Results list  Chap4TLr  (setting vector  RR)

Chap4E.an8  --  Comparing two t-distributed random samples 
Finding the equilibrium priors  --  absolute kernel loss
Function  Chap4TA  --  the t-distribution version of Chap4EQ
Results list  Chap4TAr  (setting vector  RR)

Chap4E.an9  --  Graphics for the output of Chap4E.an6-8
Figure 4.3, page 60
Equilibrium functions with the three kernel losses 
Function  Chap4EH  


CHAPTER 5
Chap5.an1  -- Newton algorithm for the balance equation with a binomial trial
Absolute kernel loss
Function  Ch5Bin;  results list Ch5BinR

Chap5.an2  --  Graphics for the results from  Chap5.an1
Figure 5.1, page 66 
Function  Ch5BinG;  result matrix Ch5BinGr

Chap5.an3  --  Newton algorithm for the balance equation with a binomial trial
Linear kernel loss
Function Ch5BinL;  results list Ch5BinLR

Chap5.an4  --  Newton method for the balance equation with a binomial trial
Quadratic kernel loss
Function Ch5BinQ;  results list Ch5BinQR

Chap5.an5  --  Graphics for the results from  Chap5.an3 and 4
##  Figure 5.2, page 68
Function  Ch5BinG2; results vector  Ch5BinG2r


Chap5P.an1  --  Decision theory with the Poisson distribution
Absolute kernel loss  - Newton algorithm for the balance equation 
Function  Ch5Poi;  results list Ch5PoiR

Chap5P.an2  --  Decision theory with the Poisson distribution
Linear kernel loss  - Newton algorithm for the balance equation 
Function  Ch5PoiL;  results list Ch5PoiLR

Chap5P.an3  --  Decision theory with the Poisson distribution
Quadratic kernel loss  - Newton algorithm for the balance equation 
Function  Ch5PoiQ;  results list Ch5PoiQR

Chap5.an5  --  Graphics for the results from  Chap5P.an1-3
Equilibrium analysis for the Poisson
Figure 5.3, page 71
Function  Ch5PoiG; results list  Ch5PoiGr


CHAPTER 6
Chap6.an1  -- Optimal thresholds in classifications will all three kernel losses
Function  Ch6cla; results matrix Ch6claR 

Chap6.an2  --  Application of the function  Ch6cla en masse
Results list  Ch6claS  (setting vectors,  si2s and mus;  rho=2.0)

Chap6.an3  --   Application of the function  Ch6cla en masse
Near-replica of Chap6.an2  (different value of  rho, 0.5)
Results list  Ch6claT  (setting vectors,  si2s and mus)

Chap6.an4  --  Graphics for the results from  Chap6.an2 and Chap6.an3
##  Figure 6.1, page 79
Function  Ch6claG; results list Ch6claGr

Chap6.an6  --  Example of a mixture of normals for the exceptions
##  Figure 6.2, page 84;  DATASET  Chap6xc.dat
Function  Ch6Exc; results list Ch6ExcR

Chap6.an7  --  Newton-Raphson algorithm for setting the thresholds $c_L$ and $c_H$
Ordinary and exceptional units
SUPERSEDED  BY  .an8  and  .an9
Function  Ch6excT;  results matrix/vector Ch6excT  --  deleted

Chap6.an8  --  Newton algorithm for setting the thresholds $c_L$ and $c_H$
Ordinary and exceptional units
Function  Ch6excNT; results list  Ch6excNTr

Chap6.an9  --  Newton-Raphson algorithm for setting the thresholds $c_L$ and $c_H$
Ordinary and exceptional units
Function  Ch6excNR; results list Ch6excNRr 
Note:  the highest value for which there is convergence:  R=349.117
(cL and cH  both close to  0.200)

Chap6A.an1 --  Classification with a range of values of  R
Results matrix  Ch6excNRs  (settings vector Rs)

Chap6.an2  --  Graphics for Ch6excNRr, the results  from  Chap6A.an1
##  Figure 6.3, page 86


CHAPTER 7
Chap7.an0  --   Generate the population sizes and illiteracy rates in a country
Function  Ch7SA0  (with graphics);  dataset  Ch7SAD  --  DATASET  Chap7.dat

Chap7.an1  --  The illiteracy rate and the population size in the districts
Figure 7.1, page 97
Intermediate objects Ch7nat, Ch7mx1

Chap7.an2  --  Functions used in other Chap7.an* files
Functions  Ch7dss (stratified sampling),
                  Ch7Esi (moment matching estimation); results vector Ch7EsiS
                  Ch7zst (finding z*)
                  Ch7bds (finding b-star)
                   Ch7smr (summarising a replication)

Chap7.an3  --  One application of the functions in  Chap7.an2
RESULTS LOCKED IN FOR  Table 7.1, page 98
Intermediate objects Ch7zstR (z*'s), Ch7dssR (a sample), Ch7EsiR (between-
   district variance matrix - estimate), Ch7bdsR (coefficients b_d*), 
   Ch7smrR (losses - summary list)

Chap7.an4
Auxiliary function  Lmean
Settings -- RRs (penalty ratios), nRs (number of R's), nrp (number of replicates)
Intermediate objects -- Ch7zstR (z*s), Ch7bdsT, Ch7bdsU, Ch7bdsV, Ch7bdsW
Ch7dssS, Ch7bdsS
Summary list  Ch7smrS 

Chap7.an5 --  Graphics for the district-wise empirical expected losses
##  Figure 7.2, page 99
Function Ch7gra, results vector Ch7graR


CHAPTER 8  
Chap8.an1  --  Illustration of the ranges of $\hDelta$ which result in an impasse
Figure 8.1, page 106  (Scenarios A and B)
Function  Ch8an1

Chap8.an2  --  Finding z-star  for sample size calculation (design)
Functions Ch8zst (all three kernels), Ch8exl
Results lists Ch8zstR and Ch8exlR 

Chap8.an3  --  Evaluation of the probability of impasse and the expected loss
Function Ch8ssz 
Results vector Ch8sszR (single application); 
Ch8sszT  -- Table 8.1, page 107  (sample size calculation)
Ch8sszT  -- a table with an alternative setting

Chap8.an4  --  More detailed exploration following Chap8.an3
Result lists Ch8sszU, Ch8sszU2  (setting vector n1t)

Chap8.an5  --  Narrower range of plausible values of $\delta$
Results list Ch8sszV, Ch8sszV2 (settings vector n1t)

Chap8.an6  --  Graphics for comparing wide and narrow range of plausible priors
Using the results lists Ch8sszU, Ch8sszV, Ch8sszU2
Figure 8.2, page 109
Function Ch8grc, results matrix Ch8grcR

Chap8.an7  --  Simulation with dropout
Auxiliary function Table (reformatting)
Principal function  Ch8drp;  results lists Ch8drpS, Ch8drpT 
Settings vector Ch8dlts (deltas)

Chap8.an8  --  Graphics for the results from  Chap8.an7 
Figure 8.3, page 110;  probabilities of decision and impasse
Function  Ch8grad 

