Here's an example of how to create a logistic regression on four parameters using the glm
function in R:
main.r434 chars13 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