Last active
December 17, 2015 04:29
-
-
Save mwormleonhard/5550942 to your computer and use it in GitHub Desktop.
test
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
ln2i <-function(num_iters) { ## Iterative version | |
i <- 2 | |
s <- 1 | |
while (i < num_iters) { | |
ifelse(i%%2==0, s <- s - 1/i, s <- s + 1/i) | |
i <- i + 1 | |
} | |
return(s) | |
} | |
ln2r <- function(num_iters) { # Recursive version | |
if (num_iters==1) | |
return(1) | |
if (num_iters%%2==0) | |
return(ln2(num_iters-1) - 1/num_iters) | |
return(ln2(num_iters-1) + 1/num_iters) | |
} | |
ln2(10) |
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(zoo) | |
#pdf("meanandmedian.pdf", paper="a4") | |
#setwd('c:/Users/mwl/Dropbox/R') | |
x<-c(1:200) | |
y<-40-0.1*x+rlnorm(x,0,2) | |
plot(x,y, main="40-0.1*x+rlnorm(x,0,2)\nRAW") | |
abline(40,-.1) | |
ymean<-rollmean(y,21, na.pad=TRUE) | |
ymedian<-rollmedian(y,21, na.pad=TRUE) | |
plot(x,ymean,main="40-0.1*x+rlnorm(x,0,2)\nRolling mean, 21 observations") | |
abline(40,-.1) | |
plot(x,ymedian,main="40-0.1*x+rlnorm(x,0,2)\nRolling median, 21 observations") | |
abline(40,-.1) | |
#dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment