This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dfm <- data.frame(y = c(30, 43, 36, 33, 50, 45, 40) + | |
scale(rnorm(7, 2, 5), scale = FALSE), x = 1:7) | |
dalt <- data.frame(x = seq(1, 7, length.out = 100)) | |
m <- lapply(1:6, function(i) {lm(y ~ poly(x = x, degree = i), data = dfm)}) | |
pdf(file = "tmp.pdf", height = 11, width = 8.5, onefile = TRUE) | |
par(mfrow = c(3, 2)) | |
for(i in as.numeric(1:6)) { | |
plot(y ~ x, data = dfm, main = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bsim <- function(reps = 10^2, groups = 200, L1k = 6, L2k = 3, seed = 10) { | |
stopifnot(all.equal(L1k %% L2k, 0L)) | |
f <- function(x) { | |
mdiff <- min(x, na.rm = TRUE) - 0 | |
(x - mdiff)/(max(x, na.rm = TRUE) - mdiff) | |
} | |
N <- reps * groups |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## In the end, what is the twelth column of 'dat', a, and b? | |
## why does the local() not matter in thirteen? | |
a <- 10 | |
b <- 10 | |
dat <- local( | |
data.frame( | |
first = b, | |
second = a <- 0 -> b, | |
third = a <- rnorm(10, mean = a), | |
fourth = a / 2, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import generics | |
# (cheap version of importFrom() in a package) | |
fixef <- nlme:::fixef | |
ranef <- nlme:::ranef | |
# define generic prediction function | |
# but using my functions/methods | |
predict2 <- function (object, ...) { | |
UseMethod("predict2") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Interactive Graph Example | |
========================= | |
Function to do the work. Aside from the packages, to run this, just load the knitr package, and then knit2html("graph.rmd"). | |
```{r} | |
longplot <- function(dat, k, xlab, ylab, seed=4324, miter = 20) { | |
require(EMCluster) | |
require(mice) | |
require(reshape2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [[Rcpp::depends(RcppParallel)]] | |
// [[Rcpp::depends(RcppEigen)]] | |
#include <Rcpp.h> | |
#include <RcppEigen.h> | |
#include <RcppParallel.h> | |
using namespace std; | |
using namespace Rcpp; | |
using namespace RcppParallel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set.seed(1234) | |
dmat <- cbind(1, matrix(rnorm(1000 * 50), ncol = 50)) | |
beta <- matrix(c(2, runif(50))) | |
yvec <- as.vector(dmat %*% beta + rnorm(1000, sd = 3)) | |
dall <- cbind(y = yvec, as.data.frame(dmat[,-1])) | |
myindex <- matrix(sample(0:(1000 - 1), 1000 * 500, TRUE), ncol = 500) | |
library(Rcpp) | |
library(RcppEigen) | |
library(RcppParallel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USEVARIABLES = | |
FAM_SUPT ISEL_ALL | |
ECEA6 PIEA17 SEEA8 | |
sash_langnew SASH_SOC | |
screen | |
! covariates | |
HCE2 MHEA26 | |
AGE US_BORN | |
CENTER2 | |
CENTER3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(brms) | |
library(bayestestR) | |
#### Simulate some data #### | |
nID <- 100 ## number of people | |
k <- 4 ## number of observations per person | |
## make it reproducible | |
set.seed(1234) |