Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Step by step procedure on how to run nested logistic regression in R

Tags:

r

Please provide me with detailed (as possible) steps on how to do nested logistic regression in R. I'm new to R so it would help me a lot if i can get a detailed answer.

We tested how fisher's decision to exit the fishery is affected by different socioeconomic factors. Dependent variable: 0 - stay; 1 - exit Predictors: Age (continuous); Education (categorical); number of children (continuous), etc.

Our respondents were from different towns. A reviewer of our paper instructed us to account for the town where the respondent comes from by using nested logistic regression.

Your help is very much appreciated. Many thanks.

like image 865
Richard Muallil Avatar asked May 06 '11 02:05

Richard Muallil


People also ask

How do you implement logistic regression in R?

Logistic regression is implemented in R using glm() by training the model using features or variables in the dataset. wt influences dependent variables positively and one unit increase in wt increases the log of odds for vs =1 by 1.44.

How do you do multilevel logistic regression in R?

To fit a multilevel logistic regression model in R, you can use the glmer function and specify family = binomial("logit"). Documentation is available here: https://www.rdocumentation.org/packages/lme4/versions/1.1-21/topics/glmer.

What is nested logistic regression?

A nested logistical regression (nested logit, for short) is a statistical method for finding a best-fit line when the the outcome variable $Y$ is a binary variable, taking values of 0 or 1. Logit regressions, in general, follow a logistical distribution and restrict predicted probabilities between 0 and 1.


1 Answers

install.packages("mlogit")    
library(mlogit)

my.data <- YOUR.DATA    

nested.logit <- mlogit(stay.exit~ age + education + children , my.data,
shape='long', alt.var='town.list', nests=list(town.list))

See page 19 of the mlogit manual for examples of nested logit model calls. You'll have to review the documentation yourself to ensure you're getting at what you need in terms of options. http://cran.r-project.org/web/packages/mlogit/mlogit.pdf

Segue: I usually like to have a peek at all models by town.list before I look at nested models:

Note: if your categorical variables are not factored you'll have to surround them with as.factor(variable) in your model formula

# Show a little love for plyr
library(plyr)

## RNG
set.seed(123454321)

## Create a list object to store your models
my.models <- list()

## import your data
my.data <- YOUR.DATA

## Create a loop that runs by the list of towns
for(x in 1:length(mydata$town.list) {
## subset data in each step by the town
dat <- subset(my.data, town == town.list[x])
## Save the model to it's own place in the list, identified by town
my.models[[town.list[x]]] <- glm(formula = stay.exit ~ age + education + children, 
family = binomial(link = "logit"), 
data=dat)
}

## View summaries for all models
llply(my.models, summary)

## Access specific models
my.models$<TOWN NAME>
like image 95
Brandon Bertelsen Avatar answered Oct 13 '22 00:10

Brandon Bertelsen