Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi. it\'s regression R-code problem. And the data i\'am using is contingency tab

ID: 3324966 • Letter: H

Question

Hi. it's regression R-code problem.

And the data i'am using is contingency table.

So, here i want to do a logistic regression.

The R-code below is my data. please help me with this.

##########################################################

age = rep(c("20~24","25~29","30~34","35,39","40~44","45~49","50~54","55~59","60~64"),4)
val = c(9,23,54,121,169,269,404,406,372,7,9,19,48,54,88,117,152,106,95,105,177,257,273,324,245,225,132,1841,1654,1863,2357,1778,1712,1324,967,526)
bre = c(rep("ybrl",18),rep("nbrl",18))
asthma = rep(c(rep("y",9),rep("n",9)),2)

m.table <- xtabs(val ~ age + bre + asthma)
m.data <- as.data.frame.table(m.table)
m.data

Explanation / Answer

I am updating your code.I assume that you want to predict whether a person has asthma or not.Having asthma is denoted by 1(or "y") and not having asthma is denoted by 0(or "n"). We transfrom the frequency data into raw data. We denote age- group by mid values of each class.

age = rep(c("20~24","25~29","30~34","35,39","40~44","45~49","50~54","55~59","60~64"),4)
val = c(9,23,54,121,169,269,404,406,372,7,9,19,48,54,88,117,152,106,95,105,177,257,273,324,245,225,132,1841,1654,1863,2357,1778,1712,1324,967,526)
bre = c(rep("ybrl",18),rep("nbrl",18))
asthma = rep(c(rep("y",9),rep("n",9)),2)

m.table <- xtabs(val ~ age + bre + asthma)
m.data <- as.data.frame.table(m.table)
m.data
response=rep(m.data$asthma,m.data$Freq)
breathing=rep(m.data$bre,m.data$Freq)
ages=rep(seq(22,62,by=5),4)
age=rep(ages,m.data$Freq)
logistic=glm(response~age+breathing,family="binomial")
summary(logistic)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote