View source: R/mrCoOccurNet_bootstrap.R
mrCoOccurNet_bootstrap | R Documentation |
This function generates a co-occurrence network from a provided list and calculates strength and directionality of the relationships.
mrCoOccurNet_bootstrap(mrPD_obj, Y)
mrPD_obj |
A list of model predictions. |
Y |
The response data. |
A dataframe representing the co-occurrence network with strength and directionality.
## Not run:
# Example usage:
#set up analysis
Y <- dplyr::select(Bird.parasites, -scale.prop.zos)%>%
dplyr::select(sort(names(.)))#response variables eg. SNPs, pathogens, species....
X <- dplyr::select(Bird.parasites, scale.prop.zos) # feature set
X1 <- Y %>%
dplyr::select(sort(names(.)))
model_rf <-
rand_forest(trees = 100, mode = "classification", mtry = tune(), min_n = tune()) %>% #100 trees are set for brevity. Aim to start with 1000
set_engine("randomForest")
yhats_rf <- mrIMLpredicts(X=X, Y=Y,
X1=X1,'Model=model_rf ,
balance_data='no',mode='classification',
tune_grid_size=5,seed = sample.int(1e8, 1),'morans=F,
prop=0.7, k=5, racing=T) #
bs_analysis <- mrBootstrap(yhats=yhats_rf,Y=Y, num_bootstrap = 5)
assoc_net<- mrCoOccurNet_bootstrap (mrPD_obj=pds , Y=Y)
assoc_net_filtered <- assoc_net %>%
filter(mean_strength > 0.05)
g <- graph_from_data_frame(assoc_net_filtered, directed=TRUE, vertices=names(Y)) #matching Y data
E(g)$Value <- assoc_net_filtered$mean_strength###chnge this as needed
E(g)$Color <- ifelse(assoc_net_filtered$direction == "negative", "blue", "red")
gg <- ggnetwork(g)
ggplot(gg, aes(x = x, y = y, xend = xend, yend = yend)) +
geom_edges(aes(color = Color, linewidth = (Value)), curvature = 0.2,
arrow = arrow(length = unit(5, "pt"), type = "closed")) + #makes arrows bigger
geom_nodes(color = "gray", size = degree(g, mode = "out")/2)+#, fill='black', stroke =2) +
scale_color_identity() +
theme_void() +
theme(legend.position = "none") +
geom_nodelabel_repel(aes(label = name),
box.padding = unit(0.5, "lines"),
data = gg,
size=2,
segment.colour = "black",
colour = "white", fill = "grey36")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.