| Title: | Course Materials for Longitudinal and Spatial Data Analysis |
|---|---|
| Description: | Datasets, teaching helper functions, interactive Shiny applications and 'learnr' tutorials supporting MATH48132 and MATH68132 Longitudinal and Spatial Data Analysis at the University of Manchester. Installing this package provides every dataset and dependency used across the eleven teaching weeks in a single step, so that tutorial code runs without students having to locate and read data files themselves. |
| Authors: | Olatunji Johnson [aut, cre] |
| Maintainer: | Olatunji Johnson <[email protected]> |
| License: | CC BY-NC-SA 4.0 |
| Version: | 0.2.0 |
| Built: | 2026-09-30 07:36:03 UTC |
| Source: | https://github.com/olatunjijohnson/lsda |
Bodyweight of 60 cattle in two treatment groups, recorded at 11 equally spaced time points. A balanced design: every animal is measured at every time, which makes it the natural first example for exploring within-subject correlation.
cattlecattle
A data frame with 60 rows and 12 columns:
treatment group, coded 0 and 1
bodyweight in kilograms at time 1
bodyweight in kilograms at time 2
bodyweight in kilograms at time 3
bodyweight in kilograms at time 4
bodyweight in kilograms at time 5
bodyweight in kilograms at time 6
bodyweight in kilograms at time 7
bodyweight in kilograms at time 8
bodyweight in kilograms at time 9
bodyweight in kilograms at time 10
bodyweight in kilograms at time 11
Used throughout weeks 1-3 of MATH48132/68132. Originally distributed as a headerless text file; column names added here.
data(cattle) spaghetti_plot(cattle, group = "group") round(cor(cattle[, -1]), 2)data(cattle) spaghetti_plot(cattle, group = "group") round(cor(cattle[, -1]), 2)
Longitudinal CD4+ counts with time measured in years relative to seroconversion, so negative times precede it. Highly unbalanced in both the number and the spacing of visits.
cd4cd4
A data frame with 2376 rows and 8 columns:
years since seroconversion (negative before)
CD4+ cell count
age in years, centred
cigarette smoking
recreational drug use, 0/1
number of sexual partners
depression score (CES-D scale)
subject identifier
Multicenter AIDS Cohort Study.
Constructs the covariance structures met in week 2, so that slides, notes and tutorials all display the same matrices. Useful for showing students what a structure *is* before asking them to fit one.
cov_structure( structure = c("independent", "exchangeable", "ar1", "arma11", "unstructured"), n = 5, sigma2 = 1, rho = 0.5, theta = 0.5, values = NULL )cov_structure( structure = c("independent", "exchangeable", "ar1", "arma11", "unstructured"), n = 5, sigma2 = 1, rho = 0.5, theta = 0.5, values = NULL )
structure |
One of |
n |
Dimension of the matrix. |
sigma2 |
Variance. |
rho |
Correlation parameter. For |
theta |
Moving-average parameter, |
values |
Optional vector of correlations for |
A symmetric n by n covariance matrix.
cov_structure("ar1", n = 5, rho = 0.8) cov_structure("exchangeable", n = 4, rho = 0.5, sigma2 = 2)cov_structure("ar1", n = 5, rho = 0.8) cov_structure("exchangeable", n = 4, rho = 0.5, sigma2 = 2)
Repeatedly permutes the values across locations and recomputes the empirical variogram. Under the null of no spatial correlation the observed variogram should sit inside the envelope of the permuted ones. This is the test used in the week 7 tutorial.
emp_variogram_mc(x, y, z, nsim = 999, nbins = 15, max_dist = NULL)emp_variogram_mc(x, y, z, nsim = 999, nbins = 15, max_dist = NULL)
x, y
|
Coordinates. |
z |
Values, typically residuals from a covariate-only fit. |
nsim |
Number of permutations. |
nbins |
Number of distance bins. |
max_dist |
Largest distance considered. Defaults to half the maximum separation. |
A list with the bin midpoints, the observed semivariance, the simulated envelope, and a permutation p-value.
data(galicia) fit <- lm(loglead ~ pm10, data = galicia) res <- emp_variogram_mc(galicia$long, galicia$lat, resid(fit), nsim = 99) res$p_valuedata(galicia) fit <- lm(loglead ~ pm10, data = galicia) res <- emp_variogram_mc(galicia$long, galicia$lat, resid(fit), nsim = 99) res$p_value
Repeated spirometry measurements on 299 girls from Topeka, Kansas, enrolled
in the Six Cities Study of Air Pollution and Health. Girls entered at around
age 6-10 and were followed roughly annually. The number of observations per
girl ranges from 1 to 12, so the design is markedly unbalanced – the
counterpart to the balanced cattle data.
fev1fev1
A data frame with 1993 rows and 8 columns:
girl identifier
height in metres at the visit
age in years at the visit
height in metres at the first visit
age in years at the first visit
log of FEV1
forced expiratory volume in one second, in litres
log(FEV1 / height), the usual response
The 2025 course tree also contained air_pollution.csv, which is
this same data with fev1 and logfev1_ht dropped. It is not
reproduced here; use fev1.
Six Cities Study of Air Pollution and Health.
data(fev1) table(table(fev1$id)) # observations per girl: the design is unbalanceddata(fev1) table(table(fev1$id)) # observations per girl: the design is unbalanced
Lead concentration measured in moss at 132 sampling stations across Galicia, north-west Spain, with a co-located PM10 measurement. The running example for the geostatistical weeks: variogram estimation in week 7, model fitting and kriging in week 8.
galiciagalicia
A data frame with 132 rows and 5 columns:
lead concentration
log lead concentration, the modelled response
longitude in decimal degrees
latitude in decimal degrees
particulate matter under 10 micrometres
RiskMap also ships a galicia, with three
columns (x, y, lead). Both packages are attached in the
week 7 and 8 tutorials, so load this one with
data(galicia, package = "lsda").
galicia_grid and galicia_pred for
prediction.
A regular grid covering the Galicia study region, for mapping kriging predictions in week 8.
galicia_gridgalicia_grid
A data frame with 1508 rows and 2 columns, X and Y,
in kilometres.
PM10 and coordinates at each prediction location, so that models including PM10 as a covariate can be used for prediction.
galicia_predgalicia_pred
A data frame with 1508 rows and 3 columns: pm10,
long, lat.
A regular grid covering Greater Manchester, carrying the same covariates as
gm_no2, for mapping predictions in week 8.
gm_gridgm_grid
An sf data frame with 4996 features and 4 columns:
elevation in metres
population count of the cell
distance to the nearest major road, in metres
grid point, EPSG:27700
data(gm_grid) nrow(gm_grid)data(gm_grid) nrow(gm_grid)
Nitrogen dioxide (NO2) measured at 25 monitoring stations across Greater Manchester, the running geostatistical example in weeks 7 and 8: the variogram of the residuals in week 7, and model fitting and prediction in week 8.
gm_no2gm_no2
An sf data frame with 25 features and 8 columns:
monitoring station name
nitrogen dioxide concentration
particulate matter concentrations
elevation in metres
distance to the nearest major road, in metres
population count of the surrounding cell
station location, EPSG:27700
gm_grid for the prediction grid.
data(gm_no2) summary(gm_no2$NO2)data(gm_no2) summary(gm_no2$NO2)
250 preschool children examined at entry and then every three months for a year. The question of interest is whether vitamin A deficiency raises the risk of respiratory infection. The binary response and repeated measures make this the standard GEE and GLMM example.
ichsichs
A data frame with 1500 rows and 6 columns:
child identifier
respiratory infection present, 0 = absent, 1 = present
months since the first visit
0 = male, 1 = female
vitamin A status, 0 = sufficient, 1 = deficient
age in years
Indonesian Children's Health Study. Used in week 5.
Cluster-level malaria incidence with height-for-age z-scores, used as the week 8 challenge dataset.
liberialiberia
A data frame with 267 rows and 5 columns:
cluster identifier
mean height-for-age z-score
decimal degrees
incidence rate
RiskMap ships a different dataset also called
liberia (onchocerciasis counts, used in the week 8 challenge). Name
the package for whichever you want.
Prediction grid for Liberia
liberia_gridliberia_grid
A data frame with 3837 rows and 2 columns, X and Y.
Village-level survey results for Loa loa (eyeworm) from 197 villages across Cameroon and southern Nigeria, with elevation and NDVI vegetation covariates. A binomial response, so it extends the Gaussian geostatistics of weeks 7-8 to the generalised case.
loaloaloaloa
A data frame with 197 rows and 11 columns:
row identifier
village identifier
decimal degrees
number of individuals tested
number testing positive
metres above sea level
NDVI summaries, 1999-2001
RiskMap also ships a loaloa — the same
survey, but with upper-case column names. Load this one with
data(loaloa, package = "lsda").
Diggle, P.J., Thomson, M.C., Christensen, O.F., Rowlingson, B., Obsomer, V., Gardon, J., Wanji, S., Takougang, I., Enyong, P., Kamgno, J., Remme, H., Boussinesq, M. and Molyneux, D.H. (2007). Spatial modelling and prediction of Loa loa risk: decision making under uncertainty.
Childhood obesity and income deprivation for the 33 local authority districts of North West England, the areal example in weeks 9 and 10.
nw_obesitynw_obesity
An sf data frame with 33 features and 8 columns:
local authority district code and name
number of children measured as obese
number of children measured
num_obese / total_sampled
Income Deprivation Affecting Children Index, average score
rank of the IDACI score (lower is more deprived)
district polygon, EPSG:27700
National Child Measurement Programme small-area data and the English Indices of Deprivation 2019, both published by gov.uk.
data(nw_obesity) summary(nw_obesity$prop_obese)data(nw_obesity) summary(nw_obesity$prop_obese)
Launch a course Shiny application
run_app(app = NULL, ...)run_app(app = NULL, ...)
app |
Application name. Omit to list what is available. |
... |
Passed to |
Called for its side effect.
## Not run: run_app() # list the apps run_app("variogram") ## End(Not run)## Not run: run_app() # list the apps run_app("variogram") ## End(Not run)
Observed and expected male lip cancer cases in each of the 56 Scottish counties, with the proportion of the workforce in agriculture, fishing and forestry (AFF) as a proxy for sunlight exposure. The running example for the areal weeks: Moran's I in week 9, CAR and ICAR models in week 10.
scotland_lipscotland_lip
An sf data frame with 56 features and 6 columns:
county name
observed cases
expected cases given the age-sex structure
proportion employed in agriculture, fishing or forestry
standardised incidence ratio, cases / expected
county polygon
The original shapefile declared no CRS and its coordinates were British
National Grid divided by 1000. Here the geometry is rescaled to metres and
tagged EPSG:27700, so basemaps and area calculations behave. Adjacency
– the only property weeks 9 and 10 rely on – is unchanged by rescaling.
Clayton and Kaldor (1987); Breslow and Clayton (1993).
data(scotland_lip) head(scotland_lip$sir)data(scotland_lip) head(scotland_lip$sir)
Standardised incidence ratio
sir(observed, expected)sir(observed, expected)
observed |
Observed counts. |
expected |
Expected counts. |
Numeric vector of ratios.
data(scotland_lip) head(sir(scotland_lip$cases, scotland_lip$expected))data(scotland_lip) head(sir(scotland_lip$cases, scotland_lip$expected))
One line per subject. Accepts either wide data (one row per subject, one
column per time) or long data (one row per observation) via id,
time and response.
spaghetti_plot( data, id = NULL, time = NULL, response = NULL, group = NULL, times = NULL, col = "grey30", alpha = 0.6, ... )spaghetti_plot( data, id = NULL, time = NULL, response = NULL, group = NULL, times = NULL, col = "grey30", alpha = 0.6, ... )
data |
A data frame. |
id, time, response
|
Column names, as strings, for long-format data. Leave
|
group |
Optional grouping column; lines are coloured by it and a legend is drawn. |
times |
Numeric times for wide format. Defaults to |
col |
Line colour when |
alpha |
Line opacity between 0 and 1. |
... |
Passed to |
Invisibly, the plotted data. Called for the side effect.
data(cattle) spaghetti_plot(cattle, group = "group") data(fev1) spaghetti_plot(fev1, id = "id", time = "age", response = "logfev1_ht")data(cattle) spaghetti_plot(cattle, group = "group") data(fev1) spaghetti_plot(fev1, id = "id", time = "age", response = "logfev1_ht")
Summary statistics from a teacher effectiveness survey, used as a secondary example.
teftef
A data frame with 37 rows and 11 columns.