SA_data <- LR_data[,-c(1,2)]
View(SA_data)
dim(SA_data) # 158849     34

SA_data$lu2010 <- factor(SA_data$lu2010)
SA_data$lu2015 <- factor(SA_data$lu2015)
SA_data$lc2006 <- factor(SA_data$lc2006)
SA_data$lc2010 <- factor(SA_data$lc2010)
SA_data$lu2006 <- factor(SA_data$lu2006)

# Create failure time (i.e., time that LU change occurs)
# Assume that LU was measured each year since 2010 for 6 years. 
# Failure time takes place when time = 1,2,3,4 (i.e., failure occurs at 2011,2012,2013,2014).
# Assume that if the failure occurs b/w t1 and t2, the object is considered failed at t2.
# time=5 means the object is censored


# time <- as.vector(rep(NA, nrow(SA_data)))
# for (i in 1:length(time)){
#   if (SA_data$lu2010[i]==SA_data$lu2015[i]) {time[i]=5} 
#   else {time[i]=floor(runif(1, 1, 5))}
# }
# table(time)

status <- ifelse(SA_data$lu2010==SA_data$lu2015, 0, 1)
set.seed(123)
time <- ifelse(SA_data$lu2010==SA_data$lu2015, 5, floor(runif(10, 1, 5)))
length(time) # 158849
table(time)
SA_data1.1 <- SA_data
SA_data1.1$time <- time
SA_data1.1$status <- status
dim(SA_data1.1) # 158849     36

######################################
# Original data
######################################
library(dplyr)
SA_To_1_all <- filter(SA_data1.1, lu2015==1)
dim(SA_To_1_all) # 7734 36

SA_To_2_all <- filter(SA_data1.1, lu2015==2)
dim(SA_To_2_all) # 125659 36

SA_To_3_all <- filter(SA_data1.1, lu2015==3)
dim(SA_To_3_all) # 2525 36

SA_To_4_all <- filter(SA_data1.1, lu2015==4)
dim(SA_To_4_all) # 5569 36

SA_To_5_all <- filter(SA_data1.1, lu2015==5)
dim(SA_To_5_all) # 1311 36

SA_To_6_all <- filter(SA_data1.1, lu2015==6)
dim(SA_To_6_all) # 197 36

SA_To_7_all <- filter(SA_data1.1, lu2015==7)
dim(SA_To_7_all) # 8015 36

SA_To_8_all <- filter(SA_data1.1, lu2015==8)
dim(SA_To_8_all) # 3059 36

SA_To_9_all <- filter(SA_data1.1, lu2015==9)
dim(SA_To_9_all) # 2295 36

SA_To_10_all <- filter(SA_data1.1, lu2015==10)
dim(SA_To_10_all) # 414 36

SA_To_11_all <- filter(SA_data1.1, lu2015==11)
dim(SA_To_11_all) # 1621 36

# write.csv(SA_To_1_all, "SA_To_1_all.csv")
# write.csv(SA_To_2_all, "SA_To_2_all.csv")
# write.csv(SA_To_3_all, "SA_To_3_all.csv")
# write.csv(SA_To_4_all, "SA_To_4_all.csv")
# write.csv(SA_To_5_all, "SA_To_5_all.csv")
# write.csv(SA_To_6_all, "SA_To_6_all.csv")
# write.csv(SA_To_7_all, "SA_To_7_all.csv")
# write.csv(SA_To_8_all, "SA_To_8_all.csv")
# write.csv(SA_To_9_all, "SA_To_9_all.csv")
# write.csv(SA_To_10_all, "SA_To_10_all.csv")
# write.csv(SA_To_11_all, "SA_To_11_all.csv")

