Skip to content

Instantly share code, notes, and snippets.

View hauselin's full-sized avatar

Hause Lin hauselin

View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
library(dplyr)
library(broom)
library(modelsummary)
clean_colnames <- function(df) {
new <- tolower(gsub(" ", "_", names(df)))
new <- gsub(".", "_", new, fixed = TRUE)
new <- gsub("(", "", new, fixed = TRUE)
new <- gsub(")", "", new, fixed = TRUE)
@hauselin
hauselin / github.bash
Created October 17, 2020 13:22 — forked from igrigorik/github.bash
Open GitHub URL for current directory/repo...
alias gh="open \`git remote -v | grep git@github.com | grep fetch | head -1 | cut -f2 | cut -d' ' -f1 | sed -e's/:/\//' -e 's/git@/http:\/\//'\`"
df_long = pd.DataFrame(
{"student": ["Andy", "Bernie", "Cindy", "Deb", "Andy", "Bernie", "Cindy", "Deb", "Andy", "Bernie", "Cindy", "Deb"],
"school": ["Z", "Y", "Z", "Y", "Z", "Y", "Z", "Y", "Z", "Y", "Z", "Y"],
"class": ["english", "english", "english", "english", "math", "math", "math", "math", "physics", "physics", "physics", "physics"],
"grade": [10, 100, 1000, 10000, 20, 200, 2000, 20000, 30, 300, 3000, 30000]
}
)
df_long
> student school class grade
def simulate(simulations=1000, n=500, quantile=0.80):
correlations = np.zeros(simulations)
for i in range(simulations):
data = {"personality": np.random.randn(
n), "attract": np.random.randn(n)}
df = pd.DataFrame(data)
@hauselin
hauselin / README.md
Created March 6, 2019 09:46 — forked from hofmannsven/README.md
My simply Git Cheatsheet
# see also seWithin function in hausekeep package
# https://hauselin.github.io/hausekeep/reference/seWithin.html
summarySE2 <- function (data = NULL, measurevar, groupvars = NULL, na.rm = TRUE, conf.interval = 0.95) {
library(data.table)
data <- data.table(data)
length2 <- function(x, na.rm = FALSE) {
if (na.rm)
sum(!is.na(x))
else length(x)
summarySE2 <- function (data = NULL, measurevar, groupvars = NULL, na.rm = TRUE, conf.interval = 0.95) {
library(data.table)
data <- data.table(data)
length2 <- function(x, na.rm = FALSE) {
if (na.rm)
sum(!is.na(x))
else length(x)
}
Atom Settings
#function to compute R2s in logistic regression
logisticR2s <- function(logisticModel) {
modelDeviance <- logisticModel$deviance
nullDeviance <- logisticModel$null.deviance
n <- length(logisticModel$fitted.values)
R2HosmerLemeshow <- 1 - modelDeviance / nullDeviance
R2CoxSnell <- 1 - exp((modelDeviance - nullDeviance) / n)
R2Nagelkerke <- R2CoxSnell / (1 - exp( - (nullDeviance / n)))