# NOT RUN {
#Example 1:
#Let's import dataset with today's Covid-19 parameters per each state:
data<-covid19us::get_states_current()
#For this example we will keep data for positive cases and deaths today:
data<-data[c(3,9)]
#We also need to replace NA values to integer 0:
data[is.na(data)] = 0
#Now run CBN:
result <- TopoCBN(data,nKNN=12) # can also try with filt_len=50,75,100
#We can obtain the same results using matrix of pairwise distances:
dMatrix <- as.matrix(dist(data))
result <- TopoCBN(dMatrix,nKNN=12,dist_matrix = TRUE)
#Let's plot the results:
set.seed(365)
distinct_clrs=randomcoloR::distinctColorPalette(result$nClust)
clrs<-distinct_clrs[result$assignments] # distinct colors for clusters
plot(data,col=clrs,pch=20,xlab='x',ylab='y',main = 'TopoCBN')
print(result)
#We can see that CBN function identified 6 clusters within our dataset.
#Example 2:
#Let's import dataset with air quality level in Californian metropolitan areas. The three
#columns of the dataset contains indicator of air quality (the lower the better), value
#added of companies (in thousands of dollars).
data<-as.matrix(Ecdat::Airq[1:3])
#Now apply TopoCBN function to the air quality data:
result <- TopoCBN(data,nKNN=12) # can also try with filt_len=50,75,100
#The same results can be obtained using matrix of pairwise distances:
dMatrix <- as.matrix(dist(data))
result <- TopoCBN(dMatrix,nKNN=12,dist_matrix = TRUE)
#Plot the results:
set.seed(365)
distinct_clrs=randomcoloR::distinctColorPalette(result$nClust)
clrs<-distinct_clrs[result$assignments] # distinct colors for clusters
plot(data,col=clrs,pch=20,xlab='x',ylab='y',main = 'TopoCBN')
print(result)
#We see that TopoCBN identified 4 clusters within our dataset of the sizes
#1,3,5, and 21. These results suggest that companies with added values under $5,000 may
#have any value of air pollution. However, companies with higher added values (>$5,000)
#correspond to the dramatically increased (deteriorated) levels of air pollution.
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab