course problem on statistics

Upload: majid-khorsand-vakilzadeh

Post on 04-Jun-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 course problem on statistics

    1/14

    ModifiedHandinAssignment1

    RandomvariablegenerationandMonteCarlointegration

    ComputerIntensiveStatisticalMethods

    MajidKhorsandVakilzadeh

    Lecturer:AndersSjgren

    2013

    Nov

    03

  • 8/13/2019 course problem on statistics

    2/14

    1

    Table of Contents

    Introduction ..................................................... ....................................................... ........... 1

    Hand-in assignment 1 .......................................................................................................... 1

    Task 1- Generate Random Variables ..... ...... ..... ..... ...... ..... ...... ..... ...... ...... ..... ...... ..... ...... ...... ... 1Part a- Standard normal variables from cauchy distribution ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. 1

    Part b ............................................................................................................................... 4

    Task 2 ................................................................................................... ........................... 7

    part a ................................................. ........................................................ ...................... 7

    part b .............................................................................................................................. 10

    Introduction% This report provides the Matlab code written for hand-in assignment 1

    % accompanied with a brief explanation of different parts which for the

    % sake of simplicity are included in Matlab script in green color.

    Hand-in assignment 1-------Random Variable Generation and Monte-Carlo Integration------------

    clc

    clear

    Task 1- Generate Random Variables

    Part a- Standard normal variables from cauchy

    distribution% In this part two embeded accept-reject algorithm is used:

    % 1. To yield Cauchy variable from uniformly distributed R.V.s

    % so, in the first part f= (pi*b*(1+((x-a)/b)^2))^-1 (cauchy pdf)

    % and g= U[xi,xf](defined on the support of interest),

    %

    % 2. Accepted variable in the previous step are used in the second

    % Accept-Reject step to generate the Standard Normal Variables

    % so, in the second part

    % f = (sqrt(2*pi*sig^2))^-1*exp(-(x-mio)^2/2/sig^2) (Normal pdf)

    % and g is obtained cauchy distribution in the previous step,

    %

    Ns = 100000; % Desired number of samples

    a=0; % Parameter values for the standard cauchy

    b=1; % Parameter values for the standard cauchy

    % support ofthe uniform distribution

    xi=-10;

    xf=10;

  • 8/13/2019 course problem on statistics

    3/14

    2

    % Normalizing Factor for the 2nd accept-reject method

    M2= 1.5; % Is chosen such that the peak value of the cauchy at x=0 be more

    % that standard normal distribution

    % Normal distribution

    sig=1; mio=0;

    % Algorithm

    i=0;r=0;j=0;

    whilej

  • 8/13/2019 course problem on statistics

    4/14

    3

  • 8/13/2019 course problem on statistics

    5/14

    4

    Part b=================Simulating from a Gamma distribution====================

    ==============with noninteger shape and scalling factor==================

    % In this part first the exp(1) R.V.s are generated by transforming

    % u~U[0,1] using -log(1-u), then we know that if Xj are i.i.d exp(1)

    % variables, then Y=B*(sum(Xj)), for j=1:A, is distributed by ga(a,b)

    % Note: A and B are natural numbers

    %

    % Finally the resulted gamma(A,B) are used in Accept-Reject step tp generate

    % ga(4.3,6.2)

    Ns = 10000; % Desired number of samples

    A1=4; % shape factor for gamma distribution(instrumental pdf)

    B1=7; % Scale factor for gamma distribution(instrumental pdf)

    A2= 4.3; % shape factor for gamma distribution (Target pdf)

    B2= 6.2; % scale factor for gamma distribution (Target pdf)

    % Normalizing constant

    M=1.2;

    % Algorithm

  • 8/13/2019 course problem on statistics

    6/14

    5

    i=0;r=0;

    whilei

  • 8/13/2019 course problem on statistics

    7/14

    6

  • 8/13/2019 course problem on statistics

    8/14

  • 8/13/2019 course problem on statistics

    9/14

    8

    fprintf('The probability of delay is %4.2f%%\n',sum(I)/Ns*100)

    % part a.c

    Delay_Pr = cumsum(I)./(1:Ns);

    sigma=sqrt(cumsum((I-Delay_Pr).^2))./(1:Ns);

    figureplot(1:Ns,Delay_Pr,'r');hold on

    plot(1:Ns,Delay_Pr+1.96*sigma,'g');hold on

    plot(1:Ns,Delay_Pr-1.96*sigma,'g')

    title('convergence plot for Probability of delay')

    legend('Probability of delay','Based on CLT')

    xlabel('sample size')

    figure

    forR=1:100

    T1 = binornd(1,.2,1,Ns).*lognrnd(1,.1,1,Ns);

    T2 = lognrnd(0,.25,1,Ns);

    T3 = lognrnd(0,.3,1,Ns);

    T4 = lognrnd(0,.2,1,Ns); T = T1 + T2 + T3 + T4;

    I=T>4;

    Delay_Pr = cumsum(I)./(1:Ns);

    plot(1:Ns,Delay_Pr,'r');hold on

    end

    title('convergence plot for Probability of delay')

    xlabel('sample size')

    % As seen the variability of the expected profit is more when we repeat the

    % experiment 100 times and it shows that CLT provides uncertainty bounds

    % which are too confident

    The expected time-to-completion is 3.64%

    The 95% confidence interval for time-to-completion is 0.00%

    The probability of delay is 22.91%

  • 8/13/2019 course problem on statistics

    10/14

    9

  • 8/13/2019 course problem on statistics

    11/14

    10

    part b

    T1 = binornd(1,.2,1,Ns).*lognrnd(1,.1,1,Ns);

    T2 = lognrnd(0,.25,1,Ns);

    T3 = lognrnd(0,.3,1,Ns);

    T4 = lognrnd(0,.2,1,Ns);T = T1 + T2 + T3 + T4; % Time-To-Completion

    Profit = 200 + 50 * randn(1,Ns);

    D=(T-4);D(D

  • 8/13/2019 course problem on statistics

    12/14

    11

    fprintf('Probability of loosing money is %4.2f%%\n',CI95)

    Probability of profit of 100MSEK or more is 0.81%

    Probability of loosing money is 0.00%

  • 8/13/2019 course problem on statistics

    13/14

    12

  • 8/13/2019 course problem on statistics

    14/14

    13

    Published with MATLAB R2013a