Matlab Programs for Pstat 160

 

Few basic matlab functions:
bin.m gives the pdf of a Binomial. Input are n and p.

disc.m simulate a discrete random variable. Input is a vector that gives the pmf

discsamp.m as disc.m but the output is a sample of size n. Inputs are n, p

poirv.m Simulate a Poisson random sample, useing the inverse transform Inputs are n and lambda

poisrv.m An alternative to the previsous one to simulate a Poisson random variable, Input is lambda

plotgeo.m Simulate a sample from a geometric. Plot an histogram with empirical (red bars) and theoretical (black lines) values. Inputs are n and p

plotpoi.m Same as previous, but for Poisson. Inputs are n and lambda.

compound.m Simulate a compound random variable. Here use the Poisson ditribution and discsamp.

runs.m simulate the length of first and second run in coin tosses.

randwalk.m simulate a random walk, Input are n (steps) and p (probability up)

rwpb.m gives the probabilities P(S_n=b). Inputs are n and p.

mc.m simulate a markov chain. Inputs are the transition matrix P and the number of steps n. Use the function disc.m above, with the output of the form (0,0,..,1,0..0).

mcabs.m simlate a markov chain as in the previous program, but in addition plot the 2 process with absorbing (i, to be chose) states as seen in class. Inputs are P,i,n. Edit the file to chose the initial state.

rwcount.m Parameters are n,p,k. Simulate k times a random walk with p and draw empirical and theoretical value of the probability distribution of Xn.

gibbs.m An example of a Gibbs sampler Open it to check what are the functions that are required.

metropois.m An example of Metropolis-Hasting algorithm to simulate Poisson random variables. Requires disc.m


Programs for Pstat160B

gamrej.m Simulate a Gamma random variable using an Exponential

poisson.m Simulate a Poisson Process. Input are the rate lambda and the terminal time T.

PP.m Very similar to poisson.m, but using "while".

nhPP.m Simulate a non-homogeneous Poisson process using rejection method

trapro.m Compute and plot the transition probability of a continuous time MC

MMs.m simulate a MMs queue and the ocupation time

bd.m simulate a linear birth and death process

gast.m simulate the B&D process of the gas station example.

ctmc.m simulate a continuous time Markov chain. Input is the transition rate matrix Q and time. Output is a graph and the time spend on each state.

ctstation.m Gives the limiting probabilities for a continuous time Markov Chain. Input is Q

rwscale.m simulate a random walk and test different scales.

stock.m simulate a stock price according to the Binomial model. Input are u,d,r and n, the number of steps. Output gives a plot of the stock price according to the risk neutral probability and the discounted stock price.

corgeo.m simulate a sequence of pairwise correlated Bernoulli. Inputs are p_1=P(X_1=1), p_2=P(X_2=1) and p_12=P(X_1=1,X_2=1)

boxmueler.m simulate 2 independent standard normal

boxmueler.m simulate a sample of size n of random normal vector with covariance matrix W.