Data.S1. R script for evaluatioin of a linear regression model with a predictor variable "ECCENTRICITY_top" and a target variable "panicle_weight". The original data of 100 rice varieties is split into training (70% original) and test sets (30% original data), the model is trained on the training set, and its performance is evaluated on the test set. The MAE (mean absolute error) between the predicted value and the real value of panicle weight is used to test the linear regression model.

#Load libraries
library(keras)
library(caret)

# Load the data, remember to change the dir and name of your data, here is "a2.csv"
panicle_weight <- read.csv("a2.csv")
panicle_weight <- na.omit(panicle_weight)

# Select the relevant columns in "a2.csv" file
panicle_weight <- panicle_weight[, c("ECCENTRICITY_top", "panicle_weight")]

# Split the data into training and test sets, "ECCENTRICITY_top" is the predictor variance and "panicle_weight" is the target variance

set.seed(123) #use set.seed function to repeat the results
ind <- sample(2, nrow(panicle_weight), replace = TRUE, prob = c(0.7, 0.3))
training <- panicle_weight[ind == 1, ]
test <- panicle_weight[ind == 2, ]
trainingtarget <- training$panicle_weight
testtarget <- test$panicle_weight
training <- training[, 1, drop = FALSE]
test <- test[, 1, drop = FALSE]

# Linear regression model built using lm function
lm_model <- lm(trainingtarget ~ ., data = training)

# Evaluate the linear regression model
lm_predictions <- predict(lm_model, newdata = test)
lm_mae <- mean(abs(lm_predictions - testtarget))
cat("Linear regression model MAE:", lm_mae, "\n")


