First return time for a 100 step random walk 2 8 14 20 26 32 38 44 50 56 62 68 74 80 86 92 98 Probability 0'0 0.1 0.2 0.3 0.4 0.5
First return time for a 100 step random walk 2 8 14 20 26 32 38 44 50 56 62 68 74 80 86 92 98 Probability 0'0 0.1 0.2 0.3 0.4 0.5
MATLAB: An Introduction with Applications
6th Edition
ISBN:9781119256830
Author:Amos Gilat
Publisher:Amos Gilat
Chapter1: Starting With Matlab
Section: Chapter Questions
Problem 1P
Related questions
Question
100%
This is a Statistics problem.
Why are EVEN the only return times possible?

Transcribed Image Text:First return time for a 100 step random walk
2 8 14 20 26 32 38 44 50 56 62 68 74 80 86 92 98
Steps to return
Only even return times are possible (why?). Half the time the first return is after two draws, one of
each color. There is a slight bump near 100, when the bag of marbles empties out and the number
of red and blue marbles drawn are forced to equalize.
Probability
0'0
0.1
0.2
0.3
0.4
0.5
![Suppose you have a bag full of marbles; 50 are red and 50 are blue. You are standing on a number
line, and you draw a marble out of the bag. If you get red, you go left one unit. If you get blue, you
go right one unit. This is called a random walk. You draw marbles up to 100 times, each time moving
left or right one unit. Let X be the number of marbles drawn from the bag until you return to 0 for
the first time. The rv X is called the first return time since it is the number of steps it takes to return
to your starting position.
Estimate the pmf of X.
First, simulate the steps of the walk, with 1 and -1 representing steps right and left.
movements <- sample(rep(c (1, -1), times = 50), 100, replace = FALSE)
movements [1:10]
## [1] 1 1 -1 -1 -1 -1 1 1 1 -1
Next, use cumsum to calculate the cumulative sum of the steps. This vector gives the position of
the walk at each step.
cumsum (movements) [1:10]
## [1] 1 2 1 0 -1 -2 -1 0 1 0
The values where the cumulative sum is zero represent a return to the origin. Using which , we
learn which steps of the walk were zero, and then find the first of these with min .
which(cumsum (movements) == 0)
## [1]
4
8
10 12
56 78 82
94 100
min(which(cumsum (movements) == 0))
## [1] 4
This results in a single value of the rv X, in this case 4. To finish, we replicate the code and table
it to compute the pmf.
X <- replicate(10000, {
movements <- sample(rep(c(1, -1), times = 50), 100, replace = FALSE)
min(which (cumsum (movements) == 0))
})
pmf <- proportions (table(X))
plot(pmf,
main = "First return time for a 100 step random walk",
xlab = "Steps to return",
ylab = "Probability"](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fcb9da028-c1e8-4fb4-9df2-7f4287e8030e%2F1067c371-20be-418b-9977-779934aacd3b%2Fajxb8ts_processed.png&w=3840&q=75)
Transcribed Image Text:Suppose you have a bag full of marbles; 50 are red and 50 are blue. You are standing on a number
line, and you draw a marble out of the bag. If you get red, you go left one unit. If you get blue, you
go right one unit. This is called a random walk. You draw marbles up to 100 times, each time moving
left or right one unit. Let X be the number of marbles drawn from the bag until you return to 0 for
the first time. The rv X is called the first return time since it is the number of steps it takes to return
to your starting position.
Estimate the pmf of X.
First, simulate the steps of the walk, with 1 and -1 representing steps right and left.
movements <- sample(rep(c (1, -1), times = 50), 100, replace = FALSE)
movements [1:10]
## [1] 1 1 -1 -1 -1 -1 1 1 1 -1
Next, use cumsum to calculate the cumulative sum of the steps. This vector gives the position of
the walk at each step.
cumsum (movements) [1:10]
## [1] 1 2 1 0 -1 -2 -1 0 1 0
The values where the cumulative sum is zero represent a return to the origin. Using which , we
learn which steps of the walk were zero, and then find the first of these with min .
which(cumsum (movements) == 0)
## [1]
4
8
10 12
56 78 82
94 100
min(which(cumsum (movements) == 0))
## [1] 4
This results in a single value of the rv X, in this case 4. To finish, we replicate the code and table
it to compute the pmf.
X <- replicate(10000, {
movements <- sample(rep(c(1, -1), times = 50), 100, replace = FALSE)
min(which (cumsum (movements) == 0))
})
pmf <- proportions (table(X))
plot(pmf,
main = "First return time for a 100 step random walk",
xlab = "Steps to return",
ylab = "Probability"
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images

Recommended textbooks for you

MATLAB: An Introduction with Applications
Statistics
ISBN:
9781119256830
Author:
Amos Gilat
Publisher:
John Wiley & Sons Inc

Probability and Statistics for Engineering and th…
Statistics
ISBN:
9781305251809
Author:
Jay L. Devore
Publisher:
Cengage Learning

Statistics for The Behavioral Sciences (MindTap C…
Statistics
ISBN:
9781305504912
Author:
Frederick J Gravetter, Larry B. Wallnau
Publisher:
Cengage Learning

MATLAB: An Introduction with Applications
Statistics
ISBN:
9781119256830
Author:
Amos Gilat
Publisher:
John Wiley & Sons Inc

Probability and Statistics for Engineering and th…
Statistics
ISBN:
9781305251809
Author:
Jay L. Devore
Publisher:
Cengage Learning

Statistics for The Behavioral Sciences (MindTap C…
Statistics
ISBN:
9781305504912
Author:
Frederick J Gravetter, Larry B. Wallnau
Publisher:
Cengage Learning

Elementary Statistics: Picturing the World (7th E…
Statistics
ISBN:
9780134683416
Author:
Ron Larson, Betsy Farber
Publisher:
PEARSON

The Basic Practice of Statistics
Statistics
ISBN:
9781319042578
Author:
David S. Moore, William I. Notz, Michael A. Fligner
Publisher:
W. H. Freeman

Introduction to the Practice of Statistics
Statistics
ISBN:
9781319013387
Author:
David S. Moore, George P. McCabe, Bruce A. Craig
Publisher:
W. H. Freeman