library(tidyverse)
library(osfr)
meta <- osf_retrieve_file("5a9hb") |>
osf_download(conflicts = "overwrite")
data <- meta$local_path |>
read_csv() |>
select(SAI_winsorized_IQ, Raven_IQ, SAIQ_IQ_dif) |>
# pak::pak("gpiras/sphet")
library(fastRG)
#> Loading required package: Matrix
library(sphet)
# simulate from y = alpha + trt * gamma + G trt * delta + lambda G y
set.seed(26)
library(tidyverse)
library(mgcv)
#> Loading required package: nlme
#>
#> Attaching package: 'nlme'
#> The following object is masked from 'package:dplyr':
#>
#> collapse
#> This is mgcv 1.8-41. For overview type 'help("mgcv-package")'.
library(tidyverse)
p_at_least_one_event <- function(p_event, periods = 50) {
tibble(
time = 1:periods,
p_at_least_one_event = 1 - (1 - p_event)^(1:periods)
)
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
data(mcycle, package = "MASS") | |
f_approxfun <- approxfun(mcycle$times, mcycle$accel) | |
f_splinefun <- splinefun(mcycle$times, mcycle$accel) | |
mcycle |> | |
ggplot(aes(times, accel)) + | |
geom_point() + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` r | |
# pak::pkg_install("stillmatic/MNIST") | |
library(MNIST) | |
# 1 is the most common digit in train | |
table(MNIST::mnist_train$y) / nrow(MNIST::mnist_train) | |
#> | |
#> 0 1 2 3 4 5 6 | |
#> 0.09871667 0.11236667 0.09930000 0.10218333 0.09736667 0.09035000 0.09863333 | |
#> 7 8 9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(tidygraph) | |
library(netmediate) | |
data <- read.csv("final_regime.IGO.sanction.csv") |> | |
# remove some columns of missing data to avoid downstream issues & unnnecessary columns | |
select(-1, -AMCOW, -MOPAN, - year, -version) | |
node_data <- data |> | |
select(country, ccode, polity2, democracy, sanction) |> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(tidygraph) | |
library(netmediate) | |
data <- read_csv("final_regime.IGO.sanction.csv") |> | |
# remove some columns of missing data to avoid downstream issues | |
select(-1, -AMCOW, -MOPAN) | |
node_data <- data |> | |
select(country, ccode, polity2, democracy, sanction) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` r | |
library(tidyverse) | |
library(glue) | |
library(unglue) | |
#> Warning: package 'unglue' was built under R version 4.2.3 | |
"~/../Desktop/patty-restaurants.txt" |> | |
readLines() |> | |
unglue_data("- [{visited}] {name}") |> | |
arrange(visited, name) |> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# rotate Y to align it to X | |
mypro <- function(X, Y) { | |
XY <- crossprod(X, Y) | |
s <- svd(XY) | |
rotation <- s$v %*% t(s$u) | |
Yrot <- Y %*% rotation | |
diff <- X - Yrot | |
colwise_loss <- Matrix::colSums(diff^2) | |
two_infty_loss <- max(sqrt(Matrix::rowSums(diff^2))) |
NewerOlder