Skip to content

Instantly share code, notes, and snippets.

@carbocation
Last active September 10, 2017 17:31
Show Gist options
  • Save carbocation/cf772a9437c6ce9e039d55e378be60f8 to your computer and use it in GitHub Desktop.
Save carbocation/cf772a9437c6ce9e039d55e378be60f8 to your computer and use it in GitHub Desktop.
Monte Carlo simulation to compare two vectors, one of which has no variance
library(MonteCarlo)
df <- data.frame(x=c(2.2, 2.2, 2.2, 2.2, 2.2), y=c(2.2, 1.2, 1.3, 2.4, 2.6))
df$trend <- seq(1,length(df$x))
pv <- function(noparams) {
return(list("p.value"=cor(jitter(df$x), df$y)))
}
param_list <- list("noparams"=c(0))
MC_result<-MonteCarlo(func=pv, nrep=100000, param_list=param_list)
mean(MC_result$results$p.value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment