Version: This
tutorial uses windcut 0.2.1. The examples pass
window_pane(...)$features to the screening functions. In
0.1.0, pass the table returned directly by window_pane().
With 0.1.0 installed, run
vignette("feature-screening", package = "windcut") for the
matching tutorial.
Run this setup first. It loads the packages used in the article and sets figure options used by the screening examples.
Window-pane analysis can create many weather predictors. The next task is to decide which ones deserve attention before modeling. This article uses two screening functions:
screen_window_features() ranks each candidate predictor
by its correlation with the disease response.screen_feature_correlations() compares candidate
predictors against each other and suggests a less redundant subset.Important. Screening is not model validation. It is only an first pass for reducing a large feature space before fitting predictive models.
Before screening, we need one row per site and one column per
candidate predictor. The bundled window_pane_demo_data
object already contains daily weather summaries and one disease
assessment per site. Here the windows end one day before the assessment
date, so the disease observation is not mixed with same-day weather.
The daily weather column names are kept exactly as they appear in the
data: daily_mean_temp, daily_mean_rh,
daily_sum_rain, and daily_sum_leaf_wetness. We
also derive daily_vpd from temperature and relative
humidity to show that derived variables can be screened in the same
workflow. The statistics list uses those column names, so
the generated feature names show both the weather variable and the
window summary.
data(window_pane_demo_data)
weather <- window_pane_demo_data$weather |>
derive_vpd(daily_mean_temp, daily_mean_rh, name = "daily_vpd")
assessments <- window_pane_demo_data$assessments
windows <- make_windows(min_offset = -18, max_offset = -1, width = 5, reference_col = "assessment_time")
daily_weather_cols <- c(
"daily_mean_temp",
"daily_mean_rh",
"daily_vpd",
"daily_sum_rain",
"daily_sum_leaf_wetness"
)
summary_statistics <- list(
daily_mean_temp = list(mean = "mean", days_18_26 = count_between(18, 26)),
daily_mean_rh = list(mean = "mean", humid_days = humid_hours(90)),
daily_vpd = list(mean = "mean", dry_days = count_above(1.2)),
daily_sum_rain = list(total = "sum", rain_events = rain_events(0.2)),
daily_sum_leaf_wetness = list(wet_days = wet_days(0)),
.conditions = list(
favorable_days = count_when(
daily_mean_temp >= 18 & daily_mean_temp <= 26 & daily_mean_rh >= 90
)
)
)
features <- window_pane(
weather = weather,
assessments = assessments,
windows = windows,
id_col = "site_id",
response_col = "disease_intensity",
weather_cols = daily_weather_cols,
statistics = summary_statistics
)$features
feature_cols <- features %>%
select(contains("_window_")) %>%
names()
feature_table_overview <- data.frame(
rows = nrow(features),
candidate_feature_columns = length(feature_cols)
)
knitr::kable(feature_table_overview)| rows | candidate_feature_columns |
|---|---|
| 10 | 130 |
| feature |
|---|
| daily_mean_temp_mean_window_m18_m13 |
| daily_mean_temp_days_18_26_window_m18_m13 |
| daily_mean_rh_mean_window_m18_m13 |
| daily_mean_rh_humid_days_window_m18_m13 |
| daily_vpd_mean_window_m18_m13 |
| daily_vpd_dry_days_window_m18_m13 |
| daily_sum_rain_total_window_m18_m13 |
| daily_sum_rain_rain_events_window_m18_m13 |
The feature table contains the weather summaries. Missing percentages
are available in the separate coverage table returned by
window_pane().
The first question is: which individual weather-window predictors are
most associated with disease intensity?
screen_window_features() answers that with one correlation
test per candidate predictor. Spearman correlation is useful for this
example because it ranks monotonic relationships and is less dependent
on a linear response shape than Pearson correlation.
screened <- screen_window_features(
data = features,
response_col = "disease_intensity",
feature_cols = feature_cols,
method = "spearman"
)
knitr::kable(screened %>% slice_head(n = 10))| feature | metric | window | estimate | p_value | n_complete | p_adjusted |
|---|---|---|---|---|---|---|
| daily_mean_rh_mean_window_m10_m05 | daily_mean_rh_mean | window_m10_m05 | -0.6242424 | 0.0602490 | 10 | 0.7946892 |
| daily_sum_rain_total_window_m08_m03 | daily_sum_rain_total | window_m08_m03 | -0.6000000 | 0.0731199 | 10 | 0.7946892 |
| daily_mean_rh_mean_window_m12_m07 | daily_mean_rh_mean | window_m12_m07 | -0.5878788 | 0.0802151 | 10 | 0.7946892 |
| daily_sum_rain_rain_events_window_m09_m04 | daily_sum_rain_rain_events | window_m09_m04 | 0.5698029 | 0.0855044 | 10 | 0.7946892 |
| daily_vpd_mean_window_m10_m05 | daily_vpd_mean | window_m10_m05 | 0.5636364 | 0.0957916 | 10 | 0.7946892 |
| daily_mean_rh_mean_window_m08_m03 | daily_mean_rh_mean | window_m08_m03 | -0.5151515 | 0.1328231 | 10 | 0.7946892 |
| daily_mean_rh_mean_window_m07_m02 | daily_mean_rh_mean | window_m07_m02 | -0.4909091 | 0.1544427 | 10 | 0.7946892 |
| daily_mean_rh_mean_window_m11_m06 | daily_mean_rh_mean | window_m11_m06 | -0.4787879 | 0.1660580 | 10 | 0.7946892 |
| daily_mean_rh_mean_window_m09_m04 | daily_mean_rh_mean | window_m09_m04 | -0.4787879 | 0.1660580 | 10 | 0.7946892 |
| daily_vpd_mean_window_m08_m03 | daily_vpd_mean | window_m08_m03 | 0.4666667 | 0.1782193 | 10 | 0.7946892 |
Plotting the strongest screened features makes the sign and magnitude of the associations easier to scan. Positive and negative correlations are separated by color because they suggest different biological interpretations: higher values of a predictor may be associated with either higher or lower disease intensity.
top10 <- screened %>%
mutate(abs_estimate = abs(estimate)) %>%
arrange(desc(abs_estimate)) %>%
slice_head(n = 10) %>%
mutate(feature = factor(feature, levels = rev(feature)))
ggplot(top10, aes(estimate, feature, fill = estimate > 0)) +
geom_col(show.legend = FALSE) +
geom_vline(xintercept = 0, linetype = "dashed", color = "gray50") +
scale_fill_manual(values = c("#c47f2c", "#5f8f63")) +
labs(
title = "Top feature-screening results",
x = "Correlation estimate",
y = NULL
) +
cowplot::theme_half_open()The output provides:
estimate: correlation estimatep_value: raw test p-valuep_adjusted: corrected p-valuemetric: parsed metric namewindow: parsed relative-time window labelThe adjusted p-value is useful because many window-derived predictors are being tested at once. It should not be read as final proof that a predictor belongs in a model, but it helps keep the first screen from being driven only by chance.