I am trying to get R to run the same function/code but for a dataset. I have it set up with 50 questions, yes(1)/no(0) answers and about 500 different responses for each of the 50 questions. The 500 responses are identified as male(1) or female(0). At the end of each person is their "Score", how many yes (1) answers they had. I have run a plot on R before but I want to run this plot for all 50 questions without having to change the code every time, and running the code 50 times. The code that I am using is below. dataset is the excel file that I made with gender, Q001-Q052 points, and score as columns and then 500 rows down with their responses and gender.
>LRmod01<-glm(dataset$'Q001points'~dataset$Score+dataset$Gender,data=dataset,family=binomial(link="logit")
>summary(LRmod01)
>LRodds01<-cbind("Odds-Ratio"=exp(LRmod01$coefficients),exp(confint(LRmod01)))
>View(LRodds01)
>LR.pred.probs01<-predict(LRmod01,type="response")
>View(LR.pred.probs01)
>scatter.smooth(dataset$Score,logit(LR.pred.probs01))
>scatter.smooth(dataset$Score,(LR.pred.probs01),main="Logistic Regression for Question 001", xlab="Number of Questions Yes on Exam", ylab="Log Odds for Question 001",ylim=range(0,1,na.rm=TRUE)
I want to do this coding above but for all 50 questions. Right now it only runs for Q01 and I know that it only will because of the coding "dataset$'Q001points'" part. Should I use a loop for this and if so how?