Skip to content

Instantly share code, notes, and snippets.

View chris-prener's full-sized avatar

Chris Prener chris-prener

View GitHub Profile
@chris-prener
chris-prener / vectorized_strings.R
Created November 27, 2018 22:32
Detecting Multiple Patterns in Strings, Vectorized
library(dplyr)
library(stringr)
# create test data
orders <- data.frame(
id = c(1,2,3,4),
items = c("Apples and Turkey", "Bacon and Crackers", "Bananas and Juice", "Pecan Pie and Ice Cream"),
stringsAsFactors = FALSE
)
#' Two-tailed Probabilities Under the t Distribution
#'
#' @description This function calculates the probability of observing a t score
#' at least as extreme as the given t value for any t test
#'
#' @param t A given t score
#' @param df The degrees of freedom associated with t
#'
#' @details Depending on the type of t test, degrees of freedom (v) is calculated
#' in a different manner. For one sample and dependent t tests, v is n-1.
@chris-prener
chris-prener / probt.R
Last active October 12, 2018 14:56
Two-tailed probability under t distribution
#' Two-tailed Probabilities Under the t Distribution
#'
#' @description This function calculates the probability of observing a t score
#' at least as extreme as the given t value for a one sample t test
#'
#' @param t A given t score
#' @param n The sample size associated with t
#'
#' @return A probability value
#'
library(dplyr)
library(ggplot2)
library(latex2exp)
abline <- as_tibble(data.frame(
xmin = c(0),
xmax = c(10),
ymin = c(5),
ymax = c(5)
))
@chris-prener
chris-prener / randomRespondents.R
Last active January 11, 2018 19:22
Generate a Random Data Frame of Names and Genders
# dependencies
library(dplyr) # data wrangling
library(gender) # assess gender
library(randomNames) # generate names
library(stringr) # work with strings
# create data frame of random names
names <- randomNames(30, which.names = "both", name.order = "first.last", name.sep = " ")
names <- as.data.frame(names, stringsAsFactors = FALSE)
@chris-prener
chris-prener / lecture-01-leaflet.R
Last active December 20, 2017 13:49
SOC 4650 & SOC 5650 - Lecture 01 - Introduction to GIS in R
# DEPENDENCIES:
# leaflet and devtools, installed from CRAN
# stlData, installed from GitHub
# LOAD PACKAGES:
library(leaflet)
library(stlData)
# MAP 1A: MORRISSEY HALL
# use OpenStreetMap map tiles by default
@chris-prener
chris-prener / week-11-scale.R
Last active December 12, 2017 20:39
SOC 4930 & SOC 5050 - Week 11 - Creating Scale Variable
library(ggplot2)
library(dplyr)
# load data
autoData <- mpg
# subset to create data frame with only variables of interest for scale
autoSubset <- select(autoData, cyl, cty, hwy)
# visually inspect cronbach's alpha results
@chris-prener
chris-prener / bibliography.bib
Created November 20, 2017 16:12
SOC 4930 & SOC 5050 - Week 13 - Example BibTeX Bibliography File
@book{fisher1937design,
title="The design of experiments",
author="Fisher, Ronald Aylmer",
year="1937",
address="London, UK",
publisher= "Oliver and Boyd"
}
@article{mcgill1978variations,
title={Variations of box plots},
author={McGill, Robert and Tukey, John W and Larsen, Wayne A},
@chris-prener
chris-prener / week-13-exercise.tex
Created November 20, 2017 16:07
SOC 4930 & SOC 5050 - Week 13 - Bibliographies in LaTeX
\documentclass{article}
\usepackage[utf8]{inputenc}
\title{}
\author{}
\date{}
\begin{document}
\maketitle
@chris-prener
chris-prener / week-12-lecture.Rmd
Created November 13, 2017 21:24
SOC 4930 & SOC 5050 - Week 12 - Plot and Linear Model Examples
---
title: "Week-12 Lecture"
output: html_notebook
---
## Introduction
This is the sample code for Week 12's lecture.
## Dependencies