Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to do Logistic regression in R language

Shulou Source: shulou.com Published: 2022-06-01 22:05:31 10月02日 Update

How to do Logistic regression in R language? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Application scenario of Logistic regression

Logistic regression is a very common tool when the dependent variable is a binary result variable and the independent variable includes data of continuous type and category type. For example, the extramarital affair data "Fair's Affairs" is used in today's example. The dependent variable is whether there have been extramarital affairs, there are 8 independent variables, which are

Sex, age, marriage age, whether there is a child's religious belief (5 points, 1 for opposition, 5 for very belief), education, occupation (reverse numbered Gordon 7 categories) what does this mean? ) self-rating of marriage

The dependent variable y is the number of derailments, which is converted to binary type. The number of derailments is greater than or equal to 1, and the assignment is 1, on the contrary, the assignment is 0.

Let's start the actual operation.

This dataset comes from the R language package AER. If you want to use this dataset, you need to install this package first.

Install.packages ("AER")

Then use the data () function to get the dataset

Data (Affairs,package = "AER")

Then you can see the following in the window of the environment

This dataset has a total of 601 observations and a total of 9 variables

The next step is to convert the variable y times of derailment to binary df.

Tags: Variables results data models next functions languages dependent variables extramarital affairs probabilities times problems happiness marriage education gender more degree occupation independent variables Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Docker MariaDB Shulou Technology Linux