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
fun <- function(x, data) { | |
if (missing(data)) | |
data <- NULL | |
if (is.null(data)) | |
data <- sys.frame(sys.parent()) | |
mf <- match.call() | |
mf.x <- mf[[match("x", names(mf))]] | |
x <- eval(mf.x, data, enclos=sys.frame(sys.parent())) | |
temp <- x^2 + 5 | |
return(temp) |
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
ll <- function(mu, tau2, yi, vi, method="ML") { | |
k <- length(yi) | |
wi <- 1/(vi + tau2) | |
if (method == "ML") { | |
sum(dnorm(yi, mean=mu, sqrt(vi + tau2), log=TRUE)) | |
} else { | |
-1/2 * (k-1) * log(2*pi) + 1/2 * log(k) - 1/2 * sum(log(vi + tau2)) - 1/2 * log(sum(wi)) - 1/2 * sum(wi * (yi - mu)^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
rm(list=ls()) | |
library(metafor) | |
iters <- 1000 | |
### number of studies/effects | |
k <- 10 | |
### SD of the true effects |
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
rm(list=ls()) | |
library(metafor) | |
iters <- 1000 | |
### number of studies/effects | |
k <- 10 | |
### SD of the true effects |
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
devtools::install_github("wviechtb/metafor") | |
library(metafor) | |
rs <- seq(-1,1,length=1001) | |
ns <- c(seq(10, 100, 10), 150, 200, 300) | |
ys <- lapply(ns, function(n) metafor:::.dcor(rs, n, rho=0)) | |
plot(NA, xlim=range(rs), ylim=range(ys), xlab="Correlation", ylab="Density") | |
invisible(lapply(ys, function(y) lines(rs, y))) |
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
iters <- 1000 | |
ns <- iters - 500 | |
nl <- iters - ns + 1 | |
rmin <- 2.4 | |
rmax <- 4 | |
rn <- 5000 | |
x <- rep(0,iters) |
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
rmat <- function(x, n, upper=TRUE, simplify=TRUE, rtoz=FALSE, data) { | |
if (inherits(x, "formula")) { | |
options(na.action = "na.pass") | |
if (missing(data)) | |
stop("Must specify 'data' argument when 'x' is a formula.") | |
if (!is.data.frame(data)) |
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
message("A message") | |
warning("A warning") | |
stop("An error") | |
globalCallingHandlers( | |
message = function(c) { | |
style <- crayon::make_style("white") | |
c$message <- style(c$message) | |
message(c) | |
invokeRestart("muffleMessage") |
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
############################################################################ | |
R version 2.5.0 (2007-04-23) | |
Copyright (C) 2007 The R Foundation for Statistical Computing | |
ISBN 3-900051-07-0 | |
R is free software and comes with ABSOLUTELY NO WARRANTY. | |
You are welcome to redistribute it under certain conditions. | |
Type 'license()' or 'licence()' for distribution details. |
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
> ############################################################################ | |
> | |
> # A comparison of for-loops versus apply() and sapply() for 1) computing the | |
> # row means in a matrix and 2) for computing the means of all elements in a | |
> # list. For task 1), we can also examine the performance of rowMeans() as a | |
> # specialized / vectorized function and for task 2), we can also compare | |
> # sapply() with vapply() (note: vapply() was added in version R-2.12.0). Also, | |
> # for the for-loop, we can examine what the impact is of pre-allocating the | |
> # vector in which to store the results versus 'growing' the vector in each | |
> # iteration. |
OlderNewer