x1 <- rnorm(100,5,sd=2)
x2 <- rnorm(200,15,3)
x3 <- c(x1,x2)
## calculate the density function
den_x <- density(x3)]
## this can be plotted:
plot(den_x)
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
# by Andrew MacDonald Nov 2011 | |
## please add your own tips and tricks! | |
## the idea here is to demonstrate how for loops are used | |
## and then immediately demonstrate how they can be avoided. | |
## we'll begin by creating a fake dataset. | |
## This experiment is a 3x3 factorial with 2 replicates of each treatment combination. | |
## The scientist applied nitrogen and phosphorous to the soil | |
## then she measured two responses: plant growth and seed production. |
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 simulation of detecting effect size on gall parasitisim rates | |
## and occupancy. | |
## basically ask: how many larvae are in each gall (poisson) | |
## how many samples do you need to see the difference? | |
## | |
#first, a homemade function for the Zero-Inflated Negative Binomial distribution | |
rzinbinom <- function(n,mu,size,zprob){ | |
ifelse(runif(n)<zprob,0,rnbinom(n,mu=mu,size=size)) | |
} |
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
## simulation of experiment | |
## to test patterns of randomization | |
## first set up the relationships | |
## volume is a uniform variable | |
n.mathoms <- 30 |
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
######### These are my attempts to incorporate McCann's models into R to help me interpret these food web models ###################### | |
library(deSolve) | |
### Section 2.2.5 | |
# parameters and state variables for the R-M model | |
r <- 1.0 # per capita rate of increase in resource | |
K <- 2.0 | |
e <- 0.7 | |
Ro <- 0.5 |
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
## file-scan.r | |
## Function to find a pattern in files with user-defined extension (.r by default) | |
## Returns file name and approximate row matches if positive. | |
## ------------------------------------------------------- | |
## Author: Laura Tremblay-Boyer ([email protected]) | |
## Written on: March 26, 2013 | |
## Time-stamp: <2013-03-26 16:19:28 Laura> | |
file.scan <- function(pattern, dir=getwd(), fpattern=NA, ftype=".r") { |
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(lme4) | |
library(ggplot2) | |
#create some levels | |
levs <- as.factor(c("l1","l2","l3","l4","l5")) | |
#set the factor means | |
f_means <- c(6,16,2,10,13) | |
# set individual as a factor |
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
getmatch <<- function(x,str2match,...) { | |
unlist(regmatches(x,regexpr(str2match,x,...))) } |
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
eps <- function(file, onefile=FALSE, width=5.5, height = 5.5, horizontal=FALSE,paper="special", ...){ | |
postscript(file=file,width=width,height=height,onefile=onefile,horizontal=horizontal,paper=paper,title=file,...) | |
par(bty='l') | |
} |
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
## make a fake data frame | |
test <- data.frame(foo=gl(n=3,k=2,labels=c("low","med","high")),bar=rep(letters[1:2],3),zoop=runif(6)) | |
## these are all factors | |
str(test) | |
## I want them to be characters, not factors, but I am too lazy to run as.character on every categorical factor | |
library(plyr) | |
test_char <- catcolwise(as.character)(test) |
OlderNewer