I have a code where I am performing a zero inflated model on excel spreadsheet named by the zip code. I have 174 such sheets in my directory. I need to run the code on each spreadsheet. How can do all this at once?
This is my code:
library(pscl)
library(sandwich)
library(lmtest)
library(MASS)
library(readxl)
library(pscl)
formula <- Street ~ BackUp+Catch+Manhole+PRCP
inputData <- read_xlsx("10028.xlsx")
model.zi <- zeroinfl(formula = formula,
dist = "negbin",
data = inputData)
summary(model.zi)
library(car)
Anova(model.zi,
type="II",
test="Chisq")
library(rcompanion)
nagelkerke(model.zi)
Anova(model.zi)$'Pr(>Chisq)'
Rsquared10028 <- nagelkerke(model.zi)$'Pseudo.R.squared'
PValue10028 <- Anova(model.zi)$'Pr(>Chisq)'
write.csv(Rsquared10028,"C:/Desktop/Rsquared10028.csv", row.names = FALSE)
write.csv(PValue10028,"C:/Desktop/PValue10028.csv", row.names = FALSE)
I'd appreciate any help. I am not sure how to add an excel file, so I added an image of the data just to show the format.