This file contains hidden or 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
# example of calculating K-medoids using the uncentered | |
# correlation metric as a measure of distance | |
# 0) load data | |
data(mtcars) | |
# 1) create a distance matrix using the "cosine of the angle" method (aka, uncentered correlation) |
This file contains hidden or 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
# =============================================================================== | |
# Name : centroid_perm | |
# Original author : Steven Worthington ([email protected]) | |
# Affiliation : IQSS, Harvard University | |
# Date (mm/dd/yyyy) : 06/14/2012 | |
# Version : v0.8 | |
# Aim : exact permutation test for group differences | |
# =============================================================================== | |
# Goal: |
This file contains hidden or 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
# ipak function: install and load multiple R packages. | |
# check to see if packages are installed. Install them if they are not, then load them into the R session. | |
ipak <- function(pkg){ | |
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])] | |
if (length(new.pkg)) | |
install.packages(new.pkg, dependencies = TRUE) | |
sapply(pkg, require, character.only = TRUE) | |
} |
This file contains hidden or 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
# example of how to concatenate lots of variables into a formula without typing them out | |
# example from the High School and Beyond data set | |
hsb_df <- read.table("http://www.ats.ucla.edu/stat/R/notes/hs0.csv", header = TRUE, sep = ",") | |
# create the formula using variables from columns 4:8 and 10:11 as predictors | |
hsb_form <- formula( paste(c("math ~ 1", colnames(hsb_df[, c(4:8, 10:11)])), collapse = " + ") ) | |
# fit the model | |
fit1 <- lm(hsb_form, data = hsb_df) |
This file contains hidden or 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(ggplot2) | |
library(plyr) | |
data(mpg) | |
# create a data frame with averages and standard deviations | |
hwy.means <- ddply(mpg, c("class", "year"), summarize, hwy.avg = mean(hwy), hwy.sd = sd(hwy)) | |
# barplot with values over bars | |
ggplot(hwy.means) + | |
geom_bar(aes(class, hwy.avg, fill = factor(year)), position = "dodge", colour = "black", size = 0.3) + |
NewerOlder