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
# see | |
# http://stackoverflow.com/questions/20203485/why-is-source-gist-function-in-r-devtools-package-not-working | |
covlm <- function(dv, ivs, n, cov) { | |
# Assumes lavaan package | |
# library(lavaan) | |
# dv: charcter vector of length 1 with name of outcome variable | |
# ivs: character vector of names of predictors | |
# n: numeric vector of length 1: sample size | |
# cov: covariance matrix where row and column names |
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
<script type="text/javascript" | |
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> | |
</script> | |
<script type="text/javascript">MathJax.Hub.Config({tex2jax: {processEscapes: true, | |
processEnvironments: false, inlineMath: [ ['$','$'] ], | |
displayMath: [ ['$$','$$'] ] }, | |
asciimath2jax: {delimiters: [ ['$','$'] ] }, | |
"HTML-CSS": {minScaleAdjust: 125 } }); | |
</script> |
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
This post examines the features of [R Markdown](http://www.rstudio.org/docs/authoring/using_markdown) | |
using [knitr](http://yihui.name/knitr/) in Rstudio 0.96. | |
This combination of tools provides an exciting improvement in usability for | |
[reproducible analysis](http://stats.stackexchange.com/a/15006/183). | |
Specifically, this post | |
(1) discusses getting started with R Markdown and `knitr` in Rstudio 0.96; | |
(2) provides a basic example of producing console output and plots using R Markdown; | |
(3) highlights several code chunk options such as caching and controlling how input and output is displayed; | |
(4) demonstrates use of standard Markdown notation as well as the extended features of formulas and tables; and | |
(5) discusses the implications of R Markdown. |
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
# Script for converting latitude and longitude coordinates (e.g., from Qualtrics) into country codes using R | |
# Assumes data set is called rcases | |
# country from coords | |
library(sp) | |
# install.packages("rworldmap") | |
library(rworldmap) | |
# The single argument to this function, points, is a data.frame in which: | |
# - column 1 contains the longitude in degrees |
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
# Function to write data.frame to xlsx spreadsheet | |
write_xlsx <- function(data, file, sheetname = "Sheet1", rowNames = TRUE, ...) { | |
require("openxlsx") | |
wb <- createWorkbook() | |
addWorksheet(wb, sheetname) | |
writeData(wb, sheetname, data, rowNames = rowNames, ...) | |
saveWorkbook(wb, file = file, overwrite = TRUE) | |
} | |
# Example |
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
EMAIL=youremail@gmail.com | |
SERVER=username@yourserver.com | |
mode=standard # e.g., quick, standard, publication | |
all: | |
make models mode=$(mode) | |
make ppc mode=$(mode) | |
make standard-figures mode=$(mode) | |
make yhat mode=$(mode) |
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
javascript:location %3D %27http://scholar.google.com/scholar%3Fq%3D%27%2Bescape(document.forms%5B0%5D.elements%5B%27q%27%5D.value)%3B |
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_csv_qualtrics <- function(file) { | |
# import a csv file exported from Qualtrics | |
# Qualtrics places variable labels in the second row. | |
# This function removes that second row and returns the data frame. | |
# taken from: | |
# http://lowlywonk.blogspot.com.au/2011/05/r-code-to-remove-second-line-of.html | |
DF <- read.csv(file, skip=2, header=FALSE) | |
DF2 <- read.csv(file) | |
names(DF) <- names(DF2) | |
DF |
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
freqtable <- function(X) { | |
# X: data.frame of typically survey items | |
# Code assumes that all items are numeric (i.e., 1 to 5, rather than text labels) | |
unique_values <- unique(unlist(sapply(X, unique))) | |
su <- sort(unique_values) | |
freq <- t(sapply(X, function(Z) table(factor(Z, su)))) | |
prop <- t(sapply(X, function(Z) prop.table(table(factor(Z, su))))) | |
list(freq = freq, prop = prop) | |
} |
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
#http://jeromyanglim.blogspot.com.au/2012/05/how-to-plot-three-categorical-variables.html | |
library(ggplot2) | |
# Create some data | |
set.seed(4444) | |
Data <- expand.grid(group=c("Apples", "Bananas", "Carrots", "Durians", "Eggplants"), | |
year=c("2000", "2001", "2002"), | |
quality=c("Grade A", "Grade B", "Grade C", "Grade D", "Grade E")) | |
Group.Weight <- data.frame( | |
group=c("Apples", "Bananas", "Carrots", "Durians", "Eggplants"), |
NewerOlder