# Worksheet: Data analysis

*Tactiverge Academy · Computational Engineering, module 3 · https://tactiverge.win/academy/computational-engineering/#data-analysis*

Name: ______________________    Date: ____________

## Learning objectives

Tick each one when you can do it without looking at your notes.

- [ ] Compute and interpret mean, median, range and standard deviation.
- [ ] Choose an appropriate plot for a dataset and label it fully.
- [ ] Fit a straight line to data and judge whether the fit is reasonable.
- [ ] Explain why correlation alone does not establish causation.

## Lesson 1: Describing data

Summarise a set of measurements with the mean, median, range and standard deviation, and learn what each one hides.

Read online: https://tactiverge.win/academy/computational-engineering/data-analysis/describing-data/

#### Project: Measure your reaction time with a ruler

You need a 30 cm ruler, a partner, a pencil and paper, and Python.

1. Your partner holds the ruler vertically with the 0 mark between your open finger and thumb. Without warning, they let go and you catch it. Record the mark where you caught it, in centimetres.
2. Do **20 trials** and write every result down, including any you fumble.
3. Convert each distance to a reaction time using the falling-object formula t = √(2d / g), with d in metres and g = 9.81 m/s². For example, 15 cm gives t = √(2 × 0.15 / 9.81) ≈ 0.175 s.
4. In Python, compute n, the mean, median, range and sample standard deviation of your times.
5. Repeat the summary for your first 10 and last 10 trials. Did you get faster with practice?

**Deliverables**

- A table of all 20 distances and reaction times
- A Python script that prints n, mean, median, range and sample standard deviation
- Two or three sentences comparing the mean and median, and the first and last 10 trials

### Check your understanding

1. The values 3, 4, 5, 6, 100 have a median of:
   A) 23.6
   B) 5
   C) 97
   D) 4.5

2. When should you divide by n − 1 rather than n when computing a standard deviation?
   A) When your values are a sample from a larger process you want to describe
   B) Only when n is larger than 100
   C) When the data contains negative numbers
   D) Never; n − 1 is an old approximation

3. Removing one slow trial changed the gripper mean from 216.9 ms to 211.5 ms but the median only from 212 ms to 211.5 ms. What does this show?
   A) The median was calculated wrongly
   B) The mean is always smaller than the median
   C) The mean is sensitive to an extreme value; the median is not
   D) The slow trial should be deleted

4. For the values 2, 4, 6 (mean 4), what is the sample standard deviation?
   A) √(8/3) ≈ 1.63
   B) 8
   C) 4
   D) √(8/2) = 2

5. Why is the range a weak measure of spread on its own?
   A) It cannot be computed in Python
   B) It depends only on the two most extreme values, so a single odd value changes it
   C) It is always zero
   D) It has no units

### My notes

______________________________________________

______________________________________________

## Lesson 2: Measurement uncertainty and error bars

Every measurement comes with uncertainty. Learn to estimate it from repeated measurements, report a mean with its standard error, and draw honest error bars.

Read online: https://tactiverge.win/academy/computational-engineering/data-analysis/measurement-uncertainty/

### Check your understanding

1. Ten readings have a sample standard deviation of 0.6 V. What is the standard error of their mean?
   A) 0.06 V
   B) 0.6 V
   C) About 0.19 V
   D) About 1.9 V

2. You want to halve the standard error of a mean you currently compute from 25 readings. Roughly how many readings do you need?
   A) 50
   B) 100
   C) 30
   D) 625

3. Every reading from a thermometer is 1.5 °C too high because it sits in sunlight. What will averaging many readings do?
   A) Remove the 1.5 °C error
   B) Make the error larger
   C) Turn it into a random error
   D) Give a precise mean that is still about 1.5 °C too high

4. A graph shows two means with error bars but does not say what the bars are. Why is this a problem?
   A) Error bars could show the standard deviation, standard error or a confidence interval, which differ greatly in size and meaning
   B) Error bars are not allowed on graphs
   C) It makes no difference what they show
   D) Error bars always show the range

5. In the simulation, why did the sample standard deviation stay near 0.4 mm as n increased, while the standard error shrank?
   A) Because the random seed was fixed
   B) Because s describes the scatter of single readings, which does not change, while SE describes the uncertainty of the mean, which improves with more data
   C) Because Python rounds large samples
   D) Because the true value changed

