Skip to content

Instantly share code, notes, and snippets.

Avatar

Douglas Bates dmbates

  • University of Wisconsin
  • Madison, WI, U.S.A.
View GitHub Profile
@dmbates
dmbates / RCall_IJulia_ggplot2.qmd
Last active Jul 2, 2022
Using ggplot2 in IJulia notebook through RCall
View RCall_IJulia_ggplot2.qmd
---
jupyter: julia-1.7
---
```{julia}
using RCall
```
```{julia}
RCall.ijulia_setdevice(MIME("image/svg+xml"))
@dmbates
dmbates / benchmark.jl
Created Jun 4, 2022
Code for benchmarking sort!(unique!(df)) versus sort!(df) on a real-world example
View benchmark.jl
using CSV, DataFrames, Downloads, Tar
datadir = "biofast-data-v1"
tarball = "$datadir.tar.gz"
if !isfile(tarball)
dataurl = joinpath(
"https://github.com/lh3/biofast/releases/download",
datadir,
tarball,
)
@dmbates
dmbates / Issue611.ipynb
Created May 3, 2022
Notebook related to MixedModels.jl issue 611
View Issue611.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dmbates
dmbates / dyestuff.Rnd
Created Apr 2, 2014
MathJax coding for \mathcal does not show up properly in the RStudio HTML previewer.
View dyestuff.Rnd
---
title: JAGS and lme4
author: Douglas Bates
date: March 28, 2014
output:
html_document:
toc: yes
highlight: tango
fig_width: 7
fig_height: 5.5
@dmbates
dmbates / permsums.ipynb
Last active Apr 20, 2021
Permutation tests in Julia
View permsums.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dmbates
dmbates / intro.md
Created Mar 3, 2014
Environment-based lme4
View intro.md

Background

The current version of the (lme4)[https://github.com/lme4/lme4] package for (R)[http://www.r-project.org) is based on a rather questionable practice of storing external pointers from C++ objects in an R reference class object. The idea was that when the reference class object was created the corresponding C++ class instance would be created. All changes to this object would be made through the external pointer in the C++ code.

This is risky because any changes to the R objects in the reference class could cause changes in the location of its values, after which all bets are off because the R object and the C++ object are referring to different memory locations.

It turns out that this does happen in the development version of R, which will become R-3.1.0, if the LAZY_DUPLICATE_OK flag is set. The symptom is that deepcopy methods are not copying and I suspect this is because the lazy duplication doesn't duplicate before the external pointer is constructed. We were living outsid

@dmbates
dmbates / Problem104.ipynb
Created Oct 3, 2013
Project Euler problem 104 in Julia.
View Problem104.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dmbates
dmbates / casestudy.md
Last active Dec 17, 2015
Handling Genome-Wide Association study data in Julia
View casestudy.md

Objectives

The dimensions of data on DNA variation such as single nucleotide polymorphisms or SNPs can be very large, involving thousands or millions of SNPs, measured on potentially thousands of individuals. Typical genotyping platforms may examine from 50K(K=thousand) to 2.5M (M= millions) SNPs. Some platforms could be even denser. There are 2 nucleotides (A, C, G or T) at each position (one on each chromosome). If the genotyping read is not sufficiently good, a missing value could be recorded in one or both chromosomes for that position/SNP. A frequently used re-codification of the nocleotide data is to replace the characters (i.e. alleles) by the count of the allele with the lower frequency in the sample, or according to a pre-specified allele as determined in the genotyping platform and software. Thus, instead of storing a pair of nucleotides (e.g., AA, AG, GG), researchers store the individual’s genotype as either 0,1,2, or NA. In thi

@dmbates
dmbates / gist:5303570
Last active Dec 15, 2015
Formula, ModelFrame and ModelMatrix types
View gist:5303570

Formula, ModelFrame and ModelMatrix types

In R, the functions for fitting statistical models based on a linear predictor usually allow for a formula/data specification of the model. The data part is a data.frame object in R. In Julia the corresponding type is a DataFrame as implemented in the DataFrames package.

A formula object in R is an expression whose top-level operator is a unary or binary tilde, ~. The interpretation of many operators, including +, *, ^, \ and : are overridden in the formula language. See the result of

?formula

in R for the details.

@dmbates
dmbates / Intro.md
Created Dec 18, 2012
Use of the "regular sparse column-oriented" representation for mixed-effects models
View Intro.md

Regular sparse matrices

In previous versions of the lme4 package for R, the random-effects model matrix, Z, or its transpose, Zt, have been stored as compressed sparse column-oriented matrices, which is a general sparse matrix representation. As implemented in the Matrix package for R, an m by n dgCMatrix matrix with nnz non-zeros has three vector slots: p, which is the length n + 1 vector of column pointers, i, which is the length nnz vector of row indices, and x, which is the length