{{ message }}

Instantly share code, notes, and snippets.

# Richard Morey richarddmorey

• Cardiff University
• Cardiff, Wales
Created Dec 23, 2016
Using JAGS to sample missing values in both DVs and IVs in Bayesian regression
View missings_jags.R
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
 set.seed(123) # make reproducible M = 10000 # Number of posterior samples N = 20 # sample the IV x = rnorm(N, 10, 5) # regression model for DVs y = 100 + 3*x + rnorm(N,0,10) ## Delete missing data (3 in each)
Created Jul 29, 2020
Two proportions, p value
View X2.R
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),
Last active Jul 17, 2020
Compute p value for equivalence test
View eqt_pvalue.R
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
 data(attitude) library(cocor) ## EQtest at alpha = .05 needs a 90% CI cocor(~ rating + complaints | rating + learning, data = attitude, alternative = "less", null.value = .2, test = "zou2007", conf.level = .9) zou_ci_func = function(conf.level, ...) {
Created Jun 21, 2020
Attempt to reproduce Maglio & Polman (2014) Figure 1
View repro_subways.R
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
Created Jun 4, 2016
A demonstration of Bayes' theorem as "selecting subsets" using R markdown and interactive 3D plots
View binomial-beta.Rnw
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: "Joint and conditional, binomial/beta example" author: "Richard D. Morey" date: "4 June 2016" output: html_document --- ```{r,echo=FALSE,warning=FALSE} library(rgl) library(knitr)
Created Oct 23, 2019
View papaja_example.Rmd
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 : "The title" shorttitle : "Title" author: - name : "First Author" affiliation : "1" corresponding : yes # Define only one corresponding author address : "Postal address" email : "my@email.com"
Created Aug 21, 2019
CI "precision" reversal
View precision.R
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
 desired_precision = .6 N1 = 5 N2 = 6 # Function to compute CDFs of "precisions" (CI widths) SS_func = function(W, n, alpha = .05){ n * (n - 1) * W^2 / (4 * qt(1-alpha/2, n - 1)^2) }
Created Jun 23, 2019
Bayes factor for one-way table
View bf_one_way
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
 # Prior setup prior_concentration = 10 # null p0 = c(0.3, 0.3, 0.4) # fake data, null
Last active May 19, 2019
Eurovision 2016-2018 analysis
View eurovision2019.csv
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
To.country Jury Televoting Netherlands 231 261 Italy 212 253 Russia 125 244 Switzerland 148 212 Norway 47 291 Sweden 239 93 Azerbaijan 197 100 North Macedonia 237 58 Australia 154 131
Last active Apr 3, 2019
Demonstrate reading bibtex for Rmarkdown from the web (e.g., from github)
View demo.R
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
 # This file is to demonstrate the output. # It is not needed. testRmd = "https://gist.githubusercontent.com/richarddmorey/c4dd7d1fba2aa055a6f71286baedac25/raw/c256dd9f1ca0b22dfbce12443e1cb98ed5bb9d86/demo.Rmd" tf = tempfile(fileext = ".Rmd") tf_out = tempfile(fileext = ".html") cat(RCurl::getURL(testRmd), file = tf)