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(dplyr) | |
library(ggplot2) | |
library(ggdist) | |
url = 'https://osf.io/846cb/download' | |
httr::GET(url, httr::write_disk(tf <- tempfile(fileext = ".xlsx"))) | |
readxl::read_xlsx(tf) %>% | |
mutate( | |
DIRECTION = factor(DIRECTION, levels = c("WEST","EAST"), |
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
--- | |
title: "Test SurveyJS and Rmarkdown" | |
output: | |
html_document: | |
css: "https://unpkg.com/survey-jquery/survey.min.css" | |
editor_options: | |
chunk_output_type: console | |
--- | |
A test javascript survey by building a JSON object for [SurveyJS](https://surveyjs.io/). |
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
No | homo | CC | Latitude | north | lat_from_o | tpar | meantemp | hitemp | lotemp | diftemp | Isosd | dpop_30 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | 1 | 595 | 27 | 0 | 35 | 1 | 17.8 | 30 | 1 | 29 | 0.218223437 | 13 | |
2 | 1 | 475 | 27 | 0 | 35 | 1 | 17.8 | 30 | 1 | 29 | 0.218223437 | 13 | |
3 | 1 | 507 | 27 | 0 | 35 | 1 | 17.8 | 30 | 1 | 29 | 0.218223437 | 13 | |
4 | 1 | 570 | 27 | 0 | 35 | 1 | 17.8 | 30 | 1 | 29 | 0.218223437 | 13 | |
6 | 1 | 776 | 4 | 1 | 4 | 7 | 24.7 | 26 | 11 | 15 | 0.212807364 | 13 | |
7 | 1 | 506.333 | 4 | 1 | 4 | 7 | 24.7 | 26 | 11 | 15 | 0.212807364 | 13 | |
8 | 1 | 622.5 | 4 | 1 | 4 | 7 | 24.7 | 26 | 11 | 15 | 0.212807364 | 13 | |
5 | 1 | 500 | 7 | 1 | 1 | 7 | 22.2 | 25 | 6 | 19 | 0.212807364 | 13 | |
15 | 1 | 775 | 40 | 1 | 32 | 4 | 5.8 | 31 | -1 | 32 | 0.25577606 | 16 |
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
# Test answer to https://stackoverflow.com/questions/68473292/prevent-double-execution-of-shiny-reactive-with-two-dependency-pathways/68475515#68475515 | |
library(shiny) | |
library(digest) | |
ui <- fluidPage( | |
sidebarLayout( | |
sidebarPanel( | |
textInput("M", "M:", ""), | |
uiOutput("S_UI"), |
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
## Define MVTN parameters | |
mu = c(-1,0,1) | |
Sigma = matrix( | |
c(1, 0, 0, | |
0, 1, .5, | |
0, .5, 1 | |
), 3,3) | |
p = length(mu) | |
library(mvtnorm) |
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
N = 20 | |
library(mvtnorm) | |
# No shared variance between a and (b,c) | |
Sigma = matrix(c(1,0,0, | |
0,1,.5, | |
0,.5,1), 3, 3) | |
# Simulation |
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
https://www.theguardian.com/science/2021/feb/08/can-you-solve-it-think-of-a-number | |
The suggested answer using "yes" and "no" amounts to encoding in base 2, which is inefficient because there are | |
three possible response options ("yes", "no", "I don't know"). We want to find a way of encoding in base 3, which | |
amounts to assigning 1/3 of the numbers to "yes", 1/3 to "no", and 1/3 to "I don't know". We can do that by telling | |
Johnny on the first step (and analogously afterward): | |
"I have two numbers in mind. One of them is 334. The other is less than 667 but greater than 333, but I will not tell you what it is. Is your | |
number less than both of my numbers?" |
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
x = rlogis(10000,0,10) | |
mod = "model{ | |
y ~ dlogis(0, 1/10) | |
} | |
" | |
library(rjags) | |
m = rjags::jags.model(file = textConnection(mod)) | |
s = rjags::coda.samples(m,n.iter = 10000,variable.names = "y") |
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(tictoc) | |
df = data.frame(y = rnorm(10000000), x = rbinom(10000000,1,.5)) | |
tic() | |
z = df[df$x == 1,]$y | |
toc() | |
rm(z) | |
tic() |
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
N = c(16, 16) | |
y = c(3, 9) | |
actual_result = prop.test(y, N, correct = FALSE) | |
compute_p_value = function(p0){ | |
## Probability of all outcomes, | |
## assuming independence | |
pr_X2s = | |
outer( dbinom(0:N[1], N[1], p0), |