Docsity

cheat sheet for intoduction to data science, Cheat Sheet of Data Mining

Toggle sidebar
bg1
ltimore
Bivariate Normal Distribution The random vector (X, Y )
has the bivariate normal distribution with means µX = E[X]
and µY = E[Y ], variances σX2 = Var(X) and σY2 = Var(Y ),
and correlation ρ = Corr(X, Y ) if it has joint p.d.f. f(x, y) =
1
2
π σ xσy
√
1−
ρ
2exp
{
−
[
zX
2
(
X
)
+
zY
2
(
y
)
−2
ρ Z X
(
x
)
ZY
(
y
)
]
2(1−
ρ
2)
}
Where ZX(x) =( x-µx)/ σx and ZY(y) =( y-µY)/ σY (example
height and weight can be a bivariate model distbn as they are
corelated). This distribution is easily generalized to the
multivariate case. Multivariate Normal Distribution The
random vector X = (X1, . . . , Xk) T has the multivariate
normal distribution with mean vector µ = (µ1, . . . , µk) T and k
× k covariance matrix Σ = (σij ) if it has p.d.f. f(x) = ((1/ ((2π)
k/2|Σ| 1/2 ))exp { − ((x − µ)TΣ −1 (x − µ))/2 } , x ∈ Rk . It turns
out that E[Xi] = µi , Var(Xi) = σii, Cov(Xi , Xj ) = σij .
Notation: X ∼ Nork(µ, Σ).
In order to generate X, let’s start with a vector Z = (Z1, . . . ,
Zk) of i.i.d. Nor(0,1) RV’s. That is, suppose Z ∼ Nork(0, I),
where I is the k × k identity matrix, and 0 is simply a vector
of 0’s. Suppose we can find the (lower triangular) Cholesky
matrix C such that Σ = CCT . Similar to the one-dimensional
result in which a linear function of a normal RV is still
normal, it can be shown that X = µ + CZ is multivariate
normal with mean µ and covariance matrix Σ ≡ Cov(X) =
Cov(µ + CZ) = C Cov(Z)CT = CICT = CCT or, Σ= E[(CZ)
(CZ)T] = E[(CZZTCT] = C(E[(ZZT])CT = CCT
For k = 2, we can derive after a teensy bit of algebra, C = ((√
σ11) 0 (σ12/√σ11) √ (σ22 – (σ212/ σ11 )) . (There are other
solutions depending on how we deal with “±” cases of the
square roots.) Since X = µ + CZ, we have X1 = µ1 + c11Z1 = µ1
+ √ (σ11 Z1) , X2 = µ2 + c21Z1 + c22Z2 = µ2 + (σ12 /√ σ11) Z1 +
(√(σ22 – (σ212/ σ11)) Z2 The following algorithm computes
C for general k: Algorithm LTM For i = 1, . . . , k, For j = 1, .
. . , i − 1, cij ← ( σij – Σl=1j=1 cilcjl) /cjj, cji ← 0 cii ← ( σij – Σ l=1
j=1 cilcjl)2 , Once C has been computed, the multivariate normal
RV X = µ + CZ can easily be generated: 1. Generate Z1,
Z2, . . . , Zk ∼ i.i.d. Nor(0, 1). 2. Let Xi ← µi + Σj=1i cilZj), for i
= 1, 2, . . . , k. 3. Return X = (X1, X2, . . . , Xk). Generating
Stochastic Processes: Markov chain, if today’s weather
only depends on yesterday, then you have a Markov chain.
Let: Xi =0 if it rains on day I, o’wise Xi=1, Denote day to day
transition prob by Pjk = P(state k in day i +1| state j in day i ),
where j,k =0,1, suppose prob state transition matrix is P= (0.7
0.3 0.4 0.6) =(0 1 0 1)
P(R|Xi-1) Ui Ui<P.0
?
R/S
M Rain
Tu P00 =0.7 0.62 Y Rain
W P00 = 0.7 0.83 N Sun
T
H
P10 = 0.4 0.91 N S
Generating Poisson Arrivals When the arrival rate is a
constant λ, the interarrivals of a Poisson(λ) process (PP) are
i.i.d. Exp(λ) arrival time are random, and the arrival times are:
T0 ← 0 and Ti ← Ti−1 – (1/ λ )ln(Ui), i ≥ 1. Now suppose that
we want to generate a fixed number n of PP(λ) arrivals in a
fixed time interval [a, b]. To do so, we note a theorem stating
that the joint distribution of the n arrivals is the same as the
joint distribution of the order statistics of n i.i.d. U(a, b) RV’s.
Generate i.i.d. U1, . . . , Un from U(0, 1) Sort the Ui’s: U(1) <
U(2) < · · < U(n) Set the arrival times to Ti ← a + (b − a)U(i).
Nonhomogeneous Poisson Process — nonstationary arrivals:
Same assumptions as regular Poisson process except the
arrival rate λ isn’t necessarily a constant, so stationary
increments may not apply. Let λ(t) = rate (intensity) function
at time t, N(t) = number of arrivals during [0, t].
Then N(s+t) − N(as) ∼ Poisson (
∫
s
s
+
t
λ
(
u
)
du).
Ex. Suppose that the arrival pattern to the Waffle House over
a certain time period is a NHPP with λ(t) = t2 . Find the
probability that there will be exactly 4 arrivals between times
t = 1 and 2. First of all, the number of arrivals in that time
interval is
N(2) − N(1) ∼ Poisson (
∫
1
2
t
2
dt) ~ Pois(7/3), Thus, P
N(2) − N(1) = 4 =( e −7/3(7/3)4) /4! = 0.120 : Don’t use: Ti+1 ←
Ti – (1/ (λ(Ti))) ln(U): the arrival rate λ(Ti) doesn’t keep pace
with changes in λ(t) that might occur between the current
arrival at time Ti and the next arrival at time Ti+1. The
Thinning Algorithm. . . Assumes that λ*≡ maxt λ(t) < ∞;
Generates potential arrivals at the rate λ*; and Accepts (keeps)
a potential arrival at time t with probability λ(t)/λ* . Remark:
Thinning is an Acceptance-Rejection method. Very nice, but
if λ* is higher than most of the values that λ(t) takes, then
thinning can be inefficient. Arena and other simulation
languages use a different method when generating NHPP
arrivals from an Arrival Schedule. That’s because such a
schedule gives λ(t) as a step function that only changes
occasionally, say, every hour. In this case, it’s possible to take
clever advantage the exponential’s memoryless property to
avoid the use of thinning
First-Order Moving Average Process An MA(1) is a time
series process is defined by Yi = εi + θεi−1, for i = 1, 2, . . .,
where θ is a constant and the εi’s are i.i.d. Nor(0, 1) RV’s that
are independent of Y0. The MA(1) is a popular tool for
modeling and detecting trends. It’s easy to show that Y1,
Y2, . . . are all Nor(0,1 + θ 2). But the Yi’s aren’t
independent! Define the covariance function, Rk ≡ Cov(Yi ,
Yi+k), k = 0, ±1, ±2, . . .. For the MA(1), we have R0 = Var(Yi)
= 1 + θ 2 , R1 = Cov(Yi , Yi+1) = θVar(εi) =θ , and Rk = 0 for k
≥ 2. So the covariances die off pretty quickly. How to
generate? Start with ε0 ∼ Nor(0, 1). Then generate ε1 ∼
Nor(0, 1) to get Y1, ε2 ∼ Nor(0, 1) to get Y2, etc.
First-Order Autoregressive Process An AR(1) process is
defined by Yi = φYi−1 + εi
, for i = 1, 2, . . ., where −1 < φ < 1,
Y0 ∼ Nor(0, 1), and the εi’s are i.i.d. Nor(0, 1 − φ 2 ) .If not
Normal system will be unsationary, RV’s that are indepnt of
Y0. This is used to model lots of real-world stuff.
First-Order Exponential Autoregressive Process An EAR(1) process
(Lewis 1980) is defined by Yi =
{
φ Y i
−1
, w . p . φ
φ Y i
−1+
εi, w . p
1−
φ
for i =
1, 2, . . ., where 0 ≤ φ < 1, Y0 ∼ Exp(1), and the εi’s are i.i.d. Exp(1)
RV’s that are independent of Y0. The EAR(1) has the same
covariance structure as the AR(1), except that 0 ≤ φ < 1, that is,
Cov(Yi , Yi+k) = φ |k| for all
Autoregressive Pareto (ARtoP): Process Now let’s see how to
generate a series of correlated Pareto RV’s. First of all, a RV X has
the Pareto distribution with parameters λ > 0 and β > 0 if it has c.d.f.
FX(x) = 1 − (λ/x)β , for x ≥ λ. The Pareto is a flat or heavy-tailed
distribution that has a variety of uses in statistical modeling, and for
which E[X] = βλ/β − 1 for β > 1 and Var(X) = βλ2/((β − 1)2(β − 2))
for β > 2.
In order to obtain the ARP process, let’s start off with a regular
AR(1) with normal noise, Yi = ρYi−1 + εi , for i = 1, 2, . . ., where −1
< ρ < 1, Y0 ∼ Nor(0, 1), and the εi’s are i.i.d. Nor(0, 1 − ρ2) and
independent of Y0. Note that Y0, Y1, Y2, . . . are marginally
Nor(0,1) but correlated. Feed this process into the Nor(0,1) c.d.f.
Φ(·) to obtain correlated Unif(0,1) RV’s, Ui = Φ(Yi), i = 1, 2, . . ..
Now feed the correlated Ui’s into the inverse of the Pareto c.d.f. to
obtain correlated Pareto RV’s: Xi = F−1X (Ui) = F−1X (Φ(Yi))
= λ/ [1 − Φ(Yi)]1/β , i = 1, 2,.. MM1 Q: Consider a single-server
queue with customers arriving according to a Poisson(λ) process,
standing in line with a FIFO discipline, and then getting served in an
Exp(µ) amount of time.{µ> λ and serv t< arriv t}. Let Ii+1 denote the
interarrival time between the ith and (i + 1)st customers; let Si be the
ith customer’s service time; and let WQi denote the ith customer’s
wait before service. Lindley gives a very nice way to generate a
series of waiting times for this simple example: WQi+1 = max{WQi +
Si − Ii+1, 0}. And similarly, the total time in system, Wi = WQi + Si, is
Wi+1 = max{Wi − Ii+1, 0} + Si+1.###### Brownian Motion:
Discovered by Robert Brown; analyzed rigorously by Einstein; and
mathematics established by Wiener (also called Wiener process).
Widely used in everything from financial analysis to queueing theory
to statistics to other OR/IE application areas. Incredibly important.
Definition: The continuous-time stochastic process {W(t), t ≥ 0} is
a standard Brownian motion process if: 1. W(0) = 0. 2. W(t) ∼
Nor(0, t). 3. {W(t), t ≥ 0} has stationary and independent
increments. Increments: Anything like W(b) − W(a). Stationary
increments informally means that the distribution of W(t + h) − W(t)
only depends on h. Independent increments: If a < b < c < d, then
W(d) − W(c) is indep of W(b) − W(a). How do you generate BM
on a computer? Suppose that Y1, Y2, . . . is any sequence of i.i.d.
RV’s with mean zero and variance 1. (To some extent, the Yi’s don’t
even have to be independent!) Donsker’s Central Limit Theorem
says that
1
√ n
∑
i
=1
¿}
Yi → W
(
t
)
as n → ∞
¿
¿
a
where d → denotes convergence in distribution as n gets big,\\ is
floor function Remark: The regular CLT is just for the case t = 1, so
that the thing converges to W(1) ∼ Nor(0, 1). Donsker is a much
more general process CLT. Now the thing converges to an entire BM
process {W(t)} for all t — not just a single, wussy Nor(0,1) RV.
Here’s a way to construct BM: One choice that works well is to
take Yi = ±1, each with probability 1/2. Take n at least 100, t = 1/n,
2/n, . . . , n/n, and calculate W(1/n), W(2/n), . . . , W(n/n). Another
choice is simply to take Yi ∼ Nor(0, 1), i = 1, 2, . . .. Exercise: Let’s
construct some BM! First, pick some “large” value of n and start
with W(0) = 0. Then W (i/ n) = W ((i – 1) /n ) + Yi /√ n , i = 1, 2, . .
{properties of Brownian Motion:# BM is continuous everywhere,
but has no derivatives! (Pretty deep result.) #Cov(W(s),W(t)=
min(s,t)#Area under W(t) is normal:
∼
Nor(0, 1/ 3 ). #A Brownian bridge, B(t), is conditioned BM such that
W(0) = W(1) = 0.(used in financial analysis)#Cov(B(s), B(t)) =
min(s, t) − st. #
∫
0
1
B
(
t
)
dt
∼ Nor(0, 1 12 )}.
Histogram: if you take enough obs, histogram will cover true
distribution, Stem and leaf diagram: if you turn histogram on
its side and add some numbersWhich distribution? Discrete
vs conti, univariate/multi , how much data is available, are
experts around to ask about nature of dada.What if you do not
have much data- you can guess 1) Discrete: Discrete?
Bernoulli(p) (success prob p) ,Binomial(n, p) (# successes in
n Bern(p) trials), Geometric(p) (# Bern(p) trials until first
success), Negative Binomial/Pascal distribution: how many
trials do you need for tenth sucess , Poisson(λ) (counts #
arrivals over time), Empirical (“sample” distribution):if we do
not have good model for discrete data
Continuous? Uniform (not much known from the data, except
maybe min and max possible values), Triangular (know min,
max, “most likely” values), Exponential(λ) (interarrival times
from a Poisson process), Normal (good model for heights,
weights, IQs, sample means, etc.), Beta (good for specifying
bounded data) Gamma, Weibull, Gumbel, lognormal
(reliability data), Empirical (“sample” distribution)
** if you hypothesize it is normal: Fall approximately on a
straight line when you do graph it on a normal probability plot.
It should also pass goodness-of-fit tests for normality.
Estimation Definition: A statistic is a function of the obsns
X.. Xn, and not explicitly dependent on any unknown
paramtrs. EX: X¯, S2 . Statistics are random variables. If we
take two different samples, we’d expect to get two different
values of a statistic. A statistic is usually used to estimate some
unknown parameter from the underlying probability
distribution of the Xi’s. Ex of parameter: θ,2. Let X1, . . . , Xn
be i.i.d. RV’s and let T(X) ≡ T(X1, . . . , Xn) be a statistic
based on the Xi’s. Suppose we use T(X) to estimate some
unknown parameter θ. Then T(X) is called a point estimator
for θ, Xbar is usually a point estimator for mean u = E[Xi], and
S2 is often point estimator for variance 2 = Var(Xi).
Properties of T(X): Exp value = parameter trying to estimate, it
should have low variance. Def: T(X) is unbaised for θ if
E[T(X)]= θ, EX:Therom: Suppose X1..Xn, Then E(
X
) = E[
1
n
∑
i
=1
n
Xi
¿
=
1
n
[
∑
i
=1
n
Xi
]
=
E
[
Xi
]
=
μ
So,
X
) is always unbiased for . That’s why
X
is sample
mean. Ex. X1…Xn are iid Exp(λ), then
X
=is unbaised
for=E[Xi]=1/λ, 1/
X
is biased for λ in this exponential case
ie, E[1/
X
]= λ. Ex. Suppose X1..Xn are iid anything with
μ
∧
var σ
2
. Then E[S2] = E[
∑
i
=1
n
¿¿¿
=
var(Xi)= 2 , S2 is always unbiased for 2, so S2 is called
sample variance. Ex. Suppose X1..Xn iid Exp(λ),then S 2
is
unbiased 1/λ 2
. S2=
∑
i
=1
n
¿¿¿
since E[Xi]= E[
X
] and
var(Xi)/n =2/n, we have E[S2]= 2 . Remark S is biased for SD
.
Estimator is unbiased if its exp value = true parameter
value. Being unbiased doesn't necessarily mean the estimator is
the best one, because an estimator that is unbiased can still be
very far off the true value for any particular sample. We
generally prefer :both low bias and low variance, these two are
often at odds with each other, known as the bias-variance
tradeoff.Good Estimator properties: Low bias(difference
between the expected value of an estimator and the true value
of the parameter it is estimating), Low variance(measures the
spread of the estimator. Lower variance implies that the
estimator values are more tightly clustered and hence, more
precise)Low Bias + high var = bad meaning less noisy
estimator, Low Var + high bias = bad (confident of wrong
answer)Example: Suppose that X1, . . . , Xn iid∼ U(0, θ), i.e.,
the p.d.f. is f(x) = 1/θ, 0 < x < θ. We’ll look at three unbiased
estimators(easy0: Y1 = 2
X
, Y2 = (n+1)/ n max1≤i≤n Xi
Easy Estimator: Y1 = 2
X
, Proof (it’s unbiased): E[Y1] =
2E[
X
¿
, = 2E[Xi ] = θ. Harder Estimator: Y2 = n+1 n
max1≤i≤n Xi . Why might this estimator for θ make sense?
E[M}=
∫
0
θ
yfM
(
y
)
dy
=¿∫
0
θn yn
θn
=
nθ
n
+1¿
** the bias of estimator T(x) is Bias[T]= E[T]- θ, The MSE
of T(X) is MSE(T)= E[(T- θ)2]
MSE(T)= Var(T) + (E[T]- θ)2= var + bias2 Lower MSE is
better-even if ther is little bias .Definition: The relative
efficiency of T2(X) to T1(X) is MSE(T1(X))/MSE(T2(X)). If
this quantity is < 1, then we’d want T1. Maximum Likelihood
Estimators Definition: Consider an i.i.d. random sample
X1..Xn, where each Xi has pdf/pmf f(x). Further, suppose that
θ is some unknown parameter from Xi . The likelihood function
is L(θ) ≡
∏
i
=1
n
f
(
xi
)
. Definition: The m MLE of θ
is the value of θ that maximizes L(θ). The MLE is a function of
the Xi’s and is a RV.For (Exp) . Find the MLE for λ. L(λ) = Y
∏
i
=1
n
λ e
−
λx
=
λn
exp
⁡
(−∑
i
=1
n
xi
). Now maximize L(λ) with respect to λ. Could take the
derivative and plow through all of the horrible algebra. Too
tedious. Trick: λ that maximizes L(λ) also maximizes ln(L(λ))!
So, ln(L(λ)) = ln(
λn
exp
⁡
(−∑
i
=1
n
xi
)) =
nln(
λ
)−∑
i
=1
n
xi
so taking next derivative and
setting it zero
^
λ
=
1
X
*** for Bern(p) finf MLE for p,
sicnce Xi =
{
1℘
p
0℘1−
p
Pmf F(x) = px(1-p)1-x, x=0,1, zero
^
p
=
X
, so E[X]=p
##
^
σ
2
is very close to unbaised sample variance than S2. S2
=
n
n
−1
σ
2
,
^
σ
2
is a little bit biased, but it has
Let H0: X1..Xn iid~Exp(λ). χ2 gof for equal prob. intervals. The amount
to choose ai’s such that F(ai) = P(X<=ai) = 1-
e
−
λ a i
=
i
k
I = 1,2..k. ai = -
1
λ
ln
(
1−
i
k
)
,i
=1
,
2.
.k
,
^
λ
=1
X,so ,
-
X
ln
(
1−
i
k
)
S=1 ** Weibull(r,λ), cdf F9x) = 1-exp[-(λx)r] for x>=0, Note r=1 yields
Exp(λ) as aspecial case. χ2 gof for equal prob. Intervals we need F(ai) =
1-
e
−(
λ a i
)
r
=
i
/
k
, ai = -
1
λ
ln
(
1−
i
k
)
1/
r
,i
=1
,
2.
.k
Here s= 2 for r,λ so
λ
=( ∑
i
=1
n
xi
r
)−1/
r
How to
soleve for r? trail and error-blech, bisection, newton method.
Implementation of Newton 1) Initialize,
^
r
0=
X
S
X
is
samplemean and S2 is sample variance 2)update
^
rj←
^
rj
−1−
g
(
^
rj
−1)
g '
(
^
rj
−1)
3, if |g
(
^
rj
−1
)
∨¿0.001
then stop and set MLE
^
rj
=
^
rj
−1
ows let j
← j
+1
and go to step 2.
Kolmogorov-Smirnov GOF Test: The K-S test is one that works well
in low-data situations. We’ll test H0 : X1,X2, . . Xn iid∼ some
distribution with cdf F(x). Recall the definition of the empirical c.d.f.
( sample c.d.f.) of the data, X1, X2.. Xn, Fˆn(x) ≡ (number of Xi<=x)/n.
Note that Fˆ n(x) is a step function with jumps of height 1/n (every time
an observation occurs). For example, here’s the empirical c.d.f. of 10
Exp(1) observations that I generated (along with the Exp(1) c.d.f.).
Fn(x) is step function with height 1/n(every time observation occurs).
The Glivenko-Cantelli Lemma says that Fˆn(x) → F(x) for all x as n →
∞. So if H0 is true, then Fˆn(x) should be a good approx.. to the true cdf,
F(x), for large n. Does the empirical dist. support that H0 is true? The K-
S test rejects H0 if D ≡ max |F(x) − Fˆn(x)| > Dα,n, where α is the level
of significance, and Dα,n is a K-S quantile that depends on the
hypothesized c.d.f. F(x). Ex. H0 : X1,X2, . . Xn iid∼U(0,1), D ≡
max0<=x<=1|x − Fˆn(x)| . max can only occur when x equals one of the
observations, X1, X2,.. Xn, i.e., at one of the jump points of Fˆn(x). The
ith jump point, Fˆ n(x) increases from (i−1)/n to i/n . ## Can easily apply
K-S to other distributions. Many other g-o-f tests: Anderson-Darling,
Cramér-von Mises, Shapiro-Wilk, etc. S-W is especially appropriate for
testing normality. Can also use graphical techniques such as Q–Q plots
to evaluate normality##
you have to be careful about. 1. No / little data: a) ask experts and find
min, max, most likely dist. Values, then guess U or Tria distbn, getting
quantiles from experts is much better, discuss the nature of obs b) if you
have some ideas about RVs you can guess the distb: D or C, obs success
or failures think Bern, bin, geom, neg binol. Poisson assumptions:Then
Poisson (if you’re counting arrivals) or exponential (interarrival times).
Are obs avg or sum: N. obs bounded:beta. Reliability or job times:
gamma, Weibull, lognormal, etc. Can you think of anything else from
the physical characteristics underlying the RV? Explosion, Price of
stock: lognornal 2. Data that doesn’t look like one of the usual
distributions(eg binormal) : ost package can’t pick up mix of two N.
Can attempt to model as a mixture of reasonable distributions. Easier:
sample from the empirical distribution or a smoothed version of the
empirical. This is a form of bootstrapping.
3. Nonstationary data (from distributions than change over time)
Suggestion: Nonhomogeneous Poisson process. (Recall from RV
Generation module.) Need to model rate function properly. Arena uses
piecewise-constant rate function; so specify a constant arrival rate for
each separate period.
4. Multivariate / correlated data: Examples: Multivariate RV — A
person’s height and weight are correlated. Serially correlated examples:
Monthly unemployment rates. Arrivals to a social media site may be
correlated if an interesting item appears there and the public gets wind of
it. A badly damaged part may require more service than usual at a series
of stations. If a server gets tired, his subsequent service times may be
longer than usual.
So what do you need to do? *Identify multivariate / serial correlation
situations. -Propose appropriate models. Examples: Multivariate normal
for heights and weights. -Time series models for serially correlated
observations, e.g., autoregressive-moving average ARMA(p, q),
EAR(1), ARTOP, which we discussed back in Module 7. *Estimate
relevant parameters (easier said than done). Examples: Multivariate
normal: Marginal means and variances (no big deal) plus covariances
(maybe not so easy). Time series: For simple models like the AR(1),
estimating the coefficient φ is easy (just like covariance). But
coefficients for more-complicated models need to be estimated using
available software, e.g., Box-Jenkins technology. *Validate to see if
your estimated model is actually any good.* Alternative: Can bootstrap
samples from an empirical distribution (if you have enough data).
Demo Time! Arena has very nice functionality that automatically fits
simple distributions to your data. Just go to Tools > Input Analyzer. The
Input Analyzer gives you the “best” distribution from its library, along
with relevant sample and goodness-of-fit statistics ExpertFit is a
specialty product that does distribution fitting with a larger library of
distributions. Minitab and R have distribution fitting functionality,
though not quite convenient as the above tools., they have some issue
dealing with problem children.Output Analayis:As input process
areRVs: Output RV and output are never iid N.Simulation run yield:
estimates of measure of system. As random there is sampling error
Measure of interest: Means, Variances, quantiles,success probabilities.
Customer waiting time:
skewed to right and are never less than 0, not
identical and are not indep as they are serially correlated. It’s difficult to
apply classical techniques to analysis of simulation output. Raison
d’Être: Give methods to perform statistical analysis of output from
discrete-event computer sim. Why?*statistical analysis can invalidate all
results *Tremendous applications if you can get it right* Lots of cool
research problems out there## Types of Simulations 1)Finite-Horizon
Simulations : The termination of a finite-horizon simulation takes place

Partial preview of the text

Download cheat sheet for intoduction to data science and more Cheat Sheet Data Mining in PDF only on Docsity!

ltimore

Bivariate Normal Distribution The random vector (X, Y ) has the bivariate normal distribution with means μX = E[X] and μY = E[Y ], variances σX^2 = Var(X) and σY^2 = Var(Y ), and correlation ρ = Corr(X, Y ) if it has joint p.d.f. f(x, y) =

2 π σ x σ y √ 1 − ρ

2 exp^ {

−[ z X

( X ) + z (^) Y

( y )− 2 ρ Z X ( x ) Z Y ( y ) ]

Where ZX(x) =( x-μx)/ σx and ZY(y) =( y-μY)/ σY (example height and weight can be a bivariate model distbn as they are corelated). This distribution is easily generalized to the multivariate case. Multivariate Normal Distribution The random vector X = (X1,... , Xk) T has the multivariate normal distribution with mean vector μ = (μ1,... , μk) T^ and k × k covariance matrix Σ = (σij ) if it has p.d.f. f(x) = ((1/ ((2π) k/2|Σ| 1/2 (^) ))exp { − ((x − μ)TΣ −1 (^) (x − μ))/2 } , x ∈ Rk (^). It turns out that E[Xi] = μi , Var(Xi) = σii, Cov(Xi , Xj ) = σij. Notation: X ∼ Nork(μ, Σ). In order to generate X, let’s start with a vector Z = (Z1,... , Zk) of i.i.d. Nor(0,1) RV’s. That is, suppose Z ∼ Nork(0, I), where I is the k × k identity matrix, and 0 is simply a vector of 0’s. Suppose we can find the (lower triangular) Cholesky matrix C such that Σ = CCT^. Similar to the one-dimensional result in which a linear function of a normal RV is still normal, it can be shown that X = μ + CZ is multivariate normal with mean μ and covariance matrix Σ ≡ Cov(X) = Cov(μ + CZ) = C Cov(Z)CT^ = CICT^ = CCT^ or, Σ= E[(CZ) (CZ)T] = E[(CZZTCT] = C(E[(ZZT])CT = CCT For k = 2, we can derive after a teensy bit of algebra, C = ((√ σ 11 ) 0 (σ12/√σ11) √ (σ22 – (σ^212 / σ 11 )). (There are other solutions depending on how we deal with “±” cases of the square roots.) Since X = μ + CZ, we have X 1 = μ 1 + c 11 Z 1 = μ 1

  • √ (σ 11 Z1) , X 2 = μ 2 + c 21 Z 1 + c 22 Z 2 = μ2 + (σ 12 /√ σ11) Z 1 + (√(σ22 – (σ^212 / σ11)) Z 2 The following algorithm computes C for general k : Algorithm LTM For i = 1,... , k, For j = 1,.

.. , i − 1, cij ← ( σij – Σ j=1 l=1j=1^ cilcjl) /cjj, cji ← 0 cii ← ( σij – Σ (^) l= cilcjl)^2 , Once C has been computed, the multivariate normal RV X = μ + CZ can easily be generated: 1. Generate Z1, Z2,... , Zk ∼ i.i.d. Nor(0, 1). 2. Let Xi ← μi + Σj=1i^ cilZj), for i = 1, 2,... , k. 3. Return X = (X1, X2,... , Xk). Generating Stochastic Processes: Markov chain , if today’s weather only depends on yesterday, then you have a Markov chain. Let: Xi =0 if it rains on day I, o’wise Xi=1, Denote day to day transition prob by Pjk = P(state k in day i +1| state j in day i ), where j,k =0,1, suppose prob state transition matrix is P= (0. 0.3 0.4 0.6) =(0 1 0 1) P(R|Xi-1) Ui Ui<P. ?

R/S

M Rain Tu P 00 =0.7 0.62 Y Rain W P 00 = 0.7 0.83 N Sun T H

P 10 = 0.4 0.91 N S

Generating Poisson Arrivals When the arrival rate is a constant λ, the interarrivals of a Poisson(λ) process (PP) are i.i.d. Exp(λ) arrival time are random, and the arrival times are: T0 ← 0 and Ti ← Ti−1 – (1/ λ )ln(Ui), i ≥ 1. Now suppose that we want to generate a fixed number n of PP(λ) arrivals in a fixed time interval [a, b]. To do so, we note a theorem stating that the joint distribution of the n arrivals is the same as the joint distribution of the order statistics of n i.i.d. U(a, b) RV’s. Generate i.i.d. U1,... , Un from U(0, 1) Sort the Ui’s: U(1) < U(2) < · · < U(n) Set the arrival times to Ti ← a + (b − a)U(i). Nonhomogeneous Poisson Process — nonstationary arrivals: Same assumptions as regular Poisson process except the arrival rate λ isn’t necessarily a constant, so stationary increments may not apply. Let λ(t) = rate (intensity) function at time t, N(t) = number of arrivals during [0, t].

Then N(s+t) − N(as) ∼ Poisson ( ∫

s s + t λ ( u )du). Ex. Suppose that the arrival pattern to the Waffle House over a certain time period is a NHPP with λ(t) = t^2. Find the probability that there will be exactly 4 arrivals between times t = 1 and 2. First of all, the number of arrivals in that time interval is

N(2) − N(1) ∼ Poisson (∫

t

2 dt) ~ Pois(7/3), Thus, P

N(2) − N(1) = 4 =( e −7/3(7/3)^4 ) /4! = 0.120 : Don’t use: Ti+1 ← Ti – (1/ (λ(Ti))) ln(U): the arrival rate λ(Ti) doesn’t keep pace with changes in λ(t) that might occur between the current arrival at time Ti and the next arrival at time Ti+1. The Thinning Algorithm... Assumes that λ≡ maxt λ(t) < ∞; Generates potential arrivals at the rate λ; and Accepts (keeps) a potential arrival at time t with probability λ(t)/λ^. Remark: Thinning is an Acceptance-Rejection method. Very nice, but if λ^ is higher than most of the values that λ(t) takes, then thinning can be inefficient. Arena and other simulation languages use a different method when generating NHPP arrivals from an Arrival Schedule. That’s because such a schedule gives λ(t) as a step function that only changes occasionally, say, every hour. In this case, it’s possible to take clever advantage the exponential’s memoryless property to avoid the use of thinning First-Order Moving Average Process An MA(1) is a time series process is defined by Yi = εi + θεi−1, for i = 1, 2,.. ., where θ is a constant and the εi’s are i.i.d. Nor(0, 1) RV’s that are independent of Y0. The MA(1) is a popular tool for modeling and detecting trends. It’s easy to show that Y1, Y2,... are all Nor(0,1 + θ 2 ). But the Yi’s aren’t independent! Define the covariance function, Rk ≡ Cov(Yi , Yi+k), k = 0, ±1, ±2,.. .. For the MA(1), we have R0 = Var(Yi) = 1 + θ 2 , R1 = Cov(Yi , Yi+1) = θVar(εi) =θ , and Rk = 0 for k ≥ 2. So the covariances die off pretty quickly. How to generate? Start with ε0 ∼ Nor(0, 1). Then generate ε1 ∼ Nor(0, 1) to get Y1, ε 2 ∼ Nor(0, 1) to get Y 2 , etc. First-Order Autoregressive Process An AR(1) process is defined by Yi = φYi−1 + εi , for i = 1, 2,.. ., where −1 < φ < 1, Y0 ∼ Nor(0, 1), and the εi’s are i.i.d. Nor(0, 1 − φ 2 ) .If not Normal system will be unsationary, RV’s that are indepnt of First-Order Exponential Autoregressive Process An EAR(1) process (Lewis 1980) is defined by Yi =

φ Y (^) i − 1 , w. p. φ φ Y (^) i − 1 + ε (^) i , w. p 1 − φ for i = 1, 2,.. ., where 0 ≤ φ < 1, Y 0 ∼ Exp(1), and the εi’s are i.i.d. Exp(1) RV’s that are independent of Y 0. The EAR(1) has the same covariance structure as the AR(1), except that 0 ≤ φ < 1, that is, Cov(Yi , Yi+k) = φ |k| for all Autoregressive Pareto (ARtoP): Process Now let’s see how to generate a series of correlated Pareto RV’s. First of all, a RV X has the Pareto distribution with parameters λ > 0 and β > 0 if it has c.d.f. FX(x) = 1 − (λ/x)β^ , for x ≥ λ. The Pareto is a flat or heavy-tailed distribution that has a variety of uses in statistical modeling, and for which E[X] = βλ/β − 1 for β > 1 and Var(X) = βλ^2 /((β − 1)^2 (β − 2)) for β > 2. In order to obtain the ARP process, let’s start off with a regular AR(1) with normal noise, Yi = ρYi−1 + εi , for i = 1, 2,.. ., where − < ρ < 1, Y0 ∼ Nor(0, 1), and the εi’s are i.i.d. Nor(0, 1 − ρ^2 ) and independent of Y0. Note that Y0, Y1, Y2,... are marginally Nor(0,1) but correlated. Feed this process into the Nor(0,1) c.d.f. Φ(·) to obtain correlated Unif(0,1) RV’s, Ui = Φ(Yi), i = 1, 2,.. .. Now feed the correlated Ui’s into the inverse of the Pareto c.d.f. to obtain correlated Pareto RV’s: Xi = F−1X (Ui) = F−1X (Φ(Yi)) = λ/ [1 − Φ(Yi)]1/β^ , i = 1, 2,.. MM1 Q: Consider a single-server queue with customers arriving according to a Poisson(λ) process, standing in line with a FIFO discipline, and then getting served in an Exp(μ) amount of time.{μ> λ and serv t< arriv t}. Let Ii+1 denote the interarrival time between the ith and (i + 1)st customers; let Si be the ith customer’s service time; and let WQi denote the ith customer’s wait before service. Lindley gives a very nice way to generate a series of waiting times for this simple example: WQi+1 = max{WQi + Si − Ii+1, 0}. And similarly, the total time in system, Wi = WQi + Si, is Wi+1 = max{Wi − Ii+1, 0} + Si+1.###### Brownian Motion : Discovered by Robert Brown; analyzed rigorously by Einstein; and mathematics established by Wiener (also called Wiener process). Widely used in everything from financial analysis to queueing theory to statistics to other OR/IE application areas. Incredibly important. Definition : The continuous-time stochastic process {W(t), t ≥ 0} is a standard Brownian motion process if: 1. W(0) = 0. 2. W(t) ∼ Nor(0, t). 3. {W(t), t ≥ 0} has stationary and independent increments. Increments: Anything like W(b) − W(a). Stationary increments informally means that the distribution of W(t + h) − W(t) only depends on h. Independent increments: If a < b < c < d, then W(d) − W(c) is indep of W(b) − W(a ). How do you generate BM on a computer? Suppose that Y1, Y2,... is any sequence of i.i.d. RV’s with mean zero and variance 1. (To some extent, the Yi’s don’t even have to be independent!) Donsker’s Central Limit Theorem

says that 1

√ n

i = 1 ¿ } Yi → W ( t ) as n → ∞ ¿

¿ a

where d → denotes convergence in distribution as n gets big,\ is floor function Remark: The regular CLT is just for the case t = 1, so that the thing converges to W(1) ∼ Nor(0, 1). Donsker is a much more general process CLT. Now the thing converges to an entire BM process {W(t)} for all t — not just a single, wussy Nor(0,1) RV. Here’s a way to construct BM: One choice that works well is to take Yi = ±1, each with probability 1/2. Take n at least 100, t = 1/n, 2/n,... , n/n, and calculate W(1/n), W(2/n),... , W(n/n). Another choice is simply to take Yi ∼ Nor(0, 1), i = 1, 2,.. .. Exercise: Let’s construct some BM! First, pick some “large” value of n and start with W(0) = 0. Then W (i/ n) = W ((i – 1) /n ) + Yi /√ n , i = 1, 2,.. { properties of Brownian Motion :# BM is continuous everywhere, but has no derivatives! (Pretty deep result.) #Cov(W(s),W(t)=

min(s,t)#Area under W(t) is normal: ∫

W ( t ) dt ∼ Nor(0, 1/ 3 ). #A Brownian bridge, B(t), is conditioned BM such that W(0) = W(1) = 0.(used in financial analysis)#Cov(B(s), B(t)) =

min(s, t) − st. #∫

B ( t ) dt ∼^ Nor(0, 1 12 )}. Histogram: if you take enough obs, histogram will cover true distribution, Stem and leaf diagram : if you turn histogram on its side and add some numbers Which distribution? Discrete vs conti, univariate/multi , how much data is available, are experts around to ask about nature of dada. What if you do not have much data - you can guess 1) Discrete : Discrete? Bernoulli(p) (success prob p) , Binomial(n, p) (# successes in n Bern(p) trials), Geometric(p) (# Bern(p) trials until first success), Negative Binomial/Pascal distribution: how many trials do you need for tenth sucess , Poisson(λ) (counts # arrivals over time), Empirical (“sample” distribution):if we do not have good model for discrete data Continuous? Uniform (not much known from the data, except maybe min and max possible values), Triangular (know min, max, “most likely” values), Exponential(λ) (interarrival times from a Poisson process), Normal (good model for heights, weights, IQs, sample means, etc.), Beta (good for specifying bounded data) Gamma, Weibull, Gumbel, lognormal (reliability data), Empirical (“sample” distribution) ** if you hypothesize it is normal : Fall approximately on a straight line when you do graph it on a normal probability plot. It should also pass goodness-of-fit tests for normality. Estimation Definition : A statistic is a function of the obsns X.. Xn, and not explicitly dependent on any unknown paramtrs. EX: X¯, S^2. Statistics are random variables. If we take two different samples, we’d expect to get two different values of a statistic. A statistic is usually used to estimate some unknown parameter from the underlying probability distribution of the Xi’s. Ex of parameter: θ,^2. Let X1,... , Xn be i.i.d. RV’s and let T(X) ≡ T(X1,... , Xn) be a statistic based on the Xi’s. Suppose we use T(X) to estimate some unknown parameter θ. Then T(X) is called a point estimator for θ, Xbar is usually a point estimator for mean u = E[Xi], and S^2 is often point estimator for variance ^2 = Var(Xi). Properties of T(X): Exp value = parameter trying to estimate, it should have low variance. Def: T(X) is unbaised for θ if E[T(X)]= θ, EX:Therom: Suppose X1..Xn, Then E( X ) = E[

n

i = 1 n Xi ¿ =

n [^

i = 1 n Xi

]

= E [ Xi ]= μ So, X ) is always unbiased for^ . That’s why X is sample mean. Ex. X1…Xn are iid Exp(λ), then X =is unbaised for =E[Xi]=1/λ, 1/ X is biased for λ in this exponential case ie, E[1/ X ]= λ. Ex. Suppose X1..Xn are iid anything with μ ∧ var σ

2. Then E[S 2 ] = E[

i = 1 n

var(Xi)= ^2 , S^2 is always unbiased for ^2 , so S^2 is called sample variance. Ex. Suppose X1..Xn iid Exp(λ), then S^2 is

unbiased 1/λ^2. S^2 =∑

i = 1 n

¿ ¿ ¿ since E[Xi]= E[ X ] and

var(Xi)/n =^2 /n, we have E[S^2 ]= ^2. Remark S is biased for SD . Estimator is unbiased if its exp value = true parameter value. Being unbiased doesn't necessarily mean the estimator is the best one, because an estimator that is unbiased can still be very far off the true value for any particular sample. We generally prefer :both low bias and low variance, these two are often at odds with each other, known as the bias-variance tradeoff. Good Estimator properties : Low bias(difference between the expected value of an estimator and the true value of the parameter it is estimating), Low variance(measures the spread of the estimator. Lower variance implies that the estimator values are more tightly clustered and hence, more precise) Low Bias + high var = bad meaning less noisy estimator , Low Var + high bias = bad (confident of wrong answer)Example: Suppose that X1,... , Xn iid∼ U(0, θ), i.e., the p.d.f. is f(x) = 1/θ, 0 < x < θ. We’ll look at three unbiased estimators(easy0: Y1 = 2 X , Y2 = (n+1)/ n max1≤i≤n Xi Easy Estimator: Y1 = 2 X , Proof (it’s unbiased): E[Y1] = 2E[ X ¿, = 2E[Xi ] = θ. Harder Estimator: Y2 = n+1 n max1≤i≤n Xi. Why might this estimator for θ make sense? E[M}=

θ

yfM ( y ) dy =¿∫

θ n y n θ

n =

nθ n + 1

** the bias of estimator T(x) is Bias[T]= E[T]- θ, The MSE of T(X) is MSE(T)= E[(T- θ)^2 ] MSE(T)= Var(T) + (E[T]- θ)^2 = var + bias^2 Lower MSE is better-even if ther is little bias .Definition: The relative efficiency of T2(X) to T1(X) is MSE(T1(X))/MSE(T2(X)). If this quantity is < 1, then we’d want T1. Maximum Likelihood Estimators Definition : Consider an i.i.d. random sample X1..Xn, where each Xi has pdf/pmf f(x). Further, suppose that θ is some unknown parameter from Xi. The likelihood function

is L(θ) ≡ ∏

i = 1 n f ( xi ). Definition: The m MLE of θ is the value of θ that maximizes L(θ). The MLE is a function of the Xi’s and is a RV. For (Exp)****. Find the MLE for λ. L(λ) = Y

i = 1 n λ e − λx = λ n

exp (−∑

i = 1 n xi ). Now maximize L(λ) with respect to λ. Could take the derivative and plow through all of the horrible algebra. Too tedious. Trick: λ that maximizes L(λ) also maximizes ln(L(λ))!

So, ln(L(λ)) = ln( λ n^ exp (−∑

i = 1 n xi )) =

nln( λ )−∑

i = 1 n xi so taking next derivative and setting it zero (^) λ^ = 1 X *** for Bern(p) finf MLE for p, sicnce Xi =

1 ℘ p 0 ℘ 1 − p Pmf F(x) = px(1-p)1-x, x=0,1, zero (^) ^ p = X , so E[X]=p

(^) σ^ 2 is very close to unbaised sample variance than S^2. S^2

=^ n n − 1 σ

2 , ^

σ

2 is a little bit biased, but it has

Let H0: X1..Xn iid~Exp(λ). χ^2 gof for equal prob. intervals. The amount to choose ai’s such that F(ai) = P(X<=ai) = 1- e −^ λ^ a^ i =^ i k I = 1,2..k. ai = -

λ

ln( 1 −

i

k )

, i = 1 ,2.. k , λ^ ^ = 1 X

,so , - X ln( 1 −

i

k )

S=1 ** Weibull(r,λ) , cdf F9x) = 1-exp[-(λx)r] for x>=0, Note r=1 yields Exp(λ) as aspecial case. χ^2 gof for equal prob. Intervals we need F(ai) = 1- e −(^ λ^ a^ i^ ) r = i / k , ai = -

λ

ln( 1 −

i

k )

1 / r , i = 1 ,2.. k

Here s= 2 for r,λ so λ =( ∑

i = 1 n x (^) i r

− 1 / r How to soleve for r? trail and error-blech, bisection, newton method. Implementation of Newton 1) Initialize, (^) r^ 0 =^ X S X is samplemean and S^2 is sample variance 2)update

r^ ^ j ← r^ j − 1 −

g ( r^ j − 1 )

g ' ( r^ j − 1 )

3, if |g

( ^^ r^ j − 1 )∨¿^ 0.001then stop and set MLE

r^ ^ (^) j = r^ (^) j − 1 ows let j ← j + 1 and go to step 2. Kolmogorov-Smirnov GOF Test: The K-S test is one that works well in low-data situations. We’ll test H0 : X1,X2,.. Xn iid∼ some distribution with cdf F(x). Recall the definition of the empirical c.d.f. ( sample c.d.f.) of the data, X1, X2.. Xn, Fˆn(x) ≡ (number of Xi<=x)/n. Note that Fˆ n(x) is a step function with jumps of height 1/n (every time an observation occurs). For example, here’s the empirical c.d.f. of 10 Exp(1) observations that I generated (along with the Exp(1) c.d.f.). Fn(x) is step function with height 1/n(every time observation occurs). The Glivenko-Cantelli Lemma says that Fˆn(x) → F(x) for all x as n → ∞. So if H 0 is true, then Fˆn(x) should be a good approx.. to the true cdf, F(x), for large n. Does the empirical dist. support that H0 is true? The K- S test rejects H0 if D ≡ max |F(x) − Fˆn(x)| > Dα,n, where α is the level of significance, and Dα,n is a K-S quantile that depends on the hypothesized c.d.f. F(x). Ex. H0 : X1,X2,.. Xn iid∼U(0,1), D ≡ max0<=x<=1|x − Fˆn(x)|. max can only occur when x equals one of the observations, X1, X2,.. Xn, i.e., at one of the jump points of Fˆn(x). The ith jump point, Fˆ n(x) increases from (i−1)/n to i/n. ## Can easily apply K-S to other distributions. Many other g-o-f tests: Anderson-Darling, Cramér-von Mises, Shapiro-Wilk, etc. S-W is especially appropriate for testing normality. Can also use graphical techniques such as Q–Q plots to evaluate normality## you have to be careful about. 1. No / little da ta: a) ask experts and find min, max, most likely dist. Values, then guess U or Tria distbn, getting quantiles from experts is much better, discuss the nature of obs b) if you have some ideas about RVs you can guess the distb: D or C, obs success or failures think Bern, bin, geom, neg binol. Poisson assumptions:Then Poisson (if you’re counting arrivals) or exponential (interarrival times). Are obs avg or sum: N. obs bounded:beta. Reliability or job times: gamma, Weibull, lognormal, etc. Can you think of anything else from the physical characteristics underlying the RV? Explosion, Price of stock: lognornal 2. Data that doesn’t look like one of the usual distributions(eg binormal ) : ost package can’t pick up mix of two N. Can attempt to model as a mixture of reasonable distributions. Easier: sample from the empirical distribution or a smoothed version of the empirical. This is a form of bootstrapping.

  1. Nonstationary data (from distributions than change over time) Suggestion: Nonhomogeneous Poisson process. (Recall from RV Generation module.) Need to model rate function properly. Arena uses piecewise-constant rate function; so specify a constant arrival rate for each separate period.
    1. Multivariate / correlated data : Examples: Multivariate RV — A person’s height and weight are correlated. Serially correlated examples: Monthly unemployment rates. Arrivals to a social media site may be correlated if an interesting item appears there and the public gets wind of it. A badly damaged part may require more service than usual at a series of stations. If a server gets tired, his subsequent service times may be longer than usual. So what do you need to do? *Identify multivariate / serial correlation situations. -Propose appropriate models. Examples: Multivariate normal for heights and weights. -Time series models for serially correlated observations, e.g., autoregressive-moving average ARMA(p, q), EAR(1), ARTOP, which we discussed back in Module 7. Estimate relevant parameters (easier said than done). Examples: Multivariate normal: Marginal means and variances (no big deal) plus covariances (maybe not so easy). Time series: For simple models like the AR(1), estimating the coefficient φ is easy (just like covariance). But coefficients for more-complicated models need to be estimated using available software, e.g., Box-Jenkins technology. Validate to see if your estimated model is actually any good. Alternative: Can bootstrap samples from an empirical distribution (if you have enough data). Demo Time! Arena has very nice functionality that automatically fits simple distributions to your data. Just go to Tools > Input Analyzer. The Input Analyzer gives you the “best” distribution from its library, along with relevant sample and goodness-of-fit statistics ExpertFit is a specialty product that does distribution fitting with a larger library of distributions. Minitab and R have distribution fitting functionality, though not quite convenient as the above tools., they have some issue dealing with problem children. Output Analayis: As input process areRVs: Output RV and output are never iid N. Simulation run yield: estimates of measure of system. As random there is sampling error Measure of interest: Means, Variances, quantiles,success probabilities. Customer waiting time: skewed to right and are never less than 0, not identical and are not indep as they are serially correlated. It’s difficult to apply classical techniques to analysis of simulation output. Raison d’Être : Give methods to perform statistical analysis of output from discrete-event computer sim. Why?statistical analysis can invalidate all results Tremendous applications if you can get it right Lots of cool research problems out there## Types of Simulations 1) Finite-Horizon Simulations : The termination of a finite-horizon simulation takes place