### My notes

______________________________________________

______________________________________________

## Lesson 3: Visualising data honestly

Choose the right kind of plot for your data, label it fully, and recognise the tricks that make charts mislead.

Read online: https://tactiverge.win/academy/computational-engineering/data-analysis/visualising-data-honestly/

#### Project: Redesign a misleading chart

Find a chart in a newspaper, an advert or a website that you think is misleading, or invent one using the made-up gripper success rates from this lesson.

1. Sketch the original on paper and list every problem you can find, using the seven tricks above.
2. Sketch an honest version that shows the same data. Label the axes with units and state n.
3. Using Python, print a text bar chart of the same values twice: once with bar lengths proportional to the values, and once proportional to (value − 91). Compare how the difference looks.
4. Optional: if you have matplotlib available, produce both versions as proper plots.

**Deliverables**

- A sketch of the original chart with its problems listed
- A sketch or plot of an honest version
- A short Python script that prints both text bar charts

### Check your understanding

1. Which plot best shows how a single sensor's readings are distributed?
   A) A pie chart
   B) A line plot of the readings in sorted order
   C) A bar chart of the mean
   D) A histogram

2. Success rates of 92% and 94% are drawn as bars on an axis starting at 91%. How many times taller does the 94% bar look?
   A) About 1.02 times
   B) 2 times
   C) 3 times
   D) It looks the same

3. You have 6 trials per condition. Why might a dot plot be better than a bar chart of means?
   A) It shows every individual value, so readers can see the spread and the sample size
   B) Dot plots always make differences look larger
   C) Bar charts cannot show means
   D) Dot plots do not need axis labels

4. Why is changing a histogram's bin width something you should report?
   A) Bin width changes the units of the data
   B) Very wide bins can hide structure and very narrow bins can make noise look like structure, so the choice affects the message
   C) Histograms must always use 10 bins
   D) It changes the mean of the data

### My notes

______________________________________________

______________________________________________

## Lesson 4: Fitting lines with least squares

Find the straight line that best fits a set of measurements, compute its slope and intercept by hand and in Python, and use residuals to judge whether a line was the right model.

Read online: https://tactiverge.win/academy/computational-engineering/data-analysis/fitting-lines/

#### Project: Calibrate a rubber band

You need a rubber band, a small bag, coins of one type, a ruler, paper and Python. Hang the bag from the rubber band over the edge of a table, with the ruler held vertically beside it.

1. Record the length of the band with 0, 2, 4, 6, 8 and 10 coins in the bag. Repeat the whole series three times and use the mean length at each load.
2. Using your `fit_line` function, fit length against number of coins and print the residuals.
3. Do the residuals look random, or is there a pattern? Rubber bands are often not linear, so a pattern is a real finding, not a failure.
4. Try fitting only the first four loads. Does the slope change?

Keep heavy loads small, and keep faces away from a stretched band in case it snaps.

**Deliverables**

- A table of mean band length for each load
- Your fitted slope and intercept, with units
- A printed list of residuals and two or three sentences on whether a straight line suits the band

### Check your understanding

1. Why does least squares add up squared residuals rather than plain residuals?
   A) Squaring makes the arithmetic faster
   B) Plain residuals can be positive or negative and cancel out, so a bad line could still score zero
   C) Residuals are always negative
   D) Squared residuals have the same units as y

2. Data has x̄ = 4 and ȳ = 10, and the least-squares slope is 2. What is the intercept?
   A) 2
   B) 8
   C) 10
   D) −2

3. The residuals of a line fit are positive at both ends and negative in the middle. What does this suggest?
   A) The fit is perfect
   B) There is too little noise
   C) The data was entered wrongly
   D) A straight line is the wrong shape for this relationship

4. A spring's extension is fitted as 1.991 mm per newton. What is its stiffness?
   A) 1.991 N/mm
   B) About 0.502 N/mm
   C) About 19.9 N/m
   D) It cannot be found from the slope

