create a logistic regression on four parameters in r

Here's an example of how to create a logistic regression on four parameters using the glm function in R:

main.r
# load data
data <- read.csv("mydata.csv")

# create logistic regression model
model <- glm(response_variable ~ predictor1 + predictor2 + predictor3 + predictor4, data = data, family = "binomial")

# summary of model
summary(model)

# make predictions on new data
new_data <- data.frame(predictor1 = c(1, 2, 3), predictor2 = c(4, 5, 6), predictor3 = c(7, 8, 9), predictor4 = c(10, 11, 12))
predict(model, new_data, type = "response")
434 chars
13 lines

In this example, mydata.csv is the name of the file containing the data. The glm function is used to fit a logistic regression model to the data, with the response variable response_variable and four predictor variables predictor1, predictor2, predictor3, and predictor4. The family argument is set to "binomial" to specify that a logistic regression is desired.

The summary function is used to obtain a summary of the model, including the coefficients and p-values.

Finally, the predict function is used to make predictions on new data. The new_data data frame contains three rows of predictor variable values. The type argument is set to "response" to obtain predicted probabilities of the response variable being "true".

gistlibby LogSnag