######################################
# Full and balanced data
######################################
# LUC 1 full
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
SA_any_to_1 = filter(SA_To_1_all, lu2010 != 1)
dim(SA_any_to_1) # 435  36
SA_one_to_1 = filter(SA_To_1_all, lu2010 == 1)
dim(SA_one_to_1) # 7299   36
set.seed(123)
select_SA_one_to_1 = sample(c(1:nrow(SA_one_to_1)), nrow(SA_any_to_1), replace=FALSE)
SA_one_to_1_1.1 = SA_one_to_1[select_SA_one_to_1,]
dim(SA_one_to_1_1.1) # 435  36

SA_To_1 = rbind(SA_any_to_1,SA_one_to_1_1.1)
set.seed(123)
Order_SA_To_1 = sample(c(1:nrow(SA_To_1)), nrow(SA_To_1), replace=FALSE)
SA_To_1 = SA_To_1[Order_SA_To_1,]
dim(SA_To_1)
SA_To_1_full = SA_To_1[,-c(3,4)]
dim(SA_To_1_full) # 870 34
# write.csv(SA_To_1_full, "SA_To_1_full.csv")

set.seed(123)
Train_SA_To_1_full_Index = sample(nrow(SA_To_1_full), floor(nrow(SA_To_1_full)*0.7), replace=FALSE)
training_SA_To_1_full = SA_To_1_full[Train_SA_To_1_full_Index,]
dim(training_SA_To_1_full) # 609 34
testing_SA_To_1_full = SA_To_1_full[-Train_SA_To_1_full_Index,]
dim(testing_SA_To_1_full) # 261 34
# write.csv(training_SA_To_1_full,"training_SA_To_1_full.csv")
# write.csv(testing_SA_To_1_full,"testing_SA_To_1_full.csv")

# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# LUC 2 full
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
SA_any_to_2 = filter(SA_To_2_all, lu2010 != 2)
dim(SA_any_to_2) # 5408  36
SA_2_to_2 = filter(SA_To_2_all, lu2010 == 2)
dim(SA_2_to_2) # 120251   36
set.seed(123)
select_SA_2_to_2 = sample(c(1:nrow(SA_2_to_2)), nrow(SA_any_to_2), replace=FALSE)
SA_2_to_2_1.1 = SA_2_to_2[select_SA_2_to_2,]
dim(SA_2_to_2_1.1) # 5408  36

SA_To_2 = rbind(SA_any_to_2,SA_2_to_2_1.1)
set.seed(123)
Order_SA_To_2 = sample(c(1:nrow(SA_To_2)), nrow(SA_To_2), replace=FALSE)
SA_To_2 = SA_To_2[Order_SA_To_2,]
dim(SA_To_2) # 10816 36
SA_To_2_full = SA_To_2[,-c(3,4)]
# write.csv(SA_To_2_full, "SA_To_2_full.csv")

set.seed(123)
Train_SA_To_2_full_Index = sample(nrow(SA_To_2_full), floor(nrow(SA_To_2_full)*0.7), replace=FALSE)
training_SA_To_2_full = SA_To_2_full[Train_SA_To_2_full_Index,]
dim(training_SA_To_2_full) # 7571 34
testing_SA_To_2_full = SA_To_2_full[-Train_SA_To_2_full_Index,]
dim(testing_SA_To_2_full) # 3245 34
# write.csv(training_SA_To_2_full,"training_SA_To_2_full.csv")
# write.csv(testing_SA_To_2_full,"testing_SA_To_2_full.csv")

# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# LUC 2 reduced
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
set.seed(123)
select_SA_any_to_2_reduced = sample(c(1:nrow(SA_any_to_2)),500,replace=FALSE)
SA_any_to_2_1.1 = SA_any_to_2[select_SA_any_to_2_reduced,]
dim(SA_any_to_2_1.1) # 500 36

set.seed(123)
select_SA_2_to_2_1.1 = sample(c(1:nrow(SA_2_to_2)), nrow(SA_any_to_2_1.1), replace=FALSE)
SA_2_to_2_1.2 = SA_2_to_2[select_SA_2_to_2_1.1,]
dim(SA_2_to_2_1.2) # 500  36

SA_To_2_reduced = rbind(SA_any_to_2_1.1,SA_2_to_2_1.2)
set.seed(123)
Order_SA_To_2_1.1 = sample(c(1:nrow(SA_To_2_reduced)), nrow(SA_To_2_reduced), replace=FALSE)
SA_To_2_reduced = SA_To_2_reduced[Order_SA_To_2_1.1,]
dim(SA_To_2_reduced) # 1000 36
SA_To_2_reduced = SA_To_2_reduced[,-c(3,4)]
# write.csv(SA_To_2_reduced, "SA_To_2_reduced.csv")

set.seed(123)
Train_SA_To_2_reduced_Index <- sample(nrow(SA_To_2_reduced), floor(nrow(SA_To_2_reduced)*0.7), replace=FALSE)
training_SA_To_2_reduced <- SA_To_2_reduced[Train_SA_To_2_reduced_Index,]
dim(training_SA_To_2_reduced) # 700 34
testing_SA_To_2_reduced <- SA_To_2_reduced[-Train_SA_To_2_reduced_Index,]
dim(testing_SA_To_2_reduced) # 300 34

# write.csv(training_SA_To_2_reduced, "training_SA_To_2_reduced.csv")
# write.csv(testing_SA_To_2_reduced, "testing_SA_To_2_reduced.csv")

# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# LUC 3 full
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
SA_any_to_3 = filter(SA_To_3_all, lu2010 != 3)
dim(SA_any_to_3) # 849  36
SA_3_to_3 = filter(SA_To_3_all, lu2010 == 3)
dim(SA_3_to_3) # 1676   36
set.seed(123)
select_SA_3_to_3 = sample(c(1:nrow(SA_3_to_3)), nrow(SA_any_to_3), replace=FALSE)
SA_3_to_3_1.1 = SA_3_to_3[select_SA_3_to_3,]
dim(SA_3_to_3_1.1) # 849  36

SA_To_3 = rbind(SA_any_to_3,SA_3_to_3_1.1)
set.seed(123)
Order_SA_To_3 = sample(c(1:nrow(SA_To_3)), nrow(SA_To_3), replace=FALSE)
SA_To_3 = SA_To_3[Order_SA_To_3,]
dim(SA_To_3) # 10816 36
SA_To_3_full = SA_To_3[,-c(3,4)]
dim(SA_To_3_full) # 10816 34
# write.csv(SA_To_3_full, "SA_To_3_full.csv")

set.seed(123)
Train_SA_To_3_full_Index = sample(nrow(SA_To_3_full), floor(nrow(SA_To_3_full)*0.7), replace=FALSE)
training_SA_To_3_full = SA_To_3_full[Train_SA_To_3_full_Index,]
dim(training_SA_To_3_full) # 1188 34
testing_SA_To_3_full = SA_To_3_full[-Train_SA_To_3_full_Index,]
dim(testing_SA_To_3_full) # 510 34
# write.csv(training_SA_To_3_full,"training_SA_To_3_full.csv")
# write.csv(testing_SA_To_3_full,"testing_SA_To_3_full.csv")

# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# LUC 3 reduced
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
set.seed(123)
select_SA_any_to_3_reduced = sample(c(1:nrow(SA_any_to_3)),500,replace=FALSE)
SA_any_to_3_1.1 = SA_any_to_3[select_SA_any_to_3_reduced,]
dim(SA_any_to_3_1.1) # 500 36

set.seed(123)
select_SA_3_to_3_1.1 = sample(c(1:nrow(SA_3_to_3)), nrow(SA_any_to_3_1.1), replace=FALSE)
SA_3_to_3_1.2 = SA_3_to_3[select_SA_3_to_3_1.1,]
dim(SA_3_to_3_1.2) # 500  36