5. A line fits loads from 0 to 5 N very well. Why is predicting the extension at 50 N risky?
   A) Least squares only works for small numbers
   B) The slope formula breaks for large x
   C) Nothing you measured tells you the spring still behaves linearly that far out
   D) R² becomes negative above 5 N

### My notes

______________________________________________

______________________________________________

## Lesson 5: Comparing two conditions

Decide whether a change really made a difference by comparing means, spreads and overlap, and by measuring the size of the effect, not just its existence.

Read online: https://tactiverge.win/academy/computational-engineering/data-analysis/comparing-two-conditions/

### Check your understanding

1. Two means each have a standard error of 0.3. What is the standard error of their difference?
   A) 0
   B) 0.6
   C) About 0.42
   D) 0.3

2. Controller B's mean is 0.002 s faster than A's, and with 10,000 trials each this is clearly larger than the noise. What is the most sensible conclusion?
   A) B is a major improvement
   B) The difference is real but probably too small to matter; judge it against the requirement
   C) The result must be an error because the difference is small
   D) Effect size does not matter when the sample is large

3. Cohen's d is the difference in means divided by:
   A) the pooled standard deviation of the individual trials
   B) the standard error of the difference
   C) the number of trials
   D) the larger of the two means

4. All 'old' trials were run on Monday and all 'new' trials on Tuesday after maintenance. What is the main problem?
   A) Tuesday trials are always faster
   B) The sample sizes are too large
   C) There is no problem as long as n is the same
   D) Any difference could be caused by the day or the maintenance rather than the new controller

### My notes

______________________________________________

______________________________________________

## Lesson 6: Correlation is not causation

Measure how strongly two quantities move together, then see in a simulation how a hidden third factor can create a strong correlation with no causal link, and how controlled experiments reveal the truth.

Read online: https://tactiverge.win/academy/computational-engineering/data-analysis/correlation-and-causation/

#### Project: Build a confounder of your own

Write a Python simulation, with a fixed random seed, of a situation where a hidden factor creates a misleading correlation. Ideas: hours of daylight driving both outdoor temperature and solar-panel output; class size driving both noise level and the number of questions asked.

1. Generate at least 200 made-up observations in which the hidden factor influences two measured quantities, but neither measured quantity affects the other.
2. Print the correlation between the two measured quantities.
3. Print the correlation within a narrow band of the hidden factor.
4. Add a randomised "experiment" in which you change one measured quantity by a coin flip, and show the other does not change.
5. Write a short paragraph, clearly labelled as describing simulated data, explaining what an analyst who never measured the hidden factor might wrongly conclude.

**Deliverables**

- A Python script with a fixed seed and comments describing the model
- Printed correlations for all data and for a narrow band
- Printed results of the randomised experiment and a short explanatory paragraph

### Check your understanding

1. In the simulation, why were temperature and error strongly correlated even though temperature had no effect?
   A) Because the random seed was 4
   B) Because Pearson's r is always high for 300 points
   C) Because payload increased both temperature and error
   D) Because error causes temperature

2. Which value of r indicates the strongest straight-line relationship?
   A) 0.5
   B) −0.9
   C) 0.1
   D) 0

3. Why does deciding by coin flip which runs get extra heating make the experiment trustworthy?
   A) It breaks any link between heating and other factors such as payload, so a difference in error can be attributed to the heat or to chance
   B) Coin flips reduce the noise in each measurement
   C) It guarantees exactly half the runs are heated
   D) It makes the correlation coefficient equal to 1

4. A joint draws more current whenever its position error is large. An engineer concludes high current causes the error. What alternative should they consider first?
   A) That the data must be fake
   B) That current and error are unrelated
   C) That correlation always proves causation for electrical quantities
   D) Reverse causation: the controller drives more current because it is trying to correct a large error

5. Within the 2.0–2.5 kg payload band, r was 0.09 from 27 runs. What is the most honest summary?
   A) Temperature definitely has exactly zero effect
   B) Close to zero, but with only 27 runs the estimate is very uncertain
   C) Temperature has a strong effect at medium payloads
   D) The band is too narrow to compute r

### My notes

______________________________________________

______________________________________________

---

## Answer key (for self-checking after you try)

**Lesson 1: Describing data**

