Question: By using R: logit
By using R:
logit <- function(z){ # can this take in any z? log(z/(1-z)) } ilogit <- function(z){ # what about this one? exp(z)/(1+exp(z)) } sim.logistic <- function(x, beta.0, beta, bind=FALSE) { linear.parts <- beta.0+(x%*%beta) y <- rbinom(nrow(x), size=1, prob=ilogit(linear.parts)) if (bind) { return(cbind(x,y)) } else { return(y) } }
1. Modify these functions in the following ways: so that the logit and ilogit functions check that the arguments satisfy any necessary conditions. so that sim.logistic doesnt require x as an input, rather it generates x within the function. Each entry of the x matrix should be normally distributed with mean zero and variance 1. so that sim.logistic takes n (the number of observations) as an input so that beta can be a vector of any length more than 1 so that sim.logistic returns a data frame (always) of y and x so that sim.logistic checks that all the arguments satisfy any necessary conditions.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
