This file contains hidden or 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
# Convert a 95% confidence interval to a p-value (two-sided). | |
# Based on: | |
# How to obtain the P value from a confidence interval | |
# BMJ 2011; 343 doi: https://doi.org/10.1136/bmj.d2304 | |
# From estimate to p-value. | |
estimate.to.pvalue <- function(estimate, lower, upper) { | |
stderror = (upper - lower) / (2 * 1.96) # Get standard error. | |
z = estimate / stderror # Get test statistic. | |
p.value = exp(-0.717 * z - 0.416 * (z ^ 2)) # Get p-value. |
This file contains hidden or 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
# Create data. | |
set.seed(1341) | |
original <- data.frame(x = rnorm(10), y = rnorm(10)) | |
change <- original | |
change[5, 1] <- 6 | |
change[7, 2] <- 4 | |
# Function to compare data frames for similarity. | |
compare_data_frames <- function(df1, df2) { | |
if (identical(df1, df2)) { |
This file contains hidden or 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
Include a DiagrammeR grViz() diagram into your RMarkdown document without the need to create a graph PDF file separately. | |
Based on the code from https://github.com/rich-iannone/DiagrammeR/issues/133#issuecomment-284370996. | |
```{r} | |
# Install packages. | |
install.packages(c("DiagrammeR", "DiagrammeRsvg", "rsvg", "magrittr")) | |
``` | |
```{r} |
This file contains hidden or 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
@echo off | |
REM From https://stackoverflow.com/questions/568564/how-can-i-view-live-mysql-queries | |
mysqladmin -u username -ppassword --verbose -i 1 processlist |
This file contains hidden or 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) | |
n.samples = 25 | |
set.seed(5) | |
rerun(20,rnorm(n.samples)) %>% | |
map_dfr(~data_frame(data = list(.x)), .id = 'samples') %>% | |
mutate(mu = map_dbl(data,mean), | |
se = map_dbl(data,~sd(.x)/sqrt(length(.x))), | |
top = mu +1.96*se, |
This file contains hidden or 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(gganimate) | |
library(ggrepel) | |
library(lubridate) | |
library(tidyverse) | |
# The order is FUBAR. | |
partycolors <- c("#006AB3", "#000077", "#52BDEC", "#E8112d", | |
"#83CF39", "#009933", "#DA291C", "#E8AC41") | |
# Mediearkivet keywords: |
This file contains hidden or 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) | |
df <- read.csv("https://raw.githubusercontent.com/peterdalle/effectsizes/master/soc-psych.tsv", | |
header=TRUE, sep="\t", stringsAsFactors=FALSE) | |
df.comm <- read.csv("https://raw.githubusercontent.com/peterdalle/effectsizes-comm/master/effectsizes.csv", | |
header=TRUE, sep=",", stringsAsFactors=FALSE) | |
ggplot() + | |
geom_density(aes(df$r), fill="red", alpha=0.3) + |
This file contains hidden or 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
favorite_packages <- c( | |
# Package development | |
"devtools", "Rcpp", "roxygen2", "testthat", "covr", | |
# Handle data | |
"rio", "tidyverse", "broom", "lubridate", "stringr", | |
# Database | |
"RMySQL", | |
This file contains hidden or 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
create_correlation <- function(n=1000, r=0.5) { | |
# Based on caracal:s answer at | |
# https://stats.stackexchange.com/questions/15011/generate-a-random-variable-with-a-defined-correlation-to-an-existing-variables/15040#15040 | |
theta <- acos(r) # corresponding angle | |
x1 <- rnorm(n, 1, 1) # fixed given data | |
x2 <- rnorm(n, 2, 0.5) # new random data | |
X <- cbind(x1, x2) # matrix | |
Xctr <- scale(X, center=TRUE, scale=FALSE) # centered columns (mean 0) | |
Id <- diag(n) # identity matrix | |
Q <- qr.Q(qr(Xctr[ , 1, drop=FALSE])) # QR-decomposition, just matrix Q |
This file contains hidden or 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
REM https://stackoverflow.com/questions/14304480/batch-resize-images-and-output-images-to-new-folder-with-imagemagick | |
magick mogrify -resize 1024 -quality 100 -path ./new *.jpg |