Skip to content

Instantly share code, notes, and snippets.

View cddesja's full-sized avatar

Chris Desjardins cddesja

  • Saint Michael's College
  • Colchester, Vermont
  • 14:20 (UTC -04:00)
View GitHub Profile
[internal] Wed Dec 21 08:22:34 2022:
(:message "Running language server: (/Library/Frameworks/Python.framework/Versions/3.10/bin/pyright-langserver --stdio)")
[client-request] (id:1) Wed Dec 21 08:22:34 2022:
(:jsonrpc "2.0" :id 1 :method "initialize" :params
(:processId 11322 :rootPath "/Users/cdesjardins/Dropbox/chris/programming/python/python_data_science_handbook/" :rootUri "file:///Users/cdesjardins/Dropbox/chris/programming/python/python_data_science_handbook" :initializationOptions #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data
())
:capabilities
(:workspace
(:applyEdit t :executeCommand
(:dynamicRegistration :json-false)
@cddesja
cddesja / introductory_statistics.R
Last active March 29, 2022 12:11
Helper Functions for Introductory Statistics
#' @param xbar sample mean
#' @param s sample standard deviation
#' @param n sample size
#' @param mu0 null hypothesis value
#' @param ha alternative hypothesis. takes on the value of "less than", "greater than", "not equal to"
#' @example
#' single.mean.test(xbar = 1.91, s = 1.22, n = 305, mu0 = 2.47, ha = "not equal to")
single.mean.test <- function(xbar, s, n, mu0, ha = "not equal to"){
t.stat <- (xbar - mu0) / (s / sqrt(n))
cat("The t-statistic is equal to:", t.stat, "\n")
@cddesja
cddesja / statbin2.R
Created January 31, 2022 15:40
Better binning
# modified version of StatBin2 inherits from StatBin, except for an
# additional 2nd last line in compute_group() function
StatBin2 <- ggproto(
"StatBin2",
StatBin,
compute_group = function (data, scales, binwidth = NULL, bins = NULL,
center = NULL, boundary = NULL,
closed = c("right", "left"), pad = FALSE,
breaks = NULL, origin = NULL, right = NULL,
drop = NULL, width = NULL) {
@cddesja
cddesja / cenz.R
Created April 16, 2021 17:07
definition of censoring plot
vadj <- .03
hadj <- .015
grid.newpage()
vp <- viewport(width=0.85,height=0.85)
pushViewport(vp)
grid.lines(x = c(0, 1),
y = c(0, 0),
gp = gpar(fill = "black"),
arrow = arrow(angle = 20, type = "closed"))
## participants
@cddesja
cddesja / dawson.R
Last active December 4, 2020 18:49
Dawson's Plot
covid <- read.csv("https://data.cdc.gov/api/views/y5bj-9g5w/rows.csv?accessType=DOWNLOAD&bom=true&format=true%20target=")
names(covid)[1] <- "Jurisdiction"
library(dplyr)
library(ggplot2)
ct <- covid %>%
group_by(Week, Year) %>%
filter(Type == "Unweighted", Jurisdiction != "United States") %>%
summarize(totl = sum(Number.of.Deaths))
@cddesja
cddesja / yt.Rmd
Last active September 9, 2020 21:20
embeding YT
---
title: "RR Laura Le"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
<iframe id="inlineFrameExample"
mtcars$vs.f <- ifelse(mtcars$vs == 0, "0", "1")
mtcars.0 <- subset(mtcars, vs.f == "0")
mtcars.1 <- subset(mtcars, vs.f == "1")
coef(lm(mpg ~ cyl * vs.f, data = mtcars)) # association between 1 should be strong
coef(lm(mpg ~ cyl, data = mtcars.0)) # association between 0 smaller
coef(lm(mpg ~ cyl, data = mtcars.1)) # association between 1 larger
cor(mtcars.0$mpg, mtcars.0$cyl)
cor(mtcars.1$mpg, mtcars.1$cyl)
@cddesja
cddesja / PISA.csv
Created February 29, 2020 17:25
PISA scores
Country Total Score
Spain 38
Spain 44
Spain 42
Spain 46
Spain 29
Spain 8
Spain 22
Spain 49
Spain 32
@cddesja
cddesja / tidy.R
Last active February 27, 2020 15:27
# untidyverse
# this one is sooooooo hard to type
an.agg <- aggregate(bmi ~ an_j + months,
FUN = function(x) c(m = mean(x), n = n(x)),
data = an.l)
# tidyverse
# this one makes my fingers sing
bmi %>%
group_by(an_j) %>%
@cddesja
cddesja / cleanNA.R
Created February 25, 2020 18:54
clean up the NAs
cleanNAs <- function(x){
if(sum(is.na(x)) == length(x)) {
x <- NA
} else
x <- x[!is.na(x)]
x
}
dat <- read.csv("testing.csv", header = TRUE)
dat$clean <- apply(dat, 1, cleanNAs)