代写 R C statistic theory Question A

Question A
Laboratory I
Test01 v1 Probability 2018 November 08
Theory Question
Statistics Probability for Data Science and

Check our slideset on Conditional Probability Independence:
Mutually: PAflBflCPAPBPC;
Pairwise: PAflBPAPB,andPAflCPAPCandPBflCPBPC;
Given 3 events, A, B and C, define what does it mean for them to be mutually, pairwise and conditionally independent.
Conditionally: For example PA fl B C PA C PB C.
A box contains 100 coins. 60 of these coins are balanced and the remaining 40 are not. In particular, each of the unbalanced coin will give you an Head with probability 13. We run the following experiment: extract a coin at random from the box, flip it, observe the result, and then put the coin back into the box.
1. What is the probability to observe an Head?
Lets write the solution in terms of random indicator functions instead of events. So let
B I have selected a balanced coin and X IB Y1 if B occurs; Then simply by the law of total probability we get 0 otherwise.
pPHeadPHeadX1PX1PHeadX0PX01 3 1 2 13 0.43. 2 5 3 5 30
k n 2. Find the probability of observing exactly k Head in n independent replications of the experiment
k 6 n. Is it a wellknown distribution? Use R to calculate this probability for k 3 and n 10.

it is clear that Sn is distributed as a Binomn, p 0.43. Hence
PS10 3 dbinom3, size 10, prob 0.43 0.19
Denoting by Sn the following random variable
Sn Number of Heads in n independent replications of the experiment,
10 3
3. Let N be a discrete uniform random variable over the set U 1, 2, . . . , 100, and suppose to replicate the experiment N times i.e. a random number of times. Assuming to have observed Head exactly 3 times, find the probability of having flipped the coin N 10 times.
1

We can simply use Bayes Theorem to get:
where
1 1 20.19 0.002
PS 3N 10PN 10 PN10S 3q100 N ,
N 3 100 100 100
N PS n1 N
3N nPN n
PS 3 N 10PN 10 1102p31p1031 1 2 dbinom3, size 10, prob 0.43
q100 PS 3N nPN n1 1 2q100 PS 3N n1 1 2q100 1n2p31 n1 1N 2 100 n3 N 100 n3 3
pn3 1 sumdbinom3, size 3:100, prob 0.43 0.023. 100
More directly
PN 10SN 3 dbinom3, size 10, prob 0.43
0.08.
4. Write a simulation in R to check or get the answer to part 4.. Meaningfully comment the result.
sumdbinom3, size 3:100, prob 0.43
Simulation setup
M 106 Simulation size
p 0.43 Prob of Head
For reproducibility
set.seed123
Run
n.vec sample 1:100, size M, replace T
s.vec sapply n.vec, functionx rbinomn 1, size x, prob p
Table of proportion
idx whichs.vec 3 when weve got 3 Heads
tt prop.table table n.vecidx distribution of N SN 3 approx Plot
plottt, type h, cex.axis .5, col gray.7, lty 3,
xlab N, ylab Frequency pointsas.numericnamestt, ctt, pch 21, bg yellow points10, tt10, pch 21, bg red
ablineh 0.08, col rgb1,0,0,.4, lwd 2
In particular
tt10 quite close to the theoretical value of 0.08
10
0.0821231
345678910 12 14 16 18 20 22 24 26 28 30 34
N
2
Frequency 0.00 0.04 0.08 0.12

Question B
Theory Question
Random variables can be discrete, that is, taking any of a specified finite or countable list of values, endowed with a probability mass function characteristic of the random variables probability distribution; or continuous, taking any numerical value in an interval or collection of intervals, via a probability density function that is characteristic of the random variables probability distribution.
Definition: Given a probability space , P, a random vector, or pvariate random variable, is any measurable mapping
X : Rp
that assigns a pdimensional vector XE to each individual outcome E .
Assuming that X, Y is a continuous random vector with joint density function fX,Y x, y, we have that X and Y are independent if and only if fX,Y x, y fX x fY y.
Check our slideset on Correlation, Linear Dependence and the Multivariate Normal Distribution: X,Yindependent X,Yuncorrelated,
the viceversa is true only for Gaussian random vectors. In all the other cases, the fact that X, Y are uncorrelated may just mean that their dependency if any is highly nonlinear.
X and Y have the following discrete joint pmf:
p x,yYcxy forx1,0,1, andy1,0,1,
X,Y 0 otherwise.
To start with, for the sake of simplicity lets unfold the joint pmf compactly defined above:
XY 1 0 1
1 0 c 2c 3c pX,Y x, y 0 c 0 c 2 c 1 2c c 0 3c
3c 2c 3c 1
1. Determine the value of the constant c that makes the previous function a true joint pmf.
Summing up all the joint masses we must get 1 or even any marginal, so
y p x,y
x, y 1 … 10 c 2 c c 02 1 … 8 c 1 … c 1. X,Y 8
2. Determine the conditional distribution of X Y 0, its expectation and variance. By simply normalizing the second column of the table we get
3

