Skip to content

Instantly share code, notes, and snippets.

@leoniedu
Created April 26, 2010 21:42
Show Gist options
  • Save leoniedu/379968 to your computer and use it in GitHub Desktop.
Save leoniedu/379968 to your computer and use it in GitHub Desktop.
set.seed(20091975)
## number of stimuli
J <- 6
## draw the stimuli. hold them fixed
x <- sort(runif(J))
sim <- function(
N=100, ## number of individuals
intercept=0,
slope=1,
sigma=.1
) {
a <- rep(intercept,N)
b <- rep(slope,N)
y <- a+b%*%t(x)+matrix(rnorm(N*J,0,sigma), ncol=J)
## constrain
y[y<0] <- 0
y[y>1] <- 1
## calculate bias
bias <- x-predict(lm(x~apply(y,2,mean)))
bias
}
res <- t(sapply(seq(-0.5,.5, .1), function(x) apply(replicate(100, sim(intercept=x)),1,mean)))
matplot(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment