Learn R Programming

PhenoSpectra (version 0.1.0)

predict_SDS: Predict Spectral Disease Severity (SDS)

Description

This function predicts Spectral Disease Severity (SDS) using a standard linear regression model (lm()). It automatically handles column names with special characters by using backticks and constrains predictions to the range [0, 100].

Usage

predict_SDS(cleaned_data, sf_test, fixed_effects = NULL)

Value

A dataframe with predicted SDS values for all treatments, constrained between 0 and 100.

Arguments

cleaned_data

A dataframe containing spectral measurements and treatment labels.

sf_test

A dataframe containing selected important features (from statistical tests).

fixed_effects

A character vector of fixed effects to include (default: NULL). Example: c("Scan.date").

Examples

Run this code
# Create mock spectral data
library(openxlsx)
cleaned_data <- data.frame(
  treatment = sample(0:1, 100, replace = TRUE),
  var1 = rnorm(100),
  var2 = rnorm(100),
  var3 = rnorm(100),
  Scan.date = sample(
    seq.Date(
      from = as.Date('2023-01-01'),
      to = as.Date('2023-12-31'),
      by = 'day'
    ),
    100
  ),
  Scan.time = format(Sys.time(), "%H:%M:%S")
)

Run the code above in your browser using DataLab