# prize35-1 Exercise 2: quadrat estimates for two habitats (invented counts) import math habitats = { "meadow": ([12, 9, 15, 11, 8, 14, 10, 13], 400.0), "hedgerow": ([4, 7, 2, 5, 6, 3, 5, 4], 400.0), } for name, (counts, area) in habitats.items(): n = len(counts) mean = sum(counts) / n var = sum((c - mean) ** 2 for c in counts) / (n - 1) se = math.sqrt(var / n) print(f"{name:9s} mean {mean:5.2f} per m2, standard error {se:4.2f}, " f"estimate for {area:.0f} m2: {mean * area:,.0f} (plus or minus {2 * se * area:,.0f})") # Output: # meadow mean 11.50 per m2, standard error 0.87, estimate for 400 m2: 4,600 (plus or minus 693) # hedgerow mean 4.50 per m2, standard error 0.57, estimate for 400 m2: 1,800 (plus or minus 454) # The two ranges (4,600 +/- 693 and 1,800 +/- 454) do not overlap, so with this data the meadow # really does hold more plants than the hedgerow. The standard error shrinks as quadrats are added.