Created
June 20, 2014 16:40
-
-
Save sc268/9b096c7b085b1c78e7ce to your computer and use it in GitHub Desktop.
synthetic data for logistic regression
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
# --- synthetic data for logistic regression # | |
# Sean Chang 2014 | |
# sean.chang@duke.edu | |
# sample size | |
n = 1e4 | |
x <- rnorm(n, -1, 0.5) + rnorm(n,0.5,0.5) | |
# transfer x to [0,1] | |
x = exp(x)/(1+exp(x)) | |
hist(x) | |
mean(x) | |
# generate positive coefficients | |
beta = 1 + rnorm(n, 0, 0.375) #noise | |
# generate y | |
prob = exp(x*beta)/(1+exp(x*beta)) | |
plot(x, prob) | |
y = rbinom(n, 1, prob) | |
# save file | |
#save(x, y, file="/v_share/simulated.RData") | |
df = data.frame(x,y) | |
write.table(df,file="/v_share/simulated.csv", sep = ",") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment