({{, (RefLink[RandomWalkProcess, paclet:ref/RandomWalkProcess])[p]
represents a random walk on a line with the probability of a positive unit step p and the probability of a negative unit step 1-p.}, {, (RefLink[RandomWalkProcess, paclet:ref/RandomWalkProcess])[p,q]
represents a random walk with the probability of a positive unit step p, the probability of a negative unit step q, and the probability of a zero step 1-p-q.}})

OpenersNotesSection(Spacer1)Details

(RefLink[RandomWalkProcess, paclet:ref/RandomWalkProcess]) is also known as a lattice random walk.

(RefLink[RandomWalkProcess, paclet:ref/RandomWalkProcess]) is a discrete-time and discrete-state random process.

(RefLink[RandomWalkProcess, paclet:ref/RandomWalkProcess])[p] value at time t follows (RefLink[TransformedDistribution, paclet:ref/TransformedDistribution])[2 x-t,x\[Distributed](RefLink[BinomialDistribution, paclet:ref/BinomialDistribution])[t,p]].

(RefLink[RandomWalkProcess, paclet:ref/RandomWalkProcess]) allows p and q to be real numbers between 0 and 1 such that p+q≤1.

(RefLink[RandomWalkProcess, paclet:ref/RandomWalkProcess]) can be used with such functions as (RefLink[Mean, paclet:ref/Mean]), (RefLink[PDF, paclet:ref/PDF]), (RefLink[Probability, paclet:ref/Probability]), and (RefLink[RandomFunction, paclet:ref/RandomFunction]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (23)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Simulate a one-dimensional random walk:

data=RandomFunction[RandomWalkProcess[.5],{0,30}]

ListPlot[data,Filling->Axis]

For a three-step random walk:

ListPlot[RandomFunction[RandomWalkProcess[.2,.3],{30}],Filling->Axis,InterpolationOrder->0]

Mean and variance functions:

Mean[RandomWalkProcess[p][t]]

Variance[RandomWalkProcess[p][t]]

For a three-step random walk:

Mean[RandomWalkProcess[p,q][t]]

Variance[RandomWalkProcess[p,q][t]]

Covariance function:

CovarianceFunction[RandomWalkProcess[p],s,t]

DiscretePlot3D[CovarianceFunction[RandomWalkProcess[.3],s,t],{s,0,10},{t,0,10},ExtentSize->1/2,ColorFunction->"Rainbow"]

For a three-step random walk:

CovarianceFunction[RandomWalkProcess[p,q],s,t]

DiscretePlot3D[CovarianceFunction[RandomWalkProcess[.3,.2],s,t],{s,0,10},{t,0,10},ExtentSize->1/2,ColorFunction->"Rainbow"]

OpenersExampleSection1(Spacer1)Scope  (11)

OpenersExampleSubsection0(Spacer1)Basic Uses  (5)

Simulate an ensemble of random paths:

data=RandomFunction[RandomWalkProcess[.7],{0,25},4]

ListStepPlot[data]

Compare paths for different values of the process parameter:

sample[p_]:=(SeedRandom[4];RandomFunction[RandomWalkProcess[p],{0,20}])

pars={.1,.4,.8};

ListStepPlot[sample[#],Filling->Axis,PlotLabel->StringJoin["p = ", ToString[#]]]&/@pars

Process parameter estimation:

sample=RandomFunction[RandomWalkProcess[.3,.5],{0,10^3}];

Estimate the process parameters from sample data:

EstimatedProcess[sample, RandomWalkProcess[p,q]]

Correlation function:

CorrelationFunction[RandomWalkProcess[p],s,t]

For a three-step random walk:

CorrelationFunction[RandomWalkProcess[p,q],s,t]

Absolute correlation function:

AbsoluteCorrelationFunction[RandomWalkProcess[p],s,t]

For a three-step random walk:

AbsoluteCorrelationFunction[RandomWalkProcess[p,q],s,t]

OpenersExampleSubsection1(Spacer1)Process Slice Properties  (6)

Univariate (RefLink[SliceDistribution, paclet:ref/SliceDistribution]):

DiscretePlot[Evaluate@Table[PDF[RandomWalkProcess[.8][t],x],{t,times={10,20,40}}],{x,0,40},PlotLegends->(StringJoin["t = ",ToString[#]]&/@times),PlotRange->All]

Univariate probability density:

PDF[RandomWalkProcess[p][t],x]

For a three-step random walk:

DiscretePlot[Evaluate@Table[PDF[RandomWalkProcess[.4,.2][t],x],{t,times={10,20,40}}],{x,0,20},PlotLegends->(StringJoin["t = ",ToString[#]]&/@times),PlotRange->All]

Multi-time slice distribution:

SliceDistribution[RandomWalkProcess[p],{1,3,7}]//Mean

Higher-order PDF:

PDF[RandomWalkProcess[p][{1,3,7}],{x,y,z}]

Compute an expectation of an event:

Expectation[x[t]^3,x\[Distributed]RandomWalkProcess[p,q]]

Calculate the probability of an event:

Probability[x[t]>7,x\[Distributed]RandomWalkProcess[p]]

Skewness:

DiscretePlot[Evaluate@Table[Skewness[RandomWalkProcess[p][t]],{p,pars={0.1,0.4,0.8}}],{t,1,20},PlotLegends->(StringJoin["t = ",ToString[#]]&/@pars)]

Skewness[RandomWalkProcess[p][t]]

Simple random walk is symmetric for p=1/2:

Solve[Skewness[RandomWalkProcess[p][t]]==0,p]

Limiting values:

Limit[Skewness[RandomWalkProcess[p][t]],t->∞]

Limit[Skewness[RandomWalkProcess[p,q][t]],t->∞]

For a three-step random walk:

Skewness[RandomWalkProcess[p,q][t]]

Find values of parameters for which a three-step random walk is symmetric:

sol=Solve[Skewness[RandomWalkProcess[p,q][t]]==0,{p,q}]

Plot[#[[All,2]]&/@sol,{p,0,1}]

Kurtosis:

DiscretePlot[Evaluate@Table[Kurtosis[RandomWalkProcess[p][t]],{p,pars={0.1,0.4,0.8}}],{t,1,20},PlotLegends->(StringJoin["t = ",ToString[#]]&/@pars)]

Kurtosis[RandomWalkProcess[p][t]]

Find values of the parameter for which a simple random walk is mesokurtic:

Solve[Kurtosis[RandomWalkProcess[p][t]]==3,p]

N[%]

Limiting values:

Limit[Kurtosis[RandomWalkProcess[p][t]],t->∞]

Limit[Kurtosis[RandomWalkProcess[p,q][t]],t->∞]

For a three-step random walk:

Kurtosis[RandomWalkProcess[p,q][t]]

Find values of the parameters for which a three-step random walk is mesokurtic:

sol=Solve[Kurtosis[RandomWalkProcess[p,q][t]]==3,{p,q}];

Plot[#[[All,2]]&/@sol,{p,0,1}]

(RefLink[Moment, paclet:ref/Moment]) has no closed form for symbolic order:

Moment[RandomWalkProcess[p][t],3]

Moment[RandomWalkProcess[p,q][t],3]

Generating functions:

MomentGeneratingFunction[RandomWalkProcess[p][t],w]

MomentGeneratingFunction[RandomWalkProcess[p,q][t],w]

CharacteristicFunction[RandomWalkProcess[p][t],w]

CharacteristicFunction[RandomWalkProcess[p,q][t],w]

(RefLink[CentralMoment, paclet:ref/CentralMoment]):

CentralMoment[RandomWalkProcess[p][t],5]

CentralMoment[RandomWalkProcess[p,q][t],5]

Central moment generating function:

CentralMomentGeneratingFunction[RandomWalkProcess[p][t],w]

CentralMomentGeneratingFunction[RandomWalkProcess[p,q][t],w]

(RefLink[FactorialMoment, paclet:ref/FactorialMoment]) and its generating function:

FactorialMoment[RandomWalkProcess[p][t],3]

FactorialMoment[RandomWalkProcess[p,q][t],3]

FactorialMomentGeneratingFunction[RandomWalkProcess[p][t],w]

FactorialMomentGeneratingFunction[RandomWalkProcess[p,q][t],w]

(RefLink[Cumulant, paclet:ref/Cumulant]):

Cumulant[RandomWalkProcess[p][t],4]

Cumulant[RandomWalkProcess[p,q][t],4]

Cumulant-generating function:

CumulantGeneratingFunction[RandomWalkProcess[p][t],w]

CumulantGeneratingFunction[RandomWalkProcess[p,q][t],w]

OpenersExampleSection3(Spacer1)Applications  (1)

A particle starts at the origin and moves to the right by one unit with probability 1/2 and to the left by one unit with probability 3/10 after each second. Find the probability that it has moved to the right by four units after 20 seconds:

particleMotion=RandomWalkProcess[1/2,3/10];

Movement to the right is denoted by 1 and to the left by -1:

ListLinePlot[RandomFunction[particleMotion,{0,20},3]]

Probability that the particle has moved four units to the right after 20 seconds:

Probability[x[20]== 4,x\[Distributed]particleMotion]//N

OpenersExampleSection4(Spacer1)Properties & Relations  (6)

A symmetric 3-step random walk simplifies to a 2-step random walk:

RandomWalkProcess[1/2,1/2]

(RefLink[RandomWalkProcess, paclet:ref/RandomWalkProcess]) is not weakly stationary:

WeakStationarity[RandomWalkProcess[p]]

Transition probability:

Table[DiscretePlot[Probability[(x[12]==(Subscript[x, 2]))\[Conditioned](x[7]==(Subscript[x, 1])),x\[Distributed]RandomWalkProcess[.6]],{(Subscript[x, 2]),0,13},ExtentSize->1/2,PlotLabel->StringJoin["(Subscript[x, 1]) = ",ToString[(Subscript[x, 1])]]],{(Subscript[x, 1]),{1,3,5,7}}]

Probability[(x[(Subscript[t, 2])]==(Subscript[x, 2]))\[Conditioned](x[(Subscript[t, 1])]==(Subscript[x, 1])),x\[Distributed]RandomWalkProcess[p],Assumptions->0<(Subscript[t, 1])<(Subscript[t, 2])&&0≤(Subscript[x, 1])≤(Subscript[t, 1])&&0≤(Subscript[x, 2])≤(Subscript[t, 2])]//Simplify

The correlation function of a random walk process is the same as of (RefLink[WienerProcess, paclet:ref/WienerProcess]):

CorrelationFunction[WienerProcess[μ,σ],s,t]

CorrelationFunction[RandomWalkProcess[p],s,t]

Univariate slice distribution is related to (RefLink[BinomialDistribution, paclet:ref/BinomialDistribution]):

dist=RandomWalkProcess[p][t]

Cumulative distribution function:

cdf=CDF[dist,x]

Compare with the CDF of the (RefLink[TransformedDistribution, paclet:ref/TransformedDistribution]) of a binomial distribution:

𝒟=TransformedDistribution[2 z-t,z\[Distributed]BinomialDistribution[t,p]];
CDF[𝒟,x]

cdf-%//Simplify

Simulate the proportion of the time spent on the positive side by a symmetric random walk:

RandomWalk[n_]:=RandomFunction[RandomWalkProcess[1/2],{n}];

Calculate the ratio of time spent on the positive side:

ratio[n_]:=Count[RandomWalk[n]["Values"],_?Positive]/n

In the limit the ratio has (RefLink[ArcSinDistribution, paclet:ref/ArcSinDistribution]):

sample[n_,walks_]:=Table[ratio[n],{i,walks}]

Show[Histogram[sample[10^3,10^3],20,"PDF"],Plot[PDF[ArcSinDistribution[{0,1}],x],{x,0,1},PlotStyle->Thick]]

OpenersExampleSection5(Spacer1)Neat Examples  (2)

A symmetric random walk in 2D:

SeedRandom[1234];data2d=RandomFunction[RandomWalkProcess[0.5],{0,10^3},2];

Graphics[Line[Transpose@data2d["ValueList"]],AspectRatio->Automatic]

In 3D:

data3d=RandomFunction[RandomWalkProcess[0.5],{0,10^3},3];

Graphics3D[Line[Transpose@data3d["ValueList"]],BoxRatios->Automatic]

Simulate 500 paths from a random walk process:

SeedRandom[1234];
data=RandomFunction[RandomWalkProcess[.7],{50},500];

Take a slice at 50 and visualize its distribution:

sd=data["SliceData",50];

cf=ColorData["Rainbow"];
sliced=BarChart[Last[#],Axes->False,BarOrigin->Left,AspectRatio->4,ChartStyle->(cf/@Rescale[MovingAverage[First[#],2],{Min[sd],Max[sd]},{0,1}]),ImageSize->60]&[HistogramList[sd,{Range[Min[sd],Max[sd],(Max[sd]-Min[sd])/15]}]];

Plot paths and histogram distribution of the slice distribution at 50:

ListLinePlot[data,ImageSize->400,PlotRange->All,
AspectRatio->3/4,Epilog->Inset[sliced,{50.5,Mean[sd]},{0,8}],PlotStyle->(cf/@Rescale[sd]),BaseStyle->Directive[Thin,Opacity[0.5]],PlotRangePadding->{{0,20},{.5,7}}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[BernoulliProcess, paclet:ref/BernoulliProcess])  ▪  (RefLink[BinomialProcess, paclet:ref/BinomialProcess])  ▪  (RefLink[TelegraphProcess, paclet:ref/TelegraphProcess])  ▪  (RefLink[WienerProcess, paclet:ref/WienerProcess])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Parametric Random Processes, paclet:guide/ParametricRandomProcesses])}, {▪(RefLinkPlain[Random Processes, paclet:guide/RandomProcesses])}, {▪(RefLinkPlain[Scientific Models, paclet:guide/ScientificModels])}})}})