Skip to content

Instantly share code, notes, and snippets.

View 3inar's full-sized avatar

Einar Holsbø 3inar

View GitHub Profile
#include <stdio.h>
void put_character(char);
void end_line();
char mask_bit(char, char);
int main() {
char a_character;
a_character = -5;
#include <stdio.h>
void put_character(char);
char mask_bit(char a_char, char bit);
void end_line() {
printf("\n");
}
#include <stdio.h>
void put_character(char);
int main() {
put_character(5);
end_line();
return 0;
}
@3inar
3inar / mice.R
Created March 24, 2020 10:28
mice demo
library(mice)
# y is function of x
x <- rnorm(100)
y <- x + rnorm(100, sd=.5)
# make some ys missing
y[sample(length(y), 10)] <- NA
dframe <- data.frame(y=y, x=x)
library(dplyr)
data_url <- "https://github.com/3inar/crime_rates/raw/master/src/data/norwegian_crime.rda"
load(url(data_url))
violent <- norwegian_crime %>% filter(crime_type=="¬ Vold og mishandling", year==2014)
violent <- violent %>% mutate(rate=reports/population)
hist(violent$rate)
@3inar
3inar / untitled-2018-01-22.R
Created January 22, 2018 17:24
2018-01-22 untitled from rstudio
# source:
# https://en.wikipedia.org/wiki/List_of_United_States_federal_funding_gaps
budget_gaps <- matrix(c(
12, 0,
14, 0,
10, 0,
10, 0,
19, 0,
13, 0,
@3inar
3inar / untitled-2018-01-16.R
Created January 16, 2018 08:53
2018-01-16 untitled from rstudio
library(ProjectTemplate); load.project()
library(plyr)
crime_type <- "¬ Vold og mishandling"
towns <- mean_crimes(crime_type)
counts <- simulate_crimes(towns$population, towns$cpp, law="binomial")
data <- tibble(rate=counts/towns$population, population=towns$population, reports=counts)
data <- as.tibble(cbind(data, stats(data)))
@3inar
3inar / untitled-2017-11-02.R
Created November 2, 2017 17:12
2017-11-02 untitled from rstudio
library(plyr)
library(MASS)
test <- raply(50000, {
dat <- mvrnorm(200, mu = c(0,1), Sigma = matrix(c(1,.3,.3,1), nrow=2))
y <- dat[,1]
x <- dat[,2]
# throw away most of the data, introduce huge bias
y <- y[x > 1]
@3inar
3inar / untitled-2017-10-24.R
Created October 24, 2017 13:57
2017-10-24 untitled from rstudio
library(pmadsim)
library(curveselection)
library(plyr)
library(ktspair)
lambdas <- 1/seq(0.01, 2, length.out = 10)
res <- aaply(lambdas, 1, function(lambda2) {
raply(1000, {
d <- simulation(lambda2=lambda2)
@3inar
3inar / untitled-2017-10-18.R
Created October 18, 2017 13:35
2017-10-18 untitled from rstudio
expression <- exprs(gene_expression)
expression_se <- se.exprs(gene_expression)
detection <- detection(gene_expression)
control_data <- controlData(gene_expression)
write.csv(expression, file="for_submission/expression.csv")
write.csv(expression_se, file="for_submission/expression_se.csv")
write.csv(detection, file="for_submission/detection.csv")
write.csv(control_data, file="for_submission/control_data.csv")