Question Details
[answered] library(car) library(MASS) library(VGAM) library(effects) l
The following data set contains a dichotomous response variable, along?with other variables that can be treated as explanatory variables:?
library(car)
library(MASS)
library(VGAM)
library(effects)
library(nnet)
data(Chile)
C=Chile[complete.cases(Chile),]
C=C[C$vote!="A",]
C=C[C$vote!="U",]
vote_ind = 1*(C$vote=="Y")
m=lm(vote_ind~C$statusquo)
plot(C$statusquo, jitter(vote_ind, .2))
abline(m, col="red")
x=seq(-5,5,length=10001)
plot(x, pnorm(x), type="l")
lines(x, plogis(x, scale=sqrt(3)/(pi)), col="red")
data(Mroz)
m=glm(lfp~., data=Mroz, family=binomial(link=logit))
summary(m)
m2=glm(lfp~.-hc, data=Mroz, family=binomial(link=logit))
summary(m2)
m3=glm(lfp~.-hc-k618, data=Mroz, family=binomial(link=logit))
summary(m3)
anova(m2,m, test="Chisq") m0=glm(lfp~1, data=Mroz, family=binomial(link=logit))
summary(m0)
# Section 14.2.1 Polytomous Logit Model
data(BEPS)
BEPS$vote=factor(BEPS$vote, levels=c("Liberal
Democrat","Labour","Conservative")) #Reorder the levels to be consistent with
the book
m1=multinom(vote~.+Europe*political.knowledge, data=BEPS) #Fit the model
summary(m1) #Contains the same information as Table 14.5
Anova(m1) #Table 14.6
plot(effect('Europe*political.knowledge',m1,xlevels=list(Europe=seq(1,11,length=
50),political.knowledge=0:3)), style="stacked",rug=FALSE,
colors=c("gold","red","blue")) #stacked effects plot
plot(effect('gender',m1), style="stacked",rug=FALSE,
colors=c("gold","red","blue")) #stacked effects plot
plot(effect('age*economic.cond.national*gender',m1), style="stacked",rug=FALSE,
colors=c("gold","red","blue")) #stacked effects plot predict(m1, newdata=BEPS[1,2:10], type="probs") m2 = update(m1,.~.-gender) #Removing Gender from the Model
summary(m2)
1-pchisq(m2$deviance-m1$deviance,df=(m1$edf-m2$edf)) #testing whether the full
model m is significant improvement over the reduced model m2, it's not.
Anova(m2)
anova(m2,m1)
plot(effect('Europe*political.knowledge',m2,xlevels=list(Europe=seq(1,11,length=
50),political.knowledge=0:3)), style="stacked",rug=FALSE,
colors=c("gold","red","blue"))
m3=update(m2,.~.-economic.cond.household)
summary(m3)
1-pchisq(m3$deviance-m2$deviance,df=(m2$edf-m3$edf)) #testing whether the full
model m is significant improvement over the reduced model m2, it's not.
Anova(m3)
anova(m3,m2)
plot(effect('Europe*political.knowledge',m3,xlevels=list(Europe=seq(1,11,length=
50),political.knowledge=0:3)), style="stacked",rug=FALSE,
colors=c("gold","red","blue"))
plot(effect('Europe*political.knowledge',m3,xlevels=list(Europe=seq(1,11,length=
50),political.knowledge=0:3)),rug=FALSE) #same plot but 'unstacked' so you get
each probability curve seperately, with confidence bounds.
# Section 14.2.2 Nested Dichotomies
BEPS$vote.lab=with(BEPS, recode(vote, "'Labour' = 'yes'; else = 'no'"))
BEPS$vote.con=with(BEPS, recode(vote, "'Conservative' = 'yes'; 'Liberal
Democrat' = 'no'; 'Labour' = NA"))
m.lab=glm(vote.lab~age+economic.cond.national+economic.cond.household+Blair+Hagu
e+Kennedy+Europe+political.knowledge+gender+Europe*political.knowledge,
data=BEPS, family=binomial(link=logit))
m.con=glm(vote.con~age+economic.cond.national+economic.cond.household+Blair+Hagu
e+Kennedy+Europe+political.knowledge+gender+Europe*political.knowledge,
data=BEPS, family=binomial(link=logit))
predict(m.lab, newdata=BEPS[1,2:10], type="response")
predict(m.con, newdata=BEPS[1,2:10], type="response")
hel
# Section 14.2.3 Ordered Logit Model
data(WVS)
m1=polr(poverty~.+country*religion+country*degree+country*age, data=WVS,
method='logistic')
m2=vglm(poverty~.+country*religion+country*degree+country*age, data=WVS,
family=cumulative(parallel=TRUE)) #Section 14.3 Discrete Explanatory Variables
closeness=factor(rep(c("one.sided", "close"),c(3,3)),
levels=c("one.sided","close"))
preference=factor(rep(c("weak","medium",
"strong"),2),levels=c("weak","medium","strong"))
voted=c(91,121,64,214,284,201)
did.not.vote=c(39,49,24,87,76,25)
logit.turnout=log(voted/did.not.vote)
Campbell=data.frame(closeness,preference,voted,did.not.vote,logit=logit.turnout)
oldpar=par(mar=c(5.1,4.1,4.1,4.1))
with(Campbell, interaction.plot(preference, closeness, logit, type="b",
pch=c(1,16), cex=2, ylab="log(Voted/Did Not Vote)"))
probabilityAxis(side="right", at=seq(0.7, 0.875, by=0.025),
axis.title="Proportion(Voted)")
par(oldpar) m1=glm(cbind(voted,did.not.vote)~closeness*preference, data=Campbell,
family=binomial(link=logit))
m2=update(m1, ~.-closeness:preference)
summary(m1)
summary(m2)
anova(m2,m1)
Campbell.binary=data.frame(close=NULL, prefer=NULL, turn=NULL)
for (j in 1:6){
x1=with(Campbell, data.frame(close=closeness[j], prefer=preference[j],
vote=rep("did not vote", did.not.vote[j])))
x2=with(Campbell, data.frame(close=closeness[j], prefer=preference[j],
vote=rep("voted", voted[j])))
Campbell.binary=rbind(Campbell.binary, x1, x2)}
ftable(xtabs(~close+prefer+vote,data=Campbell.binary))
m1a=glm(vote~close*prefer, data=Campbell.binary, family=binomial(link=logit))
m2a=update(m1a, ~.-close:prefer)
anova(m2a, m1a)
Solution details:
Answered
QUALITY
Approved
ANSWER RATING
This question was answered on: Sep 18, 2020
Solution~0001013207.zip (25.37 KB)
This attachment is locked
We have a ready expert answer for this paper which you can use for in-depth understanding, research editing or paraphrasing. You can buy it or order for a fresh, original and plagiarism-free copy from our tutoring website www.aceyourhomework.com (Deadline assured. Flexible pricing. TurnItIn Report provided)

Pay using PayPal (No PayPal account Required) or your credit card . All your purchases are securely protected by .
About this Question
STATUSAnswered
QUALITYApproved
DATE ANSWEREDSep 18, 2020
EXPERTTutor
ANSWER RATING
GET INSTANT HELP/h4>
We have top-notch tutors who can do your essay/homework for you at a reasonable cost and then you can simply use that essay as a template to build your own arguments.
You can also use these solutions:
- As a reference for in-depth understanding of the subject.
- As a source of ideas / reasoning for your own research (if properly referenced)
- For editing and paraphrasing (check your institution's definition of plagiarism and recommended paraphrase).
NEW ASSIGNMENT HELP?
Order New Solution. Quick Turnaround
Click on the button below in order to Order for a New, Original and High-Quality Essay Solutions. New orders are original solutions and precise to your writing instruction requirements. Place a New Order using the button below.
WE GUARANTEE, THAT YOUR PAPER WILL BE WRITTEN FROM SCRATCH AND WITHIN YOUR SET DEADLINE.