SA_To_3_reduced = rbind(SA_any_to_3_1.1,SA_3_to_3_1.2)
set.seed(123)
Order_SA_To_3_1.1 = sample(c(1:nrow(SA_To_3_reduced)), nrow(SA_To_3_reduced), replace=FALSE)
SA_To_3_reduced = SA_To_3_reduced[Order_SA_To_3_1.1,]
dim(SA_To_3_reduced) # 1000 36
SA_To_3_reduced = SA_To_3_reduced[,-c(3,4)]
# write.csv(SA_To_3_reduced, "SA_To_3_reduced.csv")

set.seed(123)
Train_SA_To_3_reduced_Index <- sample(nrow(SA_To_3_reduced), floor(nrow(SA_To_3_reduced)*0.7), replace=FALSE)
training_SA_To_3_reduced <- SA_To_3_reduced[Train_SA_To_3_reduced_Index,]
dim(training_SA_To_3_reduced) # 700 34
testing_SA_To_3_reduced <- SA_To_3_reduced[-Train_SA_To_3_reduced_Index,]
dim(testing_SA_To_3_reduced) # 300 34
# write.csv(training_SA_To_3_reduced, "training_SA_To_3_reduced.csv")
# write.csv(testing_SA_To_3_reduced, "testing_SA_To_3_reduced.csv")

# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# LUC 4 full
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
SA_any_to_4 = filter(SA_To_4_all, lu2010 != 4)
dim(SA_any_to_4) # 1660  36
SA_4_to_4 = filter(SA_To_4_all, lu2010 == 4)
dim(SA_4_to_4) # 3909   36
set.seed(123)
select_SA_4_to_4 = sample(c(1:nrow(SA_4_to_4)), nrow(SA_any_to_4), replace=FALSE)
SA_4_to_4_1.1 = SA_4_to_4[select_SA_4_to_4,]
dim(SA_4_to_4_1.1) # 1660  36

SA_To_4 = rbind(SA_any_to_4,SA_4_to_4_1.1)
set.seed(123)
Order_SA_To_4 = sample(c(1:nrow(SA_To_4)), nrow(SA_To_4), replace=FALSE)
SA_To_4 = SA_To_4[Order_SA_To_4,]
dim(SA_To_4) # 3320 36
SA_To_4_full = SA_To_4[,-c(3,4)]
dim(SA_To_4_full) # 3320 34
# write.csv(SA_To_4_full, "SA_To_4_full.csv")

set.seed(123)
Train_SA_To_4_full_Index = sample(nrow(SA_To_4_full), floor(nrow(SA_To_4_full)*0.7), replace=FALSE)
training_SA_To_4_full = SA_To_4_full[Train_SA_To_4_full_Index,]
dim(training_SA_To_4_full) # 2324 34
testing_SA_To_4_full = SA_To_4_full[-Train_SA_To_4_full_Index,]
dim(testing_SA_To_4_full) # 996 34
# write.csv(training_SA_To_4_full,"training_SA_To_4_full.csv")
# write.csv(testing_SA_To_4_full,"testing_SA_To_4_full.csv")

# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# LUC 4 reduced
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
set.seed(123)
select_SA_any_to_4_reduced = sample(c(1:nrow(SA_any_to_4)),500,replace=FALSE)
SA_any_to_4_1.1 = SA_any_to_4[select_SA_any_to_4_reduced,]
dim(SA_any_to_4_1.1) # 500 36

set.seed(123)
select_SA_4_to_4_1.1 = sample(c(1:nrow(SA_4_to_4)), nrow(SA_any_to_4_1.1), replace=FALSE)
SA_4_to_4_1.2 = SA_4_to_4[select_SA_4_to_4_1.1,]
dim(SA_4_to_4_1.2) # 500  36

SA_To_4_reduced = rbind(SA_any_to_4_1.1,SA_4_to_4_1.2)
set.seed(123)
Order_SA_To_4_1.1 = sample(c(1:nrow(SA_To_4_reduced)), nrow(SA_To_4_reduced), replace=FALSE)
SA_To_4_reduced = SA_To_4_reduced[Order_SA_To_4_1.1,]
dim(SA_To_4_reduced) # 1000 36
SA_To_4_reduced = SA_To_4_reduced[,-c(3,4)]
dim(SA_To_4_reduced) # 1000 34
# write.csv(SA_To_4_reduced, "SA_To_4_reduced.csv")

