Skip to content

Instantly share code, notes, and snippets.

View brunaw's full-sized avatar
💜
working on ML & bayesian stats

Bruna Wundervald brunaw

💜
working on ML & bayesian stats
View GitHub Profile
# In case you're installing, building, or removing the package:
# remove.packages("hebartBase")
# devtools::document()
# devtools::check()
# devtools::install()
# Exemplifying:
# Package loading ----------------------------------
library(magrittr)
library(ggplot2)
library(tidyverse)
library(patchwork)
iris_species <- unique(iris$Species)
colours <- c("pink", "red", "blue")
plots <- purrr::map2(
iris_species, colours,
~{
p <- iris |>
dplyr::filter(Species == .x) |>
# Loading packages
library(tidyverse)
library(tidymodels)
library(hebart)
library(lme4)
library(dbarts)
library(patchwork)
# Loading Andrew's friedman data
df <- read.table("https://raw.githubusercontent.com/andrewcparnell/rBART/master/friedman.txt")
# Loading packages
library(tidyverse)
library(hebart)
df <- read.table("https://raw.githubusercontent.com/andrewcparnell/rBART/master/friedman.txt")
df$y <- rnorm(nrow(df))
df$group <- sample(1:5, nrow(df), replace = TRUE)
group_variable = "group"
formula <- y ~ V2 + V3 + V4 + V5 + V6
create_dat <- function(artist, track){
notes = c("A", "B", "C", "D", "E", "F", "G")
flats = "b"
minor = "m"
sharps = "#"
all_notes = c(notes, paste0(notes, flats), paste0(notes,
sharps), paste0(notes, minor), paste0(notes, flats, sharps),
paste0(notes, minor, sharps), paste0(notes, flats, minor),
paste0(notes, flats, sharps, minor))
artist <- chorrrds::get_songs(artist)
library(tidyverse)
library(MASS)
det2 <- function(k_1_d, k_2_d, M_d) {
n <- nrow(M_d)
n_j <- colSums(M_d)
tMM <- crossprod(x = M_d)
Psi_tilde_inv <- diag(n) - M_d%*%diag(k_1_d/(1 + k_1_d*n_j))%*%t(M_d)
return(log(k_2_d) + log(1/k_2_d + sum(Psi_tilde_inv)) + sum(log(1 + k_1_d*n_j)))
}
library(tidyverse)
data <- data.frame(
cidade =
c("cidade_1", "urbana", "rural",
"cidade_2", "urbana", "rural",
"cidade_3", "urbana", "rural"),
valor_1 = rpois(9, 100),
valor_2 = rpois(9, 1000))
library(tidyverse)
library(factoextra)
agg_transp <- read_csv("data/aggregated_transport.csv")
transp_border <- agg_transp %>%
group_by(location) %>%
mutate(mean_value = mean_value/max(mean_value))
library(tidyverse)
# Read the data
df <- read_csv("RIP_towns_6May_w_county_edited.csv")
# Change the format from wide to long
df_long <- df %>%
gather(key = date, value = deaths, -Town, -County) %>%
mutate(year = paste0("20", str_extract(date, "[0-9]{2}")),
year = as.numeric(year),
eliminate_words <- function(first_sentence, second_sentence){
if(is.na(second_sentence)) return(first_sentence)
first_word <- word(second_sentence, 1)
characters_first_word <- strsplit(first_word, split = "")[[1]]
# Get all possible words that could have remained in the previous
# sentence
words_list <- vector()