Skip to content

Instantly share code, notes, and snippets.

Drew Schmidt wrathematics

View GitHub Profile
View eval.r
f = function(expr)
{
for (i in 1:2)
print(system.time(eval(expr))[[3]])
}
f(Sys.sleep(.4))
## [1] 0.401
## [1] 0
@wrathematics
wrathematics / nics.csv
Created Apr 3, 2020
monthly NICS background checks
View nics.csv
Year Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Totals
1998 871644 892840
1999 591355 696323 753083 646712 576272 569493 589476 703394 808627 945701 1004333 1253354 9138123
2000 639972 707070 736543 617689 538648 550561 542520 682501 782087 845886 898598 1000962 8543037
2001 640528 675156 729332 594723 543501 540491 539498 707288 864038 1029691 983186 1062559 8910191
2002 665803 694668 714665 627745 569247 518351 535594 693139 724123 849281 887647 974059 8454322
2003 653751 708281 736864 622832 567436 529334 533289 683517 738371 856863 842932 1008118 8481588
2004 695000 723654 738298 642589 542456 546847 561773 666598 740260 865741 890754 1073301 8687671
2005 685811 743070 768290 658954 557058 555560 561358 687012 791353 852478 927419 1164382 8952945
2006 775518 820679 845219 700373 626270 616097 631156 833070 919487 970030 1045194 1153840 10036933
View Dockerfile
FROM alpine:3.10.2
RUN apk add R R-dev bash build-base
CMD ["/bin/bash"]
View manifest.r
pbd = c(
"hdfio",
"hpcvis",
"kazaam",
"pbdBASE",
"pbdCS",
"pbdDEMO",
"pbdDMAT",
"pbdIO",
"pbdML",
View gist:275576ae638c57d7277fb5188b6be5f3
library(memuse)
library(hdfio)
f = nycflights13::flights
for (compression in c(0, 4, 9)){
suppressWarnings(file.remove("flights.h5"))
write_h5df(f, "flights.h5", compression=compression)
print(Sys.filesize("flights.h5"))
}
View logical.r
library(inline)
csrc = "
SEXP ret;
PROTECT(ret = allocVector(LGLSXP, 2));
LOGICAL(ret)[0] = 1;
LOGICAL(ret)[1] = -1;
UNPROTECT(1);
return ret;
View lm.Rmd
---
title: "A Bit on the Numerics Behind R's Linear Model Fitters"
output: html_document
---
The classical linear regression setup is that you want to solve a system of equations that looks something like:
$X_{m\times n}\beta_{n\times 1} = y_{m\times 1}$
In statistics/data analysis, it's pretty typical for $m>n$. If $X$ has ["full rank"](https://en.wikipedia.org/wiki/Rank_(linear_algebra)) (more on this later). In this case, [we can derive a closed form solution](https://en.wikipedia.org/wiki/Least_squares#Linear_least_squares) for $\beta$:
View cache
#include <stdio.h>
#include <papi.h>
#include <stdlib.h>
#define NUM_EVENTS 2
int main(int argc, char **argv)
{
int a = atoi(argv[1]);
int b = atoi(argv[2]);
View cache_misses.c
#include <stdio.h>
#include <papi.h>
#define NUM_EVENTS 2
int main()
{
int events[NUM_EVENTS] = {PAPI_L1_DCM, PAPI_L2_DCM};
long long values[NUM_EVENTS];
View gist:07d240b267883c93ef79ebf33a6b734b
// ----- count.c
// build with R CMD SHLIB count.c (or put it in the package, w/e)
#include <R.h>
#include <Rinternals.h>
SEXP colsum_which_eq0(SEXP nrows_, SEXP ncols_, SEXP J_)
{
SEXP ret;
const int nrows = INTEGER(nrows_)[0];
You can’t perform that action at this time.