PX1Y 0p
PX0Y 0pX,Y0,000,
1,0 1 1, X,Y 8
p0 2 2 Y8
p0 2 Y8
PX1Y 0p EXY 011 0011 0
1,0 1 1. X,Y 8
p0 2 2 Y8
Hence
VarXY 0EX2Y 0121 020121 1.
22 22
3. Find the covariance of X and Y .
We know that CovX, Y EX Y EX EY , where
EXEY13 02 13 0; 888
EXY11pX,Y1,110pX,Y1,011pX,Y1,1 112 112 1.
882
Hence,
CovX, Y EX Y 1 . 2
4. Find the distribution of the random variable Z Y 4 and calculate its median. Since Y 1,0,1 Z 0,1 with pmf pZ given by
p 0PZ 0PY 0p 0 1; ZY4
p 1PZ1P1Y 1fiY 12p 1p 13. Z YY4
In other symbols, we can simply say that Z is Bernoulli with probability of success equal to p 3 0.75. 4
Consequently its median, that is the value that cuts at its left at least 50 of the probability mass, is equal to 0.
Take a quick look
z c0,1
pz c14, 34
parmfrow c1,2
Plot PMF
plotz, pz, type h, axes F,
col rgb0,0,0,.2, xlab z, ylab PMF axis1, z, c0, 1, cex.axis .75
pointsz, pz, pch 19, col orange
Plot CDF
plotstepfunz, c0, cumsumpz, right F,
xlim c1,2, axes FALSE,
do.points T, verticals T, col.hor black, col.ver rgb0,0,0,.2, col.points orange, pch 19,
main , xlab z, ylab CDF
4

axis1, c1, z, 2, c, 0, 1, , cex.axis .75 axis2, c0, 12, 1, c0, 0.50, 1, cex.axis .75 ablineh .5, col rgb1,0,0,.4, lwd 3
0101
zz
5
PMF
CDF
0 0.50 1

Question C
This is essentially Exercise 6 from the Exercises from remote corners of the multiverse section of
TrainSetP102.
Hence, suppose that a married couple is selected at random from a certain population married couples. . . and that the joint distribution of W the height of the wife and H the height of her husband is a bivariate normal distribution.
Suppose that the heights of the wives have a mean of W 170 cm and a standard deviation of W 4 cm, the heights of the husbands have a mean of H 178 cm and a standard deviation of H 2 cm, and the correlation between these two heights is fl 0.68.
1. If I tell you that, in our randomly selected couple, the wife is 173 cm tall, what is the best mse prediction for the height of her husband? What about the reliability of this prediction? Explain and, possibly, quantify.
From the set of notes on conditional expectation, we know the optimal predictor is the conditional mean of X given Y , but they are bivariate Normal so from the cheatsheet we get
EH W 173cm H fl173cm 178cm2cm 0.68173cm178cm 176.3cm H W 4cm
2. What is the probability that, in the randomly chosen couple, the wife is taller than the husband?
We must determine the value of PW H 0. Since W and H have a bivariate Normal distribution, it follows that the distribution of W H will be univariate Normal, with mean
EW HEWEH170cm178cm8cm
2 VarWHVarWVarH2CovW,HW2 H2 2flWH
and variance
42 22 20.68429.12cm2.
Hence the standard deviation of is O9.12 3.02 cm. So, N,2 , and the probability we are looking for is given by
P 0 1 P 0 1 pnorm0, 8, 3.02 0.004, . . . quite rare indeed.
. . . of
W
6