NDVI
library(readxl)
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(clhs)
library(ClustGeo)
library(fclust)
## Registered S3 method overwritten by 'fclust':
## method from
## print.fclust e1071
library(clusterCrit)
df <- read_excel("C:/Users/ERICK/Desktop/Semestre 2022 B/Computación estadÃstica/BD_MODELADO.xlsx")
#getCriteriaNames(TRUE)
## data normalization
for (j in 2:(ncol(df)))
df[,j]=df[,j]/df[,1]
## removing the column Serving Size
df=df[,]
## fuzzy k-means
## (excluded the factor column Type (last column))
clust=FKM(df[,1:(ncol(df)-1)],k=6,m=1.5,stand=1)
## Xie and Beni index
xb=XB(clust$Xca,clust$U,clust$H,clust$m);xb
## [1] 0.9869432
df %>%
ggplot(aes(x=Avg_X_MCB,y=Avg_Y_MCE,
color=NDVI))+
geom_point(size=4)+
scale_color_viridis_c()+
theme_minimal()+
coord_equal()

df %>%
ggplot(aes(Avg_X_MCB,Avg_Y_MCE,
color=NDVI))+
geom_point(size=3)+
coord_equal()

D0 = dist(df$NDVI)
tree = hclustgeo(D0)
groups= cutree(tree,2)
df$Clusters = groups
df %>%
group_by(Clusters) %>%
summarise(mediat=mean(NDVI,
trim=0.05),
media = mean(NDVI),
mediana=median(NDVI),
n=n())
## # A tibble: 2 × 5
## Clusters mediat media mediana n
## <int> <dbl> <dbl> <dbl> <int>
## 1 1 0.00000100 0.00000100 0.00000100 263
## 2 2 0.000000930 0.000000927 0.000000938 50
df_NDVI = df%>%
select(Avg_X_MCB,
Avg_Y_MCE,
NDVI)
res = clhs(x = df_NDVI,size = 60)
df_NDVI[res,] %>%
ggplot(aes(x=Avg_X_MCB,
y=Avg_Y_MCE,
color=NDVI))+
geom_point(size=3)

table(df[res,]$Clusters)
##
## 1 2
## 50 10
tapply(df[res,]$NDVI,
df[res,]$Clusters,
mean)
## 1 2
## 1.001978e-06 9.297683e-07
ggplot(data = df,
aes(x=Avg_X_MCB,
y=Avg_Y_MCE,
color=as.factor(Clusters)))+
geom_point(size=2)+
geom_point(data = df[res,],
aes(x=Avg_X_MCB,
y=Avg_Y_MCE),
color="green",
shape=4,
size=4)
