The walk
Use the random walk from Module 9.5, with distances measured in steps of 50 meters:
- The hiker starts at \((0, 0)\), where they left the trail.
- Each minute, the hiker moves one step east or west and one step north or south, chosen by two independent coin flips.
- The road is the line \(y = 20\) (20 steps × 50 m = 1 km north). The river is the line \(y = -10\) (500 m south).
- The hike ends the first minute the hiker reaches \(y \ge 20\) (road) or \(y \le -10\) (river). If neither happens within 240 minutes (4 hours), the hiker is still lost at dark.
Because the road and river both run east–west, only the north–south position \(y\) decides how a hike ends. You’ll still track \(x\) for one hike so you can draw the path.
At first, the hiker has no sense of direction: north and south are equally likely (runif(1) < 0.5). Later you’ll give the hiker a slight pull toward the road.
Stopping a loop early with break
A hike can end before 240 minutes. Inside a loop, break leaves the loop immediately. For example, this loop stops the first time the total reaches 10:
total <- 0
for (i in 1:100) {
total <- total + 3
if (total >= 10) {
break
}
}
total # 12
i # 4: the loop stopped on its fourth passAfter a break, i still holds the pass the loop stopped on. If the loop finishes without a break, i holds the last value, 100.
What your report should show
1. Model and assumptions
In your own words, describe the model. State two assumptions it makes about the hiker or the terrain, and explain one way a real lost hiker behaves differently from this model.
2. One hike
Simulate one hike of up to 240 minutes, storing every position. Plot the path with the road and river drawn as horizontal lines (abline(h = 20) and abline(h = -10)), and report how the hike ended and after how many minutes.
Before simulating, answer by reasoning: what is the fewest number of minutes in which the hiker could reach the road? The river?
3. Many hikes
Simulate 1,000 hikes with a fair north–south coin and 240 minutes of daylight. You only need each hike’s outcome ("road", "river", or "lost"), not its whole path. Report the fraction of hikes with each outcome. The three fractions should add to 1.
Then repeat the 1,000 hikes with a different seed. How much did the fractions change? How many digits of your answer do you trust?
4. Check against an exact answer
If the hiker had unlimited time, a fair walk would eventually reach the road or the river. For a fair walk, the chance of reaching the road first has an exact answer:
\[ P(\text{road first}) = \frac{\text{distance to the river}}{\text{distance to the road} + \text{distance to the river}} = \frac{10}{20 + 10} = \frac{1}{3}. \]
You do not need to derive this formula. Test it: rerun your 1,000 hikes with max_minutes set to 5,000, so almost no hiker is still lost. Report the fraction that reached the road and its relative error compared with \(1/3\). Is the error about the size of the seed-to-seed variation from Section 3?
In one or two sentences, explain in plain language why the river is twice as likely as the road even though the hiker has no preference for either direction.
5. A pull toward the road
Suppose the hiker can faintly hear traffic and drifts north slightly more often than south. Let p_north be the chance of a step north (runif(1) < p_north). Return to 240 minutes of daylight.
For p_north from 0.50 to 0.60 in steps of 0.01, simulate 1,000 hikes and record the fraction that reach the road. Present a table and a labeled graph of the road fraction against p_north.
- Describe the shape of the graph.
- What is the smallest
p_northon your grid for which at least 75% of hikers reach the road? - In plain language, how big a change in the hiker’s behavior is that? Would anyone watching the hiker even notice it?
6. Recommendation
Write a short paragraph to a park ranger who is designing a sign for the trailhead: based on your model, what should the sign tell hikers about getting lost? Then describe at least one way your model could be wrong or limited. Consider its assumptions, the parameter values, or the number of hikes you simulated.
Evaluation
This project is graded holistically on a 10-point scale. I will look for a clearly explained model, a correct and checked simulation of one hike, outcome fractions with an honest look at their variability, a comparison with the exact answer, a readable table and graph for the pull toward the road, and a recommendation that connects the results to their limits.
Before submitting
- Render from a fresh R session and inspect the HTML output.
- Check that the road is at \(y = 20\), the river at \(y = -10\), and that every simulation in Sections 3 and 5 uses 1,000 hikes and 240 minutes.
- Label every graph’s axes and say what each line or point shows.
- Submit both the
.qmdand.htmlfiles to Moodle.