Bias correction with cross validation

Hello, I'm currently working on bias correction for precipitation data using the fitQmap function in R. I'm attempting to implement it with cross-validation, but I'm encountering some challenges that I hope someone can assist me with.

One particular aspect that I'm struggling to understand fully is how to effectively partition my data into training and testing sets. Given that my time series spans from 1980 to 2014 for both observed and modeled data, I'm concerned about ensuring that the entire dataset for the modeled data, covering the period from 1980 to 2014, has been corrected before using it in my analysis. Any insights or guidance on this matter would be greatly appreciated.

Another thing, I will provide the code that I am using for this study. I hope someone can help me confirm if it is correct or incorrect, and if it is incorrect, suggest the correct form.

note: the data frame contain dates from 1980 to 2014 only for one month.

df1 <- list_obs_m[[1]][[1]]
df1_m <- list_modH_m [[1]][[1]]
fold_df1 <- createFolds(df1$Date, k = 5, list = TRUE, returnTrain = TRUE)

for (i in 1:5) {
cat("Iteration", i, "\n")

train_indices_df1 <- unlist(fold_df1[-i])
test_indices_df1 <- fold_df1[[i]]

train_data_df1 <- df1[train_indices_df1, ]
test_data_df1 <- df1 [test_indices_df1, ]

train_data_df1_mod <- df1_m[train_indices_df1, ]
test_data_df1_mod <- df1_m [test_indices_df1, ]

cat("Number of training data:", nrow(train_data_df1), "\n")
cat("Test data count:", nrow(test_data_df1), "\n")

train RQUANT model

            qm.fit <- fitQmap(train_data_df1[2], train_data_df1_mod[2],
            method="RQUANT",qstep=0.01)
y_modH <- doQmap(test_data_df1_mod[2] ,qm.fit,type="linear")

  # Calculate Root Mean Squared Error (RMSE)

RMSE_t <- rmse(test_data_df1[[2]], y_modH[[1]])

# Calculate bias 

bias_t <- bias(test_data_df1[[2]], y_modH[[1]])

cat("RMSE_t:", RMSE_t, "\n\n")
cat("bias_t:", bias_t, "\n\n")

}

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.