fbpx

    How to Perform
    Binary Logistic
    Regression in R

    Looking for a Binary Logistic Regression in R? Doing it yourself is always cheaper, but it can also be a lot more time-consuming. If you’re not good at R programming, you can pay someone to do your R task for you.

    What is a Logistic Regression?

    With the logistic regression model, we describe the relationship between predictors that can be continuous, binary, categorical, and categorical dependent variables. For example, the dependent variable can be binary, and we predict whether something will happen or not. We estimate the probabilities of belonging to each category for a given set of predictors. Binary logistic regression implies that we have one dependent binary variable that takes the values 1 or 0 (e.g. 1 – yes, 0 – no).

    What is binary logistic regression used for?

    Logistic Regression is a classification algorithm that is used when we want to predict a categorical variable (Yes/No, Pass/Fail) based on a set of the independent variable(s). In the Logistic Regression model, the log of odds of the dependent variable is modeled as a linear combination of the independent variables.

    An Example Of Logistic Regression Analysis

    For example, a researcher wants to examine whether levels of stress, anxiety, and happiness predict success in an English language exam. So, we have one dependent variable – passed English language exam (1 – yes, 0 – no) and three independent variables – level of stress, anxiety, and happiness.

    Therefore, we test the following hypotheses:

    Null hypothesis: Levels of stress, anxiety, and happiness do not significantly predict the probability of passing the English language exam.

    Alternative hypothesis: Level of stress, anxiety, and happiness significantly predict the probability of passing the English language exam.

    R function to Compute Logistic Regression

    The code to run a Logistic Regression using R is as follows:

    glm (DV~ IV1 +IV2,…+IVx,  family=binomial, data = dataframe)

    DV: dependent variable (two-group categorical variable)

    IV: Independent variables

    Running Logistic Regression in Rstudio

    In this section, we will show you how to run the logistic regression using the r studio program and how to interpret the test results after we obtain the result of the test. In the first part, we present the r program code and function for the logistic regression analysis. Next, you will see the outputs as a result of running the r codes. In the last section, you can find the interpretation of the binary logistic regression in APA format.

    # LOAD DATA
    library(readxl)
    Data <- read_excel(“Data.xlsx“)
    # VIEW DATA
    View(Data)
    # NAME VARIABLES
    data <- Data
    anxiety <- data$anxiety
    stress <- data$stress
    happy <- data$happy
    english <- data$english

    # PERFORM LOGISTIC REGRESSION
    model <- glm(english ~ happy + stress + anxiety, data = data, family = binomial)
    summary(model)

    > model <- glm(english ~ happy + stress + anxiety, data = data, family = binomial)
    > summary(model)
    ## 
    ## Call:
    ## glm(formula = english ~ happy + stress + anxiety, family = binomial, 
    ##     data = data)
    ## 
    ## Deviance Residuals: 
    ##     Min       1Q   Median       3Q      Max  
    ## -1.5099  -1.0529  -0.8585   1.0861   1.5323  
    ## 
    ## Coefficients:
    ##              Estimate Std. Error z value Pr(>|z|)  
    ## (Intercept) -1.506139   1.581910  -0.952   0.3410  
    ## happy        0.139650   0.332618   0.420   0.6746  
    ## stress       0.177930   0.076332   2.331   0.0198 *
    ## anxiety     -0.004323   0.076120  -0.057   0.9547  
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## (Dispersion parameter for binomial family taken to be 1)
    ## 
    ##     Null deviance: 137.23  on 98  degrees of freedom
    ## Residual deviance: 131.39  on 95  degrees of freedom
    ## AIC: 139.39
    ## 
    ## Number of Fisher Scoring iterations: 4

    Reporting Logistic Regression in R

    Logistic regression was conducted to determine whether the level of stress, anxiety, and happiness predict the probability of passing the English language exam. The results indicate that only the level of stress is a significant positive predictor of the probability of passing the English language exam (p = 0.019). If the level of stress increases by 0.18 units, it means a 19% increase in the odds of passing the English language exam (assuming that all other variables remain fixed). Level of anxiety is a non-significant negative predictor of the probability of passing the English language exam (p = 0.955). Level of happiness is a non-significant positive predictor of the probability of passing the English language exam (p = 0.675).

    Are you in trouble with RStudio?

    GET HELP FROM US

    There is a lot of statistical software out there, but R is one of the most popular. If you’re a student who needs help with R Studio, there are a few different resources you can turn to. We prepared a page for R tutorial for Beginners. All contents can guide you through Step-by-step R data analysis tutorials and you can see Basic Statistical Analysis Using the R Statistical Package.

    The second option is that you can get help from us, we give R Studio help for students with their assignments, dissertation, or research. Doing it yourself is always cheaper, but it can also be a lot more time-consuming. If you’re not the best at SPSS, then this might not be a good idea. It can take days just to figure out how to do some of the easier things in SPSS. So paying someone to do your R task will save you a ton of time and make your life a lot easier.

    The procedure of the R help service at OnlineSPSS.com is fairly simple. There are three easy-to-follow steps.

    1. Click and Get a FREE Quote
    2. Make the Payment
    3. Get the Solution

    Our purpose is to provide quick, reliable, and understandable information about Rstudio data analysis to our clients.

    Open chat
    1
    Need Data Analysis Help ?
    Hello,
    How may I help you?