Created
April 26, 2010 21:42
-
-
Save leoniedu/379968 to your computer and use it in GitHub Desktop.
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
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