Skip to content

Instantly share code, notes, and snippets.

@sc268
Created June 20, 2014 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sc268/9b096c7b085b1c78e7ce to your computer and use it in GitHub Desktop.
Save sc268/9b096c7b085b1c78e7ce to your computer and use it in GitHub Desktop.
synthetic data for logistic regression
# --- 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