In about:config set dfjs.disableFontFace to true
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
################################################################################ | |
# Using the US CDC life tables for White Males (2020), I wanted to estimate the | |
# Probability that if Joe Biden or Donald Trump became the next US president | |
# They would die in office. The general approach could be used for any interval. | |
# The life tables can be found here: https://stacks.cdc.gov/view/cdc/118055 | |
################################################################################ | |
library(tidyverse) | |
library(lubridate) |
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
version_new <- list.files('~/R/x86_64-pc-linux-gnu-library/4.2') | |
version_old <- list.files('~/R/x86_64-pc-linux-gnu-library/4.1') | |
target <- version_old[!(version_old %in% version_new)] | |
install.packages(target) |
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
#' In a dataframe, find all variable names that match var_pattern | |
#' | |
#' @param var_pattern a character string ("pattern" to match) | |
#' @param dframe a dataframe | |
#' | |
#' @return all variable names in the dataframe that match var_pattern | |
#' @export | |
#' | |
#' @examples | |
#' find_var(iris, "idth") |
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
# A quick visual analysis of Donald Trump's BMI assuming that his reported weight | |
# in 2018 and 2019 are correct, and his real height lies between his claimed | |
# height of 6'3" (1.9m) and a more likely height of 6'1" (1.854m) | |
# https://www.theguardian.com/us-news/2018/jan/17/a-tall-tale-accuracy-of-trumps-medical-report-and-new-height-questioned | |
# Include the ggplot library | |
library(ggplot2) | |
# Function to calculate BMI from height (m) and mass/weight (Kg) | |
bmicalc <- function(height, mass){ |
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
phred <- function(q){ | |
10^(-q/10) | |
} | |
inv_phred <- function(p){ | |
10 * log10(p) | |
} |
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
# These data appeared in a graph on climate.gov: http://bit.ly/2AFNBJz. | |
# Paraphrasing from the website: | |
# The data are for each November since 1979 to 2017. | |
# The variable 'area' represents the combined November sea ice | |
# area for the Chukchi and Beaufort Seas, the two sub-basins of | |
# the Arctic Ocean that touch Alaska’s Arctic (northern) coast. | |
# Larger values means more sea ice in the combined basin in square kilometres. | |
# The variable 'temp' is the November temperature (Fahrenheit) at Utqiaġvik, | |
# also known as Barrow (71°17′26″N 156°47′19″W). | |
# The data were digitised using Plot Digitizer |
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 is a quick script to create two time series plots using World Bank data downloaded using the wbstats package | |
# and plotted using ggplot2. | |
# The first plot uses Malaysia data only, and is a time series plot showing Life Expectancy at Birth changes | |
# in the whole population and for males and females separately. | |
# The second plot uses data for a handful of Southeast Asian countries and Australia and shows changes in the | |
# Infant Mortality Rate over time. | |
library(wbstats) | |
library(tidyverse) |
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 is a small piece of R-Code to support a recent blog-post of mine on country-level inequalities in life expectancy. # | |
# If you are so inclined, you can read the blog-post here: http://wp.me/p8fOE1-13 # | |
# # | |
# For the purposes of re-use, the code is released under an MIT License (https://choosealicense.com/licenses/mit/) # | |
# The code is provided "as is" and without warranties. # | |
# # | |
####### Notes |
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
# Imagine that the probability of dying over a whole year is 0.5. Assuming risk is constant, | |
# what is the probability of dying in any single month? This trivial function (thank you Mark) | |
# ensures that the monthly-p results in an annual probability of 0.5. I wanted somewhere to | |
# remember it | |
p-Divide <- function(P, n){ | |
1-(1-P)^(1/n) | |
} |
NewerOlder