This is a handbag of commands that I find useful.

Get it started:

devtools::install_github("inductivestep/handbag")
library(handbag)

Enumerating contigency tables

Here are all 2 by 2 tables in which the total sum is 3:

enum_contingency_tables(2, 2, 3)

Analysis helper functions

library(tidyverse)
tib <- expand.grid(like_peas   = c(0,1), 
                   like_cheese = c(0,1),
                   like_chips  = c(0,1)) %>% as_tibble()

tib
tib$like <- handbag::binary_patterns_var(tib, "like_")
tib

Special relativity: playing around with spaceships

Let's go on holiday

speed_in_c    <- .8
distance_in_c <- 4

# Calculates the speed in m/s and distance in m
spaceship_speed     <- light_speed(speed_in_c)
distance_from_earth <- light_speed(distance_in_c)

# Work out the contracted length
distance_on_spaceship <- contracted_length(distance_from_earth,
                                           spaceship_speed)

You want to travel to a space hotel r distance_in_c light years away from earth, so you set off in a spaceship at r speed_in_c times the speed of light, c.

Length contraction means the distance from the perspective of the spaceship is shorter: r distance_on_spaceship / light_speed() light years, which would be experienced as taking r distance_on_spaceship / spaceship_speed years at r speed_in_cc.

From the perspective of earth, the trip would take r distance_from_earth / spaceship_speed years, though it would take an additional r distance_in_c years for a radio signal to return to say that you arrived okay.

Let's go on holiday again

speed_in_c    <- .999

# Calculates the speed in m/s and distance in m
spaceship_speed     <- light_speed(speed_in_c)
distance_from_earth <- light_speed(distance_in_c)

# Work out the contracted length
distance_on_spaceship <- contracted_length(distance_from_earth,
                                           spaceship_speed)

You want to travel to a space hotel r distance_in_c light years away from earth, so you set off in a spaceship at r speed_in_c times the speed of light, c.

Length contraction means the distance from the perspective of the spaceship is shorter: r distance_on_spaceship / light_speed() light years, which would be experienced as taking r distance_on_spaceship / spaceship_speed years at r speed_in_cc.

From the perspective of earth, the trip would take r distance_from_earth / spaceship_speed years, though it would take an additional r distance_in_c years for a radio signal to return to say that you arrived okay.

Let's go on holiday again - really fast this time...

speed_in_c    <- 1

This time you're going at the speed of light, c. Same distance: r distance_in_c light years.

# Calculates the speed in m/s and distance in m
spaceship_speed     <- light_speed(speed_in_c)
distance_from_earth <- light_speed(distance_in_c)

# Work out the contracted length
distance_on_spaceship <- contracted_length(distance_from_earth,
                                           spaceship_speed)

Length contraction means the distance from the perspective of the spaceship is shorter: r distance_on_spaceship / light_speed() light years, which would be experienced as taking r distance_on_spaceship / spaceship_speed years (no time!) at c.

From the perspective of earth, the trip would take r distance_from_earth / spaceship_speed years, though it would take an additional r distance_in_c years for a radio signal to return to say that you arrived okay.

Another example

This one is from Andrew Duffy.

speed_in_c    <- .95
distance_in_c <- 9.5

# Calculates the speed in m/s and distance in m
spaceship_speed     <- light_speed(speed_in_c)
distance_from_earth <- light_speed(distance_in_c)

# Work out the contracted length
distance_on_spaceship <- contracted_length(distance_from_earth,
                                           spaceship_speed)

You want to travel to a space hotel r distance_in_c light years away from earth, so you set off in a spaceship at r speed_in_c times the speed of light, c.

Length contraction means the distance from the perspective of the spaceship is shorter: r distance_on_spaceship / light_speed() light years, which would be experienced as taking r distance_on_spaceship / spaceship_speed years at r speed_in_cc.

From the perspective of earth, the trip would take r distance_from_earth / spaceship_speed years, though it would take an additional r distance_in_c years for a radio signal to return to say that you arrived okay.



InductiveStep/handbag documentation built on Aug. 2, 2020, 7:28 a.m.