set.seed(123)
Train_SA_To_4_reduced_Index <- sample(nrow(SA_To_4_reduced), floor(nrow(SA_To_4_reduced)*0.7), replace=FALSE)
training_SA_To_4_reduced <- SA_To_4_reduced[Train_SA_To_4_reduced_Index,]
dim(training_SA_To_4_reduced) # 700 34
testing_SA_To_4_reduced <- SA_To_4_reduced[-Train_SA_To_4_reduced_Index,]
dim(testing_SA_To_4_reduced) # 300 34
# write.csv(training_SA_To_4_reduced, "training_SA_To_4_reduced.csv")
# write.csv(testing_SA_To_4_reduced, "testing_SA_To_4_reduced.csv")

# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# LUC 5 full
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
SA_any_to_5 = filter(SA_To_5_all, lu2010 != 5)
dim(SA_any_to_5) # 265  36
SA_5_to_5 = filter(SA_To_5_all, lu2010 == 5)
dim(SA_5_to_5) # 1046   36
set.seed(123)
select_SA_5_to_5 = sample(c(1:nrow(SA_5_to_5)), nrow(SA_any_to_5), replace=FALSE)
SA_5_to_5_1.1 = SA_5_to_5[select_SA_5_to_5,]
dim(SA_5_to_5_1.1) # 265  36

SA_To_5 = rbind(SA_any_to_5,SA_5_to_5_1.1)
set.seed(123)
Order_SA_To_5 = sample(c(1:nrow(SA_To_5)), nrow(SA_To_5), replace=FALSE)
SA_To_5 = SA_To_5[Order_SA_To_5,]
dim(SA_To_5) # 530 36
SA_To_5_full = SA_To_5[,-c(3,4)]
dim(SA_To_5_full) # 530 34
# write.csv(SA_To_5_full, "SA_To_5_full.csv")

set.seed(123)
Train_SA_To_5_full_Index = sample(nrow(SA_To_5_full), floor(nrow(SA_To_5_full)*0.7), replace=FALSE)
training_SA_To_5_full = SA_To_5_full[Train_SA_To_5_full_Index,]
dim(training_SA_To_5_full) # 371 34
testing_SA_To_5_full = SA_To_5_full[-Train_SA_To_5_full_Index,]
dim(testing_SA_To_5_full) # 159 34
# write.csv(training_SA_To_5_full,"training_SA_To_5_full.csv")
# write.csv(testing_SA_To_5_full,"testing_SA_To_5_full.csv")

# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# LUC 6 full
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
SA_any_to_6 = filter(SA_To_6_all, lu2010 != 6)
dim(SA_any_to_6) # 5  36
SA_6_to_6 = filter(SA_To_6_all, lu2010 == 6)
dim(SA_6_to_6) # 192   36
set.seed(123)
select_SA_6_to_6 = sample(c(1:nrow(SA_6_to_6)), nrow(SA_any_to_6), replace=FALSE)
SA_6_to_6_1.1 = SA_6_to_6[select_SA_6_to_6,]
dim(SA_6_to_6_1.1) # 5  36

SA_To_6 = rbind(SA_any_to_6,SA_6_to_6_1.1)
set.seed(123)
SA_To_6_full = SA_To_6[,-c(3,4)]
dim(SA_To_6_full) # 10 34
# write.csv(SA_To_6_full, "SA_To_6_full.csv")

