Lecture 6 Note
2021-07-26
Chapter 1 Goodness of Fit
1.1 Probability Model for Asset Returns
Consider a data set of daily asset percent returns:
x1,x2,…,xn
Assume the return on day t is a random variable Xt:
- The set of all possible outcomes of Xt=xt is the set of real numbers
{all possible Xt}={−∞<xt<∞}
The probability model/distribution for Xt is given by specifying the cumulative distribution function or equivalently the probability density function
Special Cases of the Probability Model in our exercise
- Case 1: Normal Model. If Xt∼Normal(μ,σ) then
f(xt)=1√2πσe−12(x−μ)2σ2
- Case 2: Laplace Model. If Xt∼Laplace(μ,b) then
f(x)=12be−|x−μ|b
1.2 Fitting Probability Models
Useful methods for estimating the parameters of a probability model are the Method-of-Moments and Maximum Likelihood.
1.2.1 Maximum Likelihood Estimation
1.2.1.1 Introduction
The Maximum Likelihood Estimation (MLE) is a method of estimating the parameters of a model. This estimation method is one of the most widely used.
The method of maximum likelihood selects the set of values of the model parameters that maximizes the likelihood function. Intuitively, this maximizes the “agreement” of the selected model with the observed data.
The Maximum-likelihood Estimation gives an uniÖed approach to estimation.
1.2.1.2 The Principle of Maximum Likelihood
We take poisson distributed random variables as an example. Suppose that X1,X2,…,XN are i.i.d. discrete random variables, such that Xi∼Pois(θ) with a pmf (probability mass function) defined as:
Pr(Xi=xi)=exp(−θ)θxixi!
where θ is an unknown parameter to estimate.
Question: What is the probability of observing the particular sample {x1,x2,…,xN}, assuming that a Poisson distribution with as yet unknown parameter θ generated the data?
This probability is equal to
Pr((X1=x1)∩⋯∩(XN=xN))
Since the variables Xi are i.i.d., this joint probability is equal to the product of the marginal probabilities:
Pr((X1=x1)∩⋯∩(XN=xN))=N∏i=1Pr(Xi=xi)
Given the pmf of the Poisson distribution, we have:
Pr((X1=x1)∩⋯∩(XN=xN))=N∏i=1exp(−θ)θxixi!=exp(−θN)θ∑Ni=1xi∏Ni=1xi!
This joint probability is a function of θ (the unknown parameter) and corresponds to the likelihood of the sample {x1,x2,…,xN} denoted by
L(x1,…,xN|θ)=Pr((X1=x1)∩⋯∩(XN=xN))
Consider maximizing the likelihood function L(x1,…,xN|θ) with respect to θ. Since the log function is monotonically increasing, we usually maximize lnL(x1,…,xN|θ) instead. We call this as loglikelihood function: ℓ(x1,…,xN|θ)=lnL(x1,…,xN|θ), or simply ℓ(θ). In this case:
ℓ(x1,…,xN|θ)=−θN+ln(θ)N∑i=1xi−ln(N∏i=1xi!)
The simplest way to find the θ that maximizes ℓ(θ) is to take a derivative.
∂ℓ(θ)∂θ=−N+1θN∑i=1xi
To make sure that we indeed maximize not minimize ℓ(θ), we should also check that the second derivative is less than 0:
∂2ℓ(θ)∂θ2=−1θ2N∑i=1xi<0
Therefore, the maximum likelihood estimator ˆθmle is:
ˆθmle=1NN∑i=1xi
For the Laplace model, the maximum-likelihood estimates are:
ˆμ=median(xt)ˆb=1nn∑i=1|xt−ˆμ|
Note that they are different from the MOM results.
1.3 Chi-Square Goodness-of-Fit Test for True Model
The Chi-Square Goodness-of-Fit (GOF) Test applies to evaluating whether sample data is consistent with coming from a given probability distribution. The evaluation compares the empirical histogram of the sample data to the theoretical histogram of the given probability distribution.
Suppose X1,…,Xnis a random sample from the probability distribution with cumulative distribution function F:
Then, the percentiles Y1,…,Yn where Yi=F(Xi) are random variables which are an i.i.d. sample from the Uniform(0,1) distribution.
We simulated a sample from the Normal(μ0,σ0) distribution with mean μ0=50 and standard deviation σ0=10. We use R to compute the realized percentiles and evaluate the goodness of fit test for whether these are consistent with being a random sample from the Uniform(0,1) distribution.
library(tidyverse) # for ggplot2
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5 ✓ purrr 0.3.4
## ✓ tibble 3.1.2 ✓ dplyr 1.0.7
## ✓ tidyr 1.1.3 ✓ stringr 1.4.0
## ✓ readr 1.4.0 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(magrittr) # for pipes and %<>%
##
## Attaching package: 'magrittr'
## The following object is masked from 'package:purrr':
##
## set_names
## The following object is masked from 'package:tidyr':
##
## extract
library(ggpubr)
set.seed(1)
=1000
samplesize0=50
mu0=10
sigma0# 1.1 Index plot of Normal Sample ----
<-rnorm(samplesize0,mean=mu0,sd=sigma0)
x0<- sort(x0)
x
# Compute probability integral transform
# y0<-pnorm(x0, mean=mu0, sd=sigma0)
=pnorm(x, mean=50, sd=10)
y# Set nclass0 (below the chisq gof tests use this variable)
=20
nclass0<-mu0
x.mu=sigma0
x.sigma# Begin True Fit Analysis
.1<-hist(100.*pnorm(x,mean=x.mu, sd=x.sigma),
histnclass=nclass0,xlab="True Percentile",
main=paste(c("Histogram: True Percentiles\n",
"Normal(mu0, sd0) Distribution\n",
"(N=",as.character(length(y)),")"),collapse=""))
abline(h=length(x)/nclass0, col="green",lwd=2)
For convenience, we have rescaled the percentiles from the (0,1) scale to (0,100) scale. The theoretical histogram for the True Percentiles is the uniform distribution. With N=1000; and nclass0 = 20; the number of bins, we expect there to be E=N/nclass0=50 sample values in each bin. This is displayed as the green level in the plot.