library(variancePartition)
# load calcVarPart() for glm fit# must load variancePartition first
source("https://raw.githubusercontent.com/GabrielHoffman/misc_vp/master/calcVarPart.R")
# geta dataset with two categoriesdata=iris[iris$Species%in% c("virginica", "versicolor"),]
data$Category= sample(c("A", "B", "C", "D"), nrow(data), replace=TRUE)
# fit logistic regressionform=Species~Petal.Length+Categoryfit.glm= glm(form, data, family=binomial())
# Run variance partitioning
calcVarPart(fit.glm)
# Fit Gaussian model forwith both functions#-----------------------------------------# Show values are the sameform= as.numeric(Species) ~Petal.Length+Categoryfit.lm= lm(form, data)
form= as.numeric(Species) ~Petal.Length+Categoryfit.glm= glm(form, data, family=gaussian())
calcVarPart(fit.lm)
calcVarPart(fit.glm)