set.seed(123)
Train_SA_To_6_full_Index = sample(nrow(SA_To_6_full), floor(nrow(SA_To_6_full)*0.7), replace=FALSE)
training_SA_To_6_full = SA_To_6_full[Train_SA_To_6_full_Index,]
dim(training_SA_To_6_full) # 371 34
testing_SA_To_6_full = SA_To_6_full[-Train_SA_To_6_full_Index,]
dim(testing_SA_To_6_full) # 159 34
# write.csv(training_SA_To_6_full,"training_SA_To_6_full.csv")
# write.csv(testing_SA_To_6_full,"testing_SA_To_6_full.csv")

# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# LUC 7 full
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
SA_any_to_7 = filter(SA_To_7_all, lu2010 != 7)
dim(SA_any_to_7) # 946  36
SA_7_to_7 = filter(SA_To_7_all, lu2010 == 7)
dim(SA_7_to_7) # 7069   36
set.seed(123)
select_SA_7_to_7 = sample(c(1:nrow(SA_7_to_7)), nrow(SA_any_to_7), replace=FALSE)
SA_7_to_7_1.1 = SA_7_to_7[select_SA_7_to_7,]
dim(SA_7_to_7_1.1) # 946  36

SA_To_7 = rbind(SA_any_to_7,SA_7_to_7_1.1)
set.seed(123)
Order_SA_To_7 = sample(c(1:nrow(SA_To_7)), nrow(SA_To_7), replace=FALSE)
SA_To_7 = SA_To_7[Order_SA_To_7,]
dim(SA_To_7) # 1892 36
SA_To_7_full = SA_To_7[,-c(3,4)]
dim(SA_To_7_full) # 1892 34
# write.csv(SA_To_7_full, "SA_To_7_full.csv")

set.seed(123)
Train_SA_To_7_full_Index = sample(nrow(SA_To_7_full), floor(nrow(SA_To_7_full)*0.7), replace=FALSE)
training_SA_To_7_full = SA_To_7_full[Train_SA_To_7_full_Index,]
dim(training_SA_To_7_full) # 1324 34
testing_SA_To_7_full = SA_To_7_full[-Train_SA_To_7_full_Index,]
dim(testing_SA_To_7_full) # 568 34
# write.csv(training_SA_To_7_full,"training_SA_To_7_full.csv")
# write.csv(testing_SA_To_7_full,"testing_SA_To_7_full.csv")

# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# LUC 7 reduced
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
set.seed(123)
select_SA_any_to_7_reduced = sample(c(1:nrow(SA_any_to_7)),500,replace=FALSE)
SA_any_to_7_1.1 = SA_any_to_7[select_SA_any_to_7_reduced,]
dim(SA_any_to_7_1.1) # 500 36

set.seed(123)
select_SA_7_to_7_1.1 = sample(c(1:nrow(SA_7_to_7)), nrow(SA_any_to_7_1.1), replace=FALSE)
SA_7_to_7_1.2 = SA_7_to_7[select_SA_7_to_7_1.1,]
dim(SA_7_to_7_1.2) # 500  36

SA_To_7_reduced = rbind(SA_any_to_7_1.1,SA_7_to_7_1.2)
set.seed(123)
Order_SA_To_7_1.1 = sample(c(1:nrow(SA_To_7_reduced)), nrow(SA_To_7_reduced), replace=FALSE)
SA_To_7_reduced = SA_To_7_reduced[Order_SA_To_7_1.1,]
dim(SA_To_7_reduced) # 1000 36
SA_To_7_reduced = SA_To_7_reduced[,-c(3,4)]
dim(SA_To_7_reduced) # 1000 34
# write.csv(SA_To_7_reduced, "SA_To_7_reduced.csv")

set.seed(123)
Train_SA_To_7_reduced_Index <- sample(nrow(SA_To_7_reduced), floor(nrow(SA_To_7_reduced)*0.7), replace=FALSE)
training_SA_To_7_reduced <- SA_To_7_reduced[Train_SA_To_7_reduced_Index,]
dim(training_SA_To_7_reduced) # 700 34
testing_SA_To_7_reduced <- SA_To_7_reduced[-Train_SA_To_7_reduced_Index,]
dim(testing_SA_To_7_reduced) # 300 34
# write.csv(training_SA_To_7_reduced, "training_SA_To_7_reduced.csv")
# write.csv(testing_SA_To_7_reduced, "testing_SA_To_7_reduced.csv")

# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# LUC 8 full
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
SA_any_to_8 = filter(SA_To_8_all, lu2010 != 8)
dim(SA_any_to_8) # 260  36
SA_8_to_8 = filter(SA_To_8_all, lu2010 == 8)
dim(SA_8_to_8) # 3249   36
set.seed(123)
select_SA_8_to_8 = sample(c(1:nrow(SA_8_to_8)), nrow(SA_any_to_8), replace=FALSE)
SA_8_to_8_1.1 = SA_8_to_8[select_SA_8_to_8,]
dim(SA_8_to_8_1.1) # 260  36

SA_To_8 = rbind(SA_any_to_8,SA_8_to_8_1.1)
set.seed(123)
Order_SA_To_8 = sample(c(1:nrow(SA_To_8)), nrow(SA_To_8), replace=FALSE)
SA_To_8 = SA_To_8[Order_SA_To_8,]
dim(SA_To_8) # 250 36
SA_To_8_full = SA_To_8[,-c(3,4)]
dim(SA_To_8_full) # 520 34
# write.csv(SA_To_8_full, "SA_To_8_full.csv")

set.seed(123)
Train_SA_To_8_full_Index = sample(nrow(SA_To_8_full), floor(nrow(SA_To_8_full)*0.7), replace=FALSE)
training_SA_To_8_full = SA_To_8_full[Train_SA_To_8_full_Index,]
dim(training_SA_To_8_full) # 364 34
testing_SA_To_8_full = SA_To_8_full[-Train_SA_To_8_full_Index,]
dim(testing_SA_To_8_full) # 156 34
# write.csv(training_SA_To_8_full,"training_SA_To_8_full.csv")
# write.csv(testing_SA_To_8_full,"testing_SA_To_8_full.csv")

# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# LUC 9 full
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
SA_any_to_9 = filter(SA_To_9_all, lu2010 != 9)
dim(SA_any_to_9) # 0  36
SA_9_to_9 = filter(SA_To_9_all, lu2010 == 9)
dim(SA_9_to_9) # 2295   36

# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# LUC 10 full
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
SA_any_to_10 = filter(SA_To_10_all, lu2010 != 10)
dim(SA_any_to_10) # 36  36
SA_10_to_10 = filter(SA_To_10_all, lu2010 == 10)
dim(SA_10_to_10) # 378   36
set.seed(123)
select_SA_10_to_10 = sample(c(1:nrow(SA_10_to_10)), nrow(SA_any_to_10), replace=FALSE)
SA_10_to_10_1.1 = SA_10_to_10[select_SA_10_to_10,]
dim(SA_10_to_10_1.1) # 36  36

SA_To_10 = rbind(SA_any_to_10,SA_10_to_10_1.1)
set.seed(123)
Order_SA_To_10 = sample(c(1:nrow(SA_To_10)), nrow(SA_To_10), replace=FALSE)
SA_To_10 = SA_To_10[Order_SA_To_10,]
dim(SA_To_10) # 72 36
SA_To_10_full = SA_To_10[,-c(3,4)]
dim(SA_To_10_full) # 72 34
# write.csv(SA_To_10_full, "SA_To_10_full.csv")

set.seed(123)
Train_SA_To_10_full_Index = sample(nrow(SA_To_10_full), floor(nrow(SA_To_10_full)*0.7), replace=FALSE)
training_SA_To_10_full = SA_To_10_full[Train_SA_To_10_full_Index,]
dim(training_SA_To_10_full) # 50 34
testing_SA_To_10_full = SA_To_10_full[-Train_SA_To_10_full_Index,]
dim(testing_SA_To_10_full) # 22 34
# write.csv(training_SA_To_10_full,"training_SA_To_10_full.csv")
# write.csv(testing_SA_To_10_full,"testing_SA_To_10_full.csv")

# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# LUC 11 full
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
SA_any_to_11 = filter(SA_To_11_all, lu2010 != 11)
dim(SA_any_to_11) # 742  36
SA_11_to_11 = filter(SA_To_11_all, lu2010 == 11)
dim(SA_11_to_11) # 879   36
set.seed(123)
select_SA_11_to_11 = sample(c(1:nrow(SA_11_to_11)), nrow(SA_any_to_11), replace=FALSE)
SA_11_to_11_1.1 = SA_11_to_11[select_SA_11_to_11,]
dim(SA_11_to_11_1.1) # 742  36

SA_To_11 = rbind(SA_any_to_11,SA_11_to_11_1.1)
set.seed(123)
Order_SA_To_11 = sample(c(1:nrow(SA_To_11)), nrow(SA_To_11), replace=FALSE)
SA_To_11 = SA_To_11[Order_SA_To_11,]
dim(SA_To_11) # 1484 36
SA_To_11_full = SA_To_11[,-c(3,4)]
dim(SA_To_11_full) # 1484 34
# write.csv(SA_To_11_full, "SA_To_11_full.csv")

set.seed(123)
Train_SA_To_11_full_Index = sample(nrow(SA_To_11_full), floor(nrow(SA_To_11_full)*0.7), replace=FALSE)
training_SA_To_11_full = SA_To_11_full[Train_SA_To_11_full_Index,]
dim(training_SA_To_11_full) # 1038 34
testing_SA_To_11_full = SA_To_11_full[-Train_SA_To_11_full_Index,]
dim(testing_SA_To_11_full) # 446 34
# write.csv(training_SA_To_11_full,"training_SA_To_11_full.csv")
# write.csv(testing_SA_To_11_full,"testing_SA_To_11_full.csv")

# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# LUC 11 reduced
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
set.seed(123)
select_SA_any_to_11_reduced = sample(c(1:nrow(SA_any_to_11)),500,replace=FALSE)
SA_any_to_11_1.1 = SA_any_to_11[select_SA_any_to_11_reduced,]
dim(SA_any_to_11_1.1) # 500 36

set.seed(123)
select_SA_11_to_11_1.1 = sample(c(1:nrow(SA_11_to_11)), nrow(SA_any_to_11_1.1), replace=FALSE)
SA_11_to_11_1.2 = SA_11_to_11[select_SA_11_to_11_1.1,]
dim(SA_11_to_11_1.2) # 500  36

SA_To_11_reduced = rbind(SA_any_to_11_1.1,SA_11_to_11_1.2)
set.seed(123)
Order_SA_To_11_1.1 = sample(c(1:nrow(SA_To_11_reduced)), nrow(SA_To_11_reduced), replace=FALSE)
SA_To_11_reduced = SA_To_11_reduced[Order_SA_To_11_1.1,]
dim(SA_To_11_reduced) # 1000 36
SA_To_11_reduced = SA_To_11_reduced[,-c(3,4)]
dim(SA_To_11_reduced) # 1000 34
# write.csv(SA_To_11_reduced, "SA_To_11_reduced.csv")

set.seed(123)
Train_SA_To_11_reduced_Index <- sample(nrow(SA_To_11_reduced), floor(nrow(SA_To_11_reduced)*0.7), replace=FALSE)
training_SA_To_11_reduced <- SA_To_11_reduced[Train_SA_To_11_reduced_Index,]
dim(training_SA_To_11_reduced) # 700 34
testing_SA_To_11_reduced <- SA_To_11_reduced[-Train_SA_To_11_reduced_Index,]
dim(testing_SA_To_11_reduced) # 300 34
# write.csv(training_SA_To_11_reduced, "training_SA_To_11_reduced.csv")
# write.csv(testing_SA_To_11_reduced, "testing_SA_To_11_reduced.csv")