1. B — Sorted, the middle (third) of five values is 5. The mean is 23.6 because the 100 pulls it up, which is exactly why the median is called robust.
2. A — Deviations measured from the sample's own mean are slightly too small on average. Dividing by n − 1 corrects this when the data is a sample, which is the usual case in experiments.
3. C — The mean adds up every value, so one extreme value shifts it. The median only depends on the middle position. Whether to exclude the trial is a separate decision that needs a recorded reason.
4. D — The squared deviations are 4, 0 and 4, summing to 8. For a sample divide by n − 1 = 2 to get a variance of 4, so s = 2. Dividing by 3 gives the population value, about 1.63.
5. B — The range ignores every value except the largest and smallest. It also tends to grow as you collect more data, because rare extremes become more likely to appear.

**Lesson 2: Measurement uncertainty and error bars**

1. C — SE = s / √n = 0.6 / √10 ≈ 0.6 / 3.16 ≈ 0.19 V.
2. B — SE falls as 1 / √n, so halving it needs four times as many readings: 4 × 25 = 100.
3. D — This is a systematic error. Averaging reduces random scatter but leaves a consistent bias untouched. Shading the thermometer or calibrating against a reference is the fix.
4. A — A standard-deviation bar can be several times longer than a standard-error bar for the same data. Without a label and n, a reader cannot judge the result.
5. B — Each simulated reading has noise with standard deviation 0.4 mm no matter how many you take. Averaging more of them makes the mean more reliable, which is what SE measures.

**Lesson 3: Visualising data honestly**

1. D — A histogram counts how many readings fall in each bin, revealing the shape of the distribution: bunched, skewed or with several peaks.
2. C — Heights above the axis start are 92 − 91 = 1 and 94 − 91 = 3, so the second bar looks three times taller even though the rates differ by only 2 percentage points.
3. A — With small samples a bar hides how many points there are and whether one unusual trial drives the mean. Showing each point is more transparent.
4. B — The bin width is a choice the reader cannot see from the picture. Reporting it, or checking that conclusions hold for several widths, keeps the plot honest.

**Lesson 4: Fitting lines with least squares**

1. B — Positive and negative misses would cancel in a plain sum. Squaring makes every miss count and penalises large misses more heavily.
2. A — a = ȳ − b · x̄ = 10 − 2 × 4 = 2. The line passes through the point (x̄, ȳ) = (4, 10).
3. D — A systematic pattern in residuals means the model misses some structure, here a curve. Random-looking residuals are what a suitable model leaves behind.
4. B — Stiffness is force per extension, the inverse of the slope: 1 / 1.991 ≈ 0.502 N/mm, which is about 502 N/m.
5. C — Extrapolation assumes the relationship holds outside the tested range. Real springs eventually deform permanently or their coils touch, so the line may fail badly.

**Lesson 5: Comparing two conditions**

1. C — For independent means the variances add: √(0.3² + 0.3²) = √0.18 ≈ 0.42. Subtracting means does not subtract their uncertainties.
2. B — Large samples can reliably detect tiny effects. Whether an effect is worth acting on depends on its size compared with what the task needs.
3. A — d expresses the difference in units of the typical spread within the groups, so it says how far apart the distributions are, not how precisely the means are known.
4. D — When two conditions differ in more than one way, you cannot tell which change caused the difference. Interleaving or randomising trial order prevents this.

**Lesson 6: Correlation is not causation**

1. C — Payload is a confounder. It pushes both quantities up together, which creates a correlation between them without any causal link.
2. B — Strength is the size of r, regardless of sign. −0.9 is a strong falling relationship; the sign only says whether y rises or falls as x rises.
3. A — Randomisation ensures that, apart from chance, the heated and unheated groups are alike in every other respect, including ones you never thought to measure.
4. D — In feedback systems the controller responds to error, so error can cause high current rather than the other way round. The direction of cause needs separate evidence.
5. B — Small samples give noisy correlations; other seeds typically gave values from about −0.3 to +0.4 for the same band. Report the estimate together with how uncertain it is.

---

This work is licensed under the Creative Commons Attribution 4.0 International licence (CC BY 4.0): https://creativecommons.org/licenses/by/4.0/. Attribute as: Tactiverge Academy, https://tactiverge.win.
