insight/0000755000176200001440000000000013615601156011723 5ustar liggesusersinsight/NAMESPACE0000644000176200001440000005456513615562325013165 0ustar liggesusers# Generated by roxygen2: do not edit by hand S3method(clean_names,character) S3method(clean_names,default) S3method(clean_parameters,BFBayesFactor) S3method(clean_parameters,blavaan) S3method(clean_parameters,brmsfit) S3method(clean_parameters,default) S3method(clean_parameters,lavaan) S3method(clean_parameters,stanmvreg) S3method(clean_parameters,stanreg) S3method(clean_parameters,wbgee) S3method(clean_parameters,wbm) S3method(find_algorithm,BBmm) S3method(find_algorithm,BBreg) S3method(find_algorithm,Gam) S3method(find_algorithm,LORgee) S3method(find_algorithm,MixMod) S3method(find_algorithm,bayesx) S3method(find_algorithm,bigglm) S3method(find_algorithm,biglm) S3method(find_algorithm,blavaan) S3method(find_algorithm,brmsfit) S3method(find_algorithm,crq) S3method(find_algorithm,default) S3method(find_algorithm,gam) S3method(find_algorithm,gamlss) S3method(find_algorithm,glimML) S3method(find_algorithm,glm) S3method(find_algorithm,glmmTMB) S3method(find_algorithm,glmrob) S3method(find_algorithm,lm) S3method(find_algorithm,lmRob) S3method(find_algorithm,lme) S3method(find_algorithm,lmrob) S3method(find_algorithm,logistf) S3method(find_algorithm,merMod) S3method(find_algorithm,mixed) S3method(find_algorithm,rlmerMod) S3method(find_algorithm,rq) S3method(find_algorithm,rqss) S3method(find_algorithm,speedglm) S3method(find_algorithm,speedlm) S3method(find_algorithm,stanreg) S3method(find_formula,BBmm) S3method(find_formula,BFBayesFactor) S3method(find_formula,DirichletRegModel) S3method(find_formula,LORgee) S3method(find_formula,MANOVA) S3method(find_formula,MCMCglmm) S3method(find_formula,MixMod) S3method(find_formula,RM) S3method(find_formula,aovlist) S3method(find_formula,bamlss) S3method(find_formula,brmsfit) S3method(find_formula,cgamm) S3method(find_formula,cglm) S3method(find_formula,clm2) S3method(find_formula,clmm) S3method(find_formula,clmm2) S3method(find_formula,coxme) S3method(find_formula,cpglmm) S3method(find_formula,data.frame) S3method(find_formula,default) S3method(find_formula,feglm) S3method(find_formula,feis) S3method(find_formula,felm) S3method(find_formula,fixest) S3method(find_formula,gam) S3method(find_formula,gamlss) S3method(find_formula,gamm) S3method(find_formula,gee) S3method(find_formula,glimML) S3method(find_formula,glmmTMB) S3method(find_formula,glmmadmb) S3method(find_formula,gls) S3method(find_formula,hurdle) S3method(find_formula,iv_robust) S3method(find_formula,ivreg) S3method(find_formula,lme) S3method(find_formula,merMod) S3method(find_formula,mixed) S3method(find_formula,mixor) S3method(find_formula,mmclogit) S3method(find_formula,nlmerMod) S3method(find_formula,plm) S3method(find_formula,rlmerMod) S3method(find_formula,stanmvreg) S3method(find_formula,stanreg) S3method(find_formula,tobit) S3method(find_formula,wbgee) S3method(find_formula,wbm) S3method(find_formula,zeroinfl) S3method(find_formula,zerotrunc) S3method(find_parameters,BBmm) S3method(find_parameters,BBreg) S3method(find_parameters,BFBayesFactor) S3method(find_parameters,DirichletRegModel) S3method(find_parameters,Gam) S3method(find_parameters,MCMCglmm) S3method(find_parameters,MixMod) S3method(find_parameters,aareg) S3method(find_parameters,aovlist) S3method(find_parameters,bayesx) S3method(find_parameters,betareg) S3method(find_parameters,blavaan) S3method(find_parameters,bracl) S3method(find_parameters,brmsfit) S3method(find_parameters,brmultinom) S3method(find_parameters,cgam) S3method(find_parameters,clm2) S3method(find_parameters,clmm2) S3method(find_parameters,coxme) S3method(find_parameters,cpglmm) S3method(find_parameters,crq) S3method(find_parameters,crqs) S3method(find_parameters,data.frame) S3method(find_parameters,default) S3method(find_parameters,flexsurvreg) S3method(find_parameters,gam) S3method(find_parameters,gamlss) S3method(find_parameters,gamm) S3method(find_parameters,gbm) S3method(find_parameters,glimML) S3method(find_parameters,glmmTMB) S3method(find_parameters,glmmadmb) S3method(find_parameters,glmx) S3method(find_parameters,hurdle) S3method(find_parameters,lavaan) S3method(find_parameters,lme) S3method(find_parameters,lrm) S3method(find_parameters,mcmc) S3method(find_parameters,merMod) S3method(find_parameters,mixed) S3method(find_parameters,mixor) S3method(find_parameters,mlm) S3method(find_parameters,multinom) S3method(find_parameters,nlmerMod) S3method(find_parameters,polr) S3method(find_parameters,rlmerMod) S3method(find_parameters,rma) S3method(find_parameters,rqss) S3method(find_parameters,sim) S3method(find_parameters,sim.merMod) S3method(find_parameters,stanmvreg) S3method(find_parameters,stanreg) S3method(find_parameters,vgam) S3method(find_parameters,wbgee) S3method(find_parameters,wbm) S3method(find_parameters,zeroinfl) S3method(find_parameters,zerotrunc) S3method(find_weights,brmsfit) S3method(find_weights,default) S3method(format_value,character) S3method(format_value,data.frame) S3method(format_value,double) S3method(format_value,factor) S3method(format_value,logical) S3method(format_value,numeric) S3method(get_data,BBmm) S3method(get_data,BFBayesFactor) S3method(get_data,DirichletRegModel) S3method(get_data,LORgee) S3method(get_data,MANOVA) S3method(get_data,MCMCglmm) S3method(get_data,MixMod) S3method(get_data,RM) S3method(get_data,aareg) S3method(get_data,bigglm) S3method(get_data,biglm) S3method(get_data,blavaan) S3method(get_data,bracl) S3method(get_data,brmsfit) S3method(get_data,clm2) S3method(get_data,clmm) S3method(get_data,clmm2) S3method(get_data,complmrob) S3method(get_data,cpglmm) S3method(get_data,data.frame) S3method(get_data,default) S3method(get_data,feglm) S3method(get_data,feis) S3method(get_data,felm) S3method(get_data,fixest) S3method(get_data,gamlss) S3method(get_data,gamm) S3method(get_data,gbm) S3method(get_data,gee) S3method(get_data,glimML) S3method(get_data,glmmTMB) S3method(get_data,glmmadmb) S3method(get_data,gls) S3method(get_data,gmnl) S3method(get_data,hurdle) S3method(get_data,iv_robust) S3method(get_data,ivreg) S3method(get_data,lavaan) S3method(get_data,lme) S3method(get_data,merMod) S3method(get_data,mixed) S3method(get_data,mixor) S3method(get_data,nlrq) S3method(get_data,plm) S3method(get_data,rlmerMod) S3method(get_data,rma) S3method(get_data,rqss) S3method(get_data,stanmvreg) S3method(get_data,stanreg) S3method(get_data,survfit) S3method(get_data,tobit) S3method(get_data,vgam) S3method(get_data,vglm) S3method(get_data,wbgee) S3method(get_data,wbm) S3method(get_data,zeroinfl) S3method(get_data,zerotrunc) S3method(get_parameters,BBmm) S3method(get_parameters,BBreg) S3method(get_parameters,BFBayesFactor) S3method(get_parameters,DirichletRegModel) S3method(get_parameters,Gam) S3method(get_parameters,MCMCglmm) S3method(get_parameters,MixMod) S3method(get_parameters,aareg) S3method(get_parameters,aov) S3method(get_parameters,aovlist) S3method(get_parameters,bayesx) S3method(get_parameters,betareg) S3method(get_parameters,blavaan) S3method(get_parameters,bracl) S3method(get_parameters,brmsfit) S3method(get_parameters,brmultinom) S3method(get_parameters,cgam) S3method(get_parameters,clm2) S3method(get_parameters,clmm2) S3method(get_parameters,coxme) S3method(get_parameters,cpglmm) S3method(get_parameters,crq) S3method(get_parameters,crqs) S3method(get_parameters,data.frame) S3method(get_parameters,default) S3method(get_parameters,flexsurvreg) S3method(get_parameters,gam) S3method(get_parameters,gamlss) S3method(get_parameters,gamm) S3method(get_parameters,gbm) S3method(get_parameters,glimML) S3method(get_parameters,glmmTMB) S3method(get_parameters,glmmadmb) S3method(get_parameters,glmx) S3method(get_parameters,hurdle) S3method(get_parameters,lavaan) S3method(get_parameters,lme) S3method(get_parameters,lrm) S3method(get_parameters,mcmc) S3method(get_parameters,merMod) S3method(get_parameters,mixed) S3method(get_parameters,mixor) S3method(get_parameters,mlm) S3method(get_parameters,multinom) S3method(get_parameters,nlmerMod) S3method(get_parameters,polr) S3method(get_parameters,rlmerMod) S3method(get_parameters,rma) S3method(get_parameters,rqss) S3method(get_parameters,sim) S3method(get_parameters,sim.merMod) S3method(get_parameters,stanmvreg) S3method(get_parameters,stanreg) S3method(get_parameters,vgam) S3method(get_parameters,wbgee) S3method(get_parameters,wbm) S3method(get_parameters,zeroinfl) S3method(get_parameters,zerotrunc) S3method(get_priors,BFBayesFactor) S3method(get_priors,blavaan) S3method(get_priors,brmsfit) S3method(get_priors,stanmvreg) S3method(get_priors,stanreg) S3method(get_statistic,DirichletRegModel) S3method(get_statistic,Gam) S3method(get_statistic,LORgee) S3method(get_statistic,MANOVA) S3method(get_statistic,MixMod) S3method(get_statistic,RM) S3method(get_statistic,aareg) S3method(get_statistic,betareg) S3method(get_statistic,bigglm) S3method(get_statistic,biglm) S3method(get_statistic,bracl) S3method(get_statistic,brmultinom) S3method(get_statistic,censReg) S3method(get_statistic,cgam) S3method(get_statistic,clm2) S3method(get_statistic,clmm2) S3method(get_statistic,complmrob) S3method(get_statistic,coxme) S3method(get_statistic,coxph) S3method(get_statistic,cpglm) S3method(get_statistic,cpglmm) S3method(get_statistic,crch) S3method(get_statistic,crq) S3method(get_statistic,default) S3method(get_statistic,feis) S3method(get_statistic,fixest) S3method(get_statistic,flexsurvreg) S3method(get_statistic,gam) S3method(get_statistic,gamlss) S3method(get_statistic,gamm) S3method(get_statistic,gee) S3method(get_statistic,geeglm) S3method(get_statistic,glimML) S3method(get_statistic,glmmTMB) S3method(get_statistic,glmmadmb) S3method(get_statistic,glmx) S3method(get_statistic,hurdle) S3method(get_statistic,list) S3method(get_statistic,lm_robust) S3method(get_statistic,lme) S3method(get_statistic,logistf) S3method(get_statistic,lrm) S3method(get_statistic,maxLik) S3method(get_statistic,mixor) S3method(get_statistic,mlm) S3method(get_statistic,multinom) S3method(get_statistic,negbin) S3method(get_statistic,nlrq) S3method(get_statistic,ols) S3method(get_statistic,plm) S3method(get_statistic,psm) S3method(get_statistic,rma) S3method(get_statistic,rms) S3method(get_statistic,rq) S3method(get_statistic,rqss) S3method(get_statistic,survreg) S3method(get_statistic,svyglm.nb) S3method(get_statistic,svyglm.zip) S3method(get_statistic,tobit) S3method(get_statistic,truncreg) S3method(get_statistic,vgam) S3method(get_statistic,vglm) S3method(get_statistic,wbgee) S3method(get_statistic,wbm) S3method(get_statistic,zerocount) S3method(get_statistic,zeroinfl) S3method(get_varcov,BBmm) S3method(get_varcov,BBreg) S3method(get_varcov,DirichletRegModel) S3method(get_varcov,LORgee) S3method(get_varcov,MixMod) S3method(get_varcov,betareg) S3method(get_varcov,brmsfit) S3method(get_varcov,cglm) S3method(get_varcov,clm2) S3method(get_varcov,clmm2) S3method(get_varcov,cpglm) S3method(get_varcov,cpglmm) S3method(get_varcov,crq) S3method(get_varcov,default) S3method(get_varcov,feis) S3method(get_varcov,flexsurvreg) S3method(get_varcov,gamlss) S3method(get_varcov,gamm) S3method(get_varcov,gee) S3method(get_varcov,geeglm) S3method(get_varcov,glimML) S3method(get_varcov,glmRob) S3method(get_varcov,glmmTMB) S3method(get_varcov,glmx) S3method(get_varcov,hurdle) S3method(get_varcov,list) S3method(get_varcov,lmRob) S3method(get_varcov,maxLik) S3method(get_varcov,mixed) S3method(get_varcov,mixor) S3method(get_varcov,nlrq) S3method(get_varcov,rq) S3method(get_varcov,tobit) S3method(get_varcov,truncreg) S3method(get_varcov,vgam) S3method(get_varcov,vglm) S3method(get_varcov,zerocount) S3method(get_varcov,zeroinfl) S3method(get_variance,MixMod) S3method(get_variance,clmm) S3method(get_variance,cpglmm) S3method(get_variance,default) S3method(get_variance,glmmTMB) S3method(get_variance,glmmadmb) S3method(get_variance,lme) S3method(get_variance,merMod) S3method(get_variance,mixed) S3method(get_variance,rlmerMod) S3method(get_variance,stanreg) S3method(get_variance,wblm) S3method(get_variance,wbm) S3method(get_weights,brmsfit) S3method(get_weights,default) S3method(link_function,BBmm) S3method(link_function,BBreg) S3method(link_function,DirichletRegModel) S3method(link_function,LORgee) S3method(link_function,MANOVA) S3method(link_function,RM) S3method(link_function,aovlist) S3method(link_function,bamlss) S3method(link_function,bayesx) S3method(link_function,betareg) S3method(link_function,bigglm) S3method(link_function,biglm) S3method(link_function,brglm) S3method(link_function,brmsfit) S3method(link_function,censReg) S3method(link_function,cgam) S3method(link_function,cglm) S3method(link_function,clm) S3method(link_function,clm2) S3method(link_function,clmm) S3method(link_function,complmRob) S3method(link_function,coxme) S3method(link_function,coxph) S3method(link_function,cpglm) S3method(link_function,cpglmm) S3method(link_function,crch) S3method(link_function,crq) S3method(link_function,crqs) S3method(link_function,default) S3method(link_function,feglm) S3method(link_function,feis) S3method(link_function,felm) S3method(link_function,fixest) S3method(link_function,flexsurvreg) S3method(link_function,gam) S3method(link_function,gamlss) S3method(link_function,gamm) S3method(link_function,gbm) S3method(link_function,glimML) S3method(link_function,glm) S3method(link_function,glmmadmb) S3method(link_function,glmx) S3method(link_function,gls) S3method(link_function,gmnl) S3method(link_function,hurdle) S3method(link_function,iv_robust) S3method(link_function,ivreg) S3method(link_function,lm) S3method(link_function,lmRob) S3method(link_function,lm_robust) S3method(link_function,lme) S3method(link_function,lmrob) S3method(link_function,logistf) S3method(link_function,lrm) S3method(link_function,mixed) S3method(link_function,mixor) S3method(link_function,mlogit) S3method(link_function,multinom) S3method(link_function,plm) S3method(link_function,polr) S3method(link_function,psm) S3method(link_function,rq) S3method(link_function,rqss) S3method(link_function,speedglm) S3method(link_function,speedlm) S3method(link_function,stanmvreg) S3method(link_function,survfit) S3method(link_function,survreg) S3method(link_function,svyolr) S3method(link_function,tobit) S3method(link_function,truncreg) S3method(link_function,vgam) S3method(link_function,vglm) S3method(link_function,zeroinfl) S3method(link_function,zerotrunc) S3method(link_inverse,BBmm) S3method(link_inverse,BBreg) S3method(link_inverse,DirichletRegModel) S3method(link_inverse,LORgee) S3method(link_inverse,MANOVA) S3method(link_inverse,MCMCglmm) S3method(link_inverse,MixMod) S3method(link_inverse,RM) S3method(link_inverse,aovlist) S3method(link_inverse,bamlss) S3method(link_inverse,bayesx) S3method(link_inverse,betareg) S3method(link_inverse,bigglm) S3method(link_inverse,biglm) S3method(link_inverse,brmsfit) S3method(link_inverse,censReg) S3method(link_inverse,cgam) S3method(link_inverse,clm) S3method(link_inverse,clm2) S3method(link_inverse,clmm) S3method(link_inverse,complmrob) S3method(link_inverse,coxme) S3method(link_inverse,coxph) S3method(link_inverse,cpglm) S3method(link_inverse,cpglmm) S3method(link_inverse,crch) S3method(link_inverse,crq) S3method(link_inverse,crqs) S3method(link_inverse,default) S3method(link_inverse,feglm) S3method(link_inverse,feis) S3method(link_inverse,felm) S3method(link_inverse,fixest) S3method(link_inverse,flexsurvreg) S3method(link_inverse,gam) S3method(link_inverse,gamlss) S3method(link_inverse,gamm) S3method(link_inverse,gbm) S3method(link_inverse,glimML) S3method(link_inverse,glm) S3method(link_inverse,glmmPQL) S3method(link_inverse,glmmTMB) S3method(link_inverse,glmmadmb) S3method(link_inverse,glmx) S3method(link_inverse,gls) S3method(link_inverse,gmnl) S3method(link_inverse,hurdle) S3method(link_inverse,iv_robust) S3method(link_inverse,ivreg) S3method(link_inverse,lm) S3method(link_inverse,lmRob) S3method(link_inverse,lm_robust) S3method(link_inverse,lme) S3method(link_inverse,lmrob) S3method(link_inverse,logistf) S3method(link_inverse,lrm) S3method(link_inverse,mixed) S3method(link_inverse,mixor) S3method(link_inverse,mlogit) S3method(link_inverse,multinom) S3method(link_inverse,plm) S3method(link_inverse,polr) S3method(link_inverse,psm) S3method(link_inverse,rq) S3method(link_inverse,rqss) S3method(link_inverse,speedglm) S3method(link_inverse,speedlm) S3method(link_inverse,stanmvreg) S3method(link_inverse,survfit) S3method(link_inverse,survreg) S3method(link_inverse,svyolr) S3method(link_inverse,tobit) S3method(link_inverse,truncreg) S3method(link_inverse,vgam) S3method(link_inverse,vglm) S3method(link_inverse,zeroinfl) S3method(link_inverse,zerotrunc) S3method(model_info,BBmm) S3method(model_info,BBreg) S3method(model_info,BFBayesFactor) S3method(model_info,DirichletRegModel) S3method(model_info,LORgee) S3method(model_info,MANOVA) S3method(model_info,MCMCglmm) S3method(model_info,MixMod) S3method(model_info,RM) S3method(model_info,aareg) S3method(model_info,aovlist) S3method(model_info,bamlss) S3method(model_info,bayesx) S3method(model_info,betareg) S3method(model_info,brmsfit) S3method(model_info,brmultinom) S3method(model_info,censReg) S3method(model_info,cgam) S3method(model_info,cglm) S3method(model_info,clm) S3method(model_info,clm2) S3method(model_info,clmm) S3method(model_info,complmrob) S3method(model_info,coxme) S3method(model_info,coxph) S3method(model_info,cpglm) S3method(model_info,cpglmm) S3method(model_info,crch) S3method(model_info,crq) S3method(model_info,crqs) S3method(model_info,data.frame) S3method(model_info,default) S3method(model_info,feglm) S3method(model_info,feis) S3method(model_info,felm) S3method(model_info,fixest) S3method(model_info,flexsurvreg) S3method(model_info,gam) S3method(model_info,gamlss) S3method(model_info,gamm) S3method(model_info,gbm) S3method(model_info,glimML) S3method(model_info,glmmPQL) S3method(model_info,glmmTMB) S3method(model_info,glmmadmb) S3method(model_info,glmx) S3method(model_info,gls) S3method(model_info,gmnl) S3method(model_info,htest) S3method(model_info,hurdle) S3method(model_info,iv_robust) S3method(model_info,ivreg) S3method(model_info,lmRob) S3method(model_info,lm_robust) S3method(model_info,lme) S3method(model_info,lmrob) S3method(model_info,logistf) S3method(model_info,lrm) S3method(model_info,maxLik) S3method(model_info,mcmc) S3method(model_info,mixed) S3method(model_info,mixor) S3method(model_info,mlm) S3method(model_info,mlogit) S3method(model_info,mmclogit) S3method(model_info,multinom) S3method(model_info,nlrq) S3method(model_info,nls) S3method(model_info,plm) S3method(model_info,polr) S3method(model_info,rma) S3method(model_info,rq) S3method(model_info,rqss) S3method(model_info,speedglm) S3method(model_info,speedlm) S3method(model_info,stanmvreg) S3method(model_info,survfit) S3method(model_info,survreg) S3method(model_info,svyolr) S3method(model_info,tobit) S3method(model_info,truncreg) S3method(model_info,vgam) S3method(model_info,vglm) S3method(model_info,zeroinfl) S3method(model_info,zerotrunc) S3method(n_obs,BBmm) S3method(n_obs,BBreg) S3method(n_obs,LORgee) S3method(n_obs,MANOVA) S3method(n_obs,RM) S3method(n_obs,aareg) S3method(n_obs,aovlist) S3method(n_obs,bamlss) S3method(n_obs,bayesx) S3method(n_obs,bigglm) S3method(n_obs,biglm) S3method(n_obs,censReg) S3method(n_obs,cgam) S3method(n_obs,cglm) S3method(n_obs,complmrob) S3method(n_obs,coxme) S3method(n_obs,coxph) S3method(n_obs,cpglm) S3method(n_obs,cpglmm) S3method(n_obs,crq) S3method(n_obs,crqs) S3method(n_obs,default) S3method(n_obs,feglm) S3method(n_obs,feis) S3method(n_obs,felm) S3method(n_obs,fixest) S3method(n_obs,flexsurvreg) S3method(n_obs,gamm) S3method(n_obs,gbm) S3method(n_obs,glimML) S3method(n_obs,glmRob) S3method(n_obs,gmnl) S3method(n_obs,hurdle) S3method(n_obs,lmRob) S3method(n_obs,maxLik) S3method(n_obs,mcmc) S3method(n_obs,mlogit) S3method(n_obs,multinom) S3method(n_obs,nlrq) S3method(n_obs,rq) S3method(n_obs,rqss) S3method(n_obs,stanmvreg) S3method(n_obs,survfit) S3method(n_obs,survreg) S3method(n_obs,svyolr) S3method(n_obs,wbgee) S3method(n_obs,wbm) S3method(n_obs,zeroinfl) S3method(n_obs,zerotrunc) S3method(print,easystats_check) export(all_models_equal) export(all_models_same_class) export(clean_names) export(clean_parameters) export(color_if) export(colour_if) export(download_model) export(find_algorithm) export(find_formula) export(find_interactions) export(find_parameters) export(find_predictors) export(find_random) export(find_random_slopes) export(find_response) export(find_statistic) export(find_terms) export(find_variables) export(find_weights) export(format_ci) export(format_table) export(format_value) export(get_correlation_slope_intercept) export(get_data) export(get_parameters) export(get_predictors) export(get_priors) export(get_random) export(get_response) export(get_statistic) export(get_varcov) export(get_variance) export(get_variance_dispersion) export(get_variance_distribution) export(get_variance_fixed) export(get_variance_intercept) export(get_variance_random) export(get_variance_residual) export(get_variance_slope) export(get_weights) export(has_intercept) export(is_model) export(is_model_supported) export(is_multivariate) export(is_nullmodel) export(link_function) export(link_inverse) export(model_info) export(n_obs) export(print_color) export(print_colour) export(print_parameters) export(supported_models) importFrom(methods,.hasSlot) importFrom(methods,slot) importFrom(methods,slotNames) importFrom(stats,Gamma) importFrom(stats,as.formula) importFrom(stats,binomial) importFrom(stats,coef) importFrom(stats,drop.terms) importFrom(stats,family) importFrom(stats,fitted) importFrom(stats,formula) importFrom(stats,gaussian) importFrom(stats,getCall) importFrom(stats,make.link) importFrom(stats,model.frame) importFrom(stats,model.matrix) importFrom(stats,na.omit) importFrom(stats,nobs) importFrom(stats,plogis) importFrom(stats,poisson) importFrom(stats,predict) importFrom(stats,qchisq) importFrom(stats,reformulate) importFrom(stats,reshape) importFrom(stats,setNames) importFrom(stats,terms) importFrom(stats,update) importFrom(stats,var) importFrom(stats,vcov) importFrom(utils,capture.output) importFrom(utils,tail) insight/README.md0000644000176200001440000003451513615555663013225 0ustar liggesusers # insight [![DOI](http://joss.theoj.org/papers/10.21105/joss.01412/status.svg)](https://doi.org/10.21105/joss.01412) [![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/insight)](https://cran.r-project.org/package=insight) [![Documentation](https://img.shields.io/badge/documentation-insight-orange.svg?colorB=E91E63)](https://easystats.github.io/insight/) [![Build Status](https://travis-ci.org/easystats/insight.svg?branch=master)](https://travis-ci.org/easystats/insight) [![downloads](http://cranlogs.r-pkg.org/badges/insight)](http://cranlogs.r-pkg.org/) [![total](http://cranlogs.r-pkg.org/badges/grand-total/insight)](http://cranlogs.r-pkg.org/) **Gain insight into your models\!** When fitting any statistical model, there are many useful pieces of information that are simultaneously calculated and stored beyond coefficient estimates and general model fit statistics. Although there exist some generic functions to obtain model information and data, many package-specific modeling functions do not provide such methods to allow users to access such valuable information. **insight** is an R-package that fills this important gap by providing a suite of functions to support almost any model (see a list of the many models supported below in the **List of Supported Packages and Models** section). The goal of **insight**, then, is to provide tools to provide *easy*, *intuitive*, and *consistent* access to information contained in model objects. These tools aid applied research in virtually any field who fit, diagnose, and present statistical models by streamlining access to every aspect of many model objects via consistent syntax and output. Built with non-programmers in mind, **insight** offers a broad toolbox for making model and data information easily accessible. While **insight** offers many useful functions for working with and understanding model objects (discussed below), we suggest users start with `model_info()`, as this function provides a clean and consistent overview of model objects (e.g., functional form of the model, the model family, link function, number of observations, variables included in the specification, etc.). With a clear understanding of the model introduced, users are able to adapt other functions for more nuanced exploration of and interaction with virtually any model object. ## Definition of Model Components The functions from **insight** address different components of a model. In an effort to avoid confusion about specific “targets” of each function, in this section we provide a short explanation of **insight**’s definitions of regression model components. #### Data The dataset used to fit the model. #### Parameters Values estimated or learned from data that capture the relationship between variables. In regression models, these are usually referred to as *coefficients*. #### Response and Predictors - **response**: the outcome or response variable (dependent variable) of a regression model. - **predictor**: independent variables of (the *fixed* part of) a regression model. For mixed models, variables that are only in the *random effects* part (i.e. grouping factors) of the model are not returned as predictors by default. However, these can be included using additional arguments in the function call, treating predictors are “unique”. As such, if a variable appears as a fixed effect and a random slope, it is treated as one (the same) predictor. #### Variables Any unique variable names that appear in a regression model, e.g., response variable, predictors or random effects. A “variable” only relates to the unique occurence of a term, or the term name. For instance, the expression `x + poly(x, 2)` has only the variable `x`. #### Terms Terms themselves consist of variable and factor names separated by operators, or involve arithmetic expressions. For instance, the expression `x + poly(x, 2)` has *one* variable `x`, but *two* terms `x` and `poly(x, 2)`. #### Random Effects - **random slopes**: variables that are specified as random slopes in a mixed effects model. - **random or grouping factors**: variables that are specified as grouping variables in a mixed effects model. *Aren’t the predictors, terms and parameters the same thing?* In some cases, yes. But not in all cases. Find out more by [**clicking here to access the documentation**](https://easystats.github.io/insight/articles/insight.html). ## Functions The package revolves around two key prefixes: `get_*` and `find_*`. The `get_*` prefix extracts *values* (or *data*) associated with model-specific objects (e.g., parameters or variables), while the `find_*` prefix *lists* model-specific objects (e.g., priors or predictors). These are powerful families of functions allowing for great flexibility in use, whether at a high, descriptive level (`find_*`) or narrower level of statistical inspection and reporting (`get_*`). ![](https://raw.githubusercontent.com/easystats/insight/master/paper/figure1_small.png) In total, the **insight** package includes 16 core functions: [get\_data()](https://easystats.github.io/insight/reference/get_data.html), [get\_priors()](https://easystats.github.io/insight/reference/get_priors.html), [get\_variance()](https://easystats.github.io/insight/reference/get_variance.html), [get\_parameters()](https://easystats.github.io/insight/reference/get_parameters.html), [get\_predictors()](https://easystats.github.io/insight/reference/get_predictors.html), [get\_random()](https://easystats.github.io/insight/reference/get_random.html), [get\_response()](https://easystats.github.io/insight/reference/get_response.html), [find\_algorithm()](https://easystats.github.io/insight/reference/find_algorithm.html), [find\_formula()](https://easystats.github.io/insight/reference/find_formula.html), [find\_variables()](https://easystats.github.io/insight/reference/find_variables.html), [find\_terms()](https://easystats.github.io/insight/reference/find_terms.html), [find\_parameters()](https://easystats.github.io/insight/reference/find_parameters.html), [find\_predictors()](https://easystats.github.io/insight/reference/find_predictors.html), [find\_random()](https://easystats.github.io/insight/reference/find_random.html), [find\_response()](https://easystats.github.io/insight/reference/find_response.html), and [model\_info()](https://easystats.github.io/insight/reference/model_info.html). In all cases, users must supply at a minimum, the name of the model fit object. In several functions, there are additional arguments that allow for more targeted returns of model information. For example, the `find_terms()` function’s `effects` argument allows for the extraction of “fixed effects” terms, “random effects” terms, or by default, “all” terms in the model object. We point users to the package documentation or the complementary package website, , for a detailed list of the arguments associated with each function as well as the returned values from each function. ## Examples of Use Cases in R We now would like to provide examples of use cases of the **insight** package. These examples probably do not cover typical real-world problems, but serve as illustration of the core idea of this package: The unified interface to access model information. **insight** should help both users and package developers in order to reduce the hassle with the many exceptions from various modelling packages when accessing model information. #### Making Predictions at Specific Values of a Term of Interest Say, the goal is to make predictions for a certain term, holding remaining co-variates constant. This is achieved by calling `predict()` and feeding the `newdata`-argument with the values of the term of interest as well as the “constant” values for remaining co-variates. The functions `get_data()` and `find_predictors()` are used to get this information, which then can be used in the call to `predict()`. In this example, we fit a simple linear model, but it could be replaced by (m)any other models, so this approach is “universal” and applies to many different model objects. ``` r library(insight) m <- lm(Sepal.Length ~ Species + Petal.Width + Sepal.Width, data = iris) dat <- get_data(m) pred <- find_predictors(m, flatten = TRUE) l <- lapply(pred, function(x) { if (is.numeric(dat[[x]])) mean(dat[[x]]) else unique(dat[[x]]) }) names(l) <- pred l <- as.data.frame(l) cbind(l, predictions = predict(m, newdata = l)) #> Species Petal.Width Sepal.Width predictions #> 1 setosa 1.2 3.1 5.1 #> 2 versicolor 1.2 3.1 6.1 #> 3 virginica 1.2 3.1 6.3 ``` #### Printing Model Coefficients The next example should emphasize the possibilities to generalize functions to many different model objects using **insight**. The aim is simply to print coefficients in a complete, human readable sentence. The first approach uses the functions that are available for some, but obviously not for all models, to access the information about model coefficients. ``` r print_params <- function(model) { paste0("My parameters are ", paste0(row.names(summary(model)$coefficients), collapse = ", "), ", thank you for your attention!") } m1 <- lm(Sepal.Length ~ Petal.Width, data = iris) print_params(m1) #> [1] "My parameters are (Intercept), Petal.Width, thank you for your attention!" # obviously, something is missing in the output m2 <- mgcv::gam(Sepal.Length ~ Petal.Width + s(Petal.Length), data = iris) print_params(m2) #> [1] "My parameters are , thank you for your attention!" ``` As we can see, the function fails for *gam*-models. As the access to models depends on the type of the model in the R ecosystem, we would need to create specific functions for all models types. With **insight**, users can write a function without having to worry about the model type. ``` r print_params <- function(model) { paste0("My parameters are ", paste0(insight::find_parameters(model, flatten = TRUE), collapse = ", "), ", thank you for your attention!") } m1 <- lm(Sepal.Length ~ Petal.Width, data = iris) print_params(m1) #> [1] "My parameters are (Intercept), Petal.Width, thank you for your attention!" m2 <- mgcv::gam(Sepal.Length ~ Petal.Width + s(Petal.Length), data = iris) print_params(m2) #> [1] "My parameters are (Intercept), Petal.Width, s(Petal.Length), thank you for your attention!" ``` ## Installation Run the following to install the latest GitHub-version of **insight**: ``` r install.packages("devtools") devtools::install_github("easystats/insight") ``` Or install the latest stable release from CRAN: ``` r install.packages("insight") ``` ## Documentation Please visit for documentation. ## Contributing and Support In case you want to file an issue or contribute in another way to the package, please follow [this guide](https://github.com/easystats/insight/blob/master/.github/CONTRIBUTING.md). For questions about the functionality, you may either contact us via email or also file an issue. ## List of Supported Models by Class ``` r supported_models() #> [1] "aareg" "aov" "aovlist" #> [4] "bamlss" "bamlss.frame" "bayesx" #> [7] "BBmm" "BBreg" "betareg" #> [10] "BFBayesFactor" "bigglm" "biglm" #> [13] "blavaan" "bracl" "brglm" #> [16] "brmsfit" "brmultinom" "censReg" #> [19] "cgam" "cgamm" "cglm" #> [22] "clm" "clm2" "clmm" #> [25] "clmm2" "complmrob" "coxme" #> [28] "coxph" "cpglm" "cpglmm" #> [31] "crch" "crq" "crqs" #> [34] "DirichletRegModel" "feglm" "feis" #> [37] "felm" "fixest" "flexsurvreg" #> [40] "gam" "Gam" "gamlss" #> [43] "gamm" "gamm4" "gbm" #> [46] "gee" "geeglm" "glimML" #> [49] "glm" "glmmadmb" "glmmPQL" #> [52] "glmmTMB" "glmrob" "glmRob" #> [55] "glmx" "gls" "gmnl" #> [58] "htest" "hurdle" "iv_robust" #> [61] "ivreg" "lavaan" "lm" #> [64] "lm_robust" "lme" "lmrob" #> [67] "lmRob" "logistf" "LORgee" #> [70] "lrm" "MANOVA" "maxLik" #> [73] "mclogit" "mcmc" "MCMCglmm" #> [76] "merMod" "mixed" "MixMod" #> [79] "mixor" "mlm" "mlogit" #> [82] "mmlogit" "multinom" "ols" #> [85] "plm" "polr" "psm" #> [88] "rlm" "rlmerMod" "RM" #> [91] "rma" "rma.uni" "rq" #> [94] "rqss" "speedglm" "speedlm" #> [97] "stanmvreg" "stanreg" "survfit" #> [100] "survreg" "svyglm" "svyolr" #> [103] "tobit" "truncreg" "vgam" #> [106] "vglm" "wbgee" "wblm" #> [109] "wbm" "zeroinfl" "zerotrunc" ``` - **Didn’t find a model?** [File an issue](https://github.com/easystats/insight/issues) and request additional model-support in *insight*\! ## Credits If this package helped you, please consider citing as follows: Lüdecke D, Waggoner P, Makowski D. insight: A Unified Interface to Access Information from Model Objects in R. Journal of Open Source Software 2019;4:1412. doi: [10.21105/joss.01412](https://doi.org/10.21105/joss.01412) insight/man/0000755000176200001440000000000013602213235012467 5ustar liggesusersinsight/man/clean_names.Rd0000644000176200001440000000307713566471215015247 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/clean_names.R \name{clean_names} \alias{clean_names} \title{Get clean names of model terms} \usage{ clean_names(x) } \arguments{ \item{x}{A fitted model, or a character vector.} } \value{ The "cleaned" variable names as character vector, i.e. pattern like \code{s()} for splines or \code{log()} are removed from the model terms. } \description{ This function "cleans" names of model terms (or a character vector with such names) by removing patterns like \code{log()} or \code{as.factor()} etc. } \note{ Typically, this method is intended to work on character vectors, in order to remove patterns that obscure the variable names. For convenience reasons it is also possible to call \code{clean_names()} also on a model object. If \code{x} is a regression model, this function is (almost) equal to calling \code{find_variables()}. The main difference is that \code{clean_names()} always returns a character vector, while \code{find_variables()} returns a list of character vectors, unless \code{flatten = TRUE}. See 'Examples'. } \examples{ # example from ?stats::glm counts <- c(18, 17, 15, 20, 10, 20, 25, 13, 12) outcome <- c(gl(3, 1, 9)) treatment <- gl(3, 3) m <- glm(counts ~ log(outcome) + as.factor(treatment), family = poisson()) clean_names(m) # difference "clean_names()" and "find_variables()" library(lme4) m <- glmer( cbind(incidence, size - incidence) ~ period + (1 | herd), data = cbpp, family = binomial ) clean_names(m) find_variables(m) find_variables(m, flatten = TRUE) } insight/man/find_random.Rd0000644000176200001440000000272513566471215015261 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/find_random.R \name{find_random} \alias{find_random} \title{Find names of random effects} \usage{ find_random(x, split_nested = FALSE, flatten = FALSE) } \arguments{ \item{x}{A fitted mixed model.} \item{split_nested}{Logical, if \code{TRUE}, terms from nested random effects will be returned as separated elements, not as single string with colon. See 'Examples'.} \item{flatten}{Logical, if \code{TRUE}, the values are returned as character vector, not as list. Duplicated values are removed.} } \value{ A list of character vectors that represent the name(s) of the random effects (grouping factors). Depending on the model, the returned list has following elements: \itemize{ \item \code{random}, the "random effects" terms from the conditional part of model \item \code{zero_inflated_random}, the "random effects" terms from the zero-inflation component of the model } } \description{ Return the name of the grouping factors from mixed effects models. } \examples{ library(lme4) data(sleepstudy) sleepstudy$mygrp <- sample(1:5, size = 180, replace = TRUE) sleepstudy$mysubgrp <- NA for (i in 1:5) { filter_group <- sleepstudy$mygrp == i sleepstudy$mysubgrp[filter_group] <- sample(1:30, size = sum(filter_group), replace = TRUE) } m <- lmer( Reaction ~ Days + (1 | mygrp / mysubgrp) + (1 | Subject), data = sleepstudy ) find_random(m) find_random(m, split_nested = TRUE) } insight/man/find_parameters.Rd0000644000176200001440000001037113600225174016126 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/find_parameters.R, R/get_parameters.R \name{find_parameters} \alias{find_parameters} \alias{find_parameters.gam} \alias{find_parameters.merMod} \alias{find_parameters.zeroinfl} \alias{find_parameters.hurdle} \alias{find_parameters.BFBayesFactor} \alias{find_parameters.brmsfit} \alias{find_parameters.bayesx} \alias{find_parameters.stanreg} \alias{find_parameters.sim.merMod} \alias{get_parameters.bayesx} \title{Find names of model parameters} \usage{ find_parameters(x, ...) \method{find_parameters}{gam}( x, component = c("all", "conditional", "smooth_terms"), flatten = FALSE, ... ) \method{find_parameters}{merMod}(x, effects = c("all", "fixed", "random"), flatten = FALSE, ...) \method{find_parameters}{zeroinfl}( x, component = c("all", "conditional", "zi", "zero_inflated"), flatten = FALSE, ... ) \method{find_parameters}{hurdle}( x, component = c("all", "conditional", "zi", "zero_inflated"), flatten = FALSE, ... ) \method{find_parameters}{BFBayesFactor}( x, effects = c("all", "fixed", "random"), component = c("all", "extra"), flatten = FALSE, ... ) \method{find_parameters}{brmsfit}( x, effects = c("all", "fixed", "random"), component = c("all", "conditional", "zi", "zero_inflated", "dispersion", "simplex", "sigma", "smooth_terms"), flatten = FALSE, parameters = NULL, ... ) \method{find_parameters}{bayesx}( x, component = c("all", "conditional", "smooth_terms"), flatten = FALSE, parameters = NULL, ... ) \method{find_parameters}{stanreg}( x, effects = c("all", "fixed", "random"), component = c("all", "conditional", "smooth_terms"), flatten = FALSE, parameters = NULL, ... ) \method{find_parameters}{sim.merMod}( x, effects = c("all", "fixed", "random"), flatten = FALSE, parameters = NULL, ... ) \method{get_parameters}{bayesx}( x, component = c("all", "conditional", "smooth_terms"), flatten = FALSE, parameters = NULL, ... ) } \arguments{ \item{x}{A fitted model.} \item{...}{Currently not used.} \item{component}{Should all parameters, parameters for the conditional model, the zero-inflated part of the model, the dispersion term or the instrumental variables be returned? Applies to models with zero-inflated and/or dispersion formula, or to models with instrumental variable (so called fixed-effects regressions). May be abbreviated. Note that the \emph{conditional} component is also called \emph{count} or \emph{mean} component, depending on the model.} \item{flatten}{Logical, if \code{TRUE}, the values are returned as character vector, not as list. Duplicated values are removed.} \item{effects}{Should parameters for fixed effects, random effects or both be returned? Only applies to mixed models. May be abbreviated.} \item{parameters}{Regular expression pattern that describes the parameters that should be returned.} } \value{ A list of parameter names. For simple models, only one list-element, \code{conditional}, is returned. For more complex models, the returned list may have following elements: \itemize{ \item \code{conditional}, the "fixed effects" part from the model \item \code{random}, the "random effects" part from the model \item \code{zero_inflated}, the "fixed effects" part from the zero-inflation component of the model \item \code{zero_inflated_random}, the "random effects" part from the zero-inflation component of the model \item \code{dispersion}, the dispersion parameters \item \code{simplex}, simplex parameters of monotonic effects (\pkg{brms} only) \item \code{smooth_terms}, the smooth parameters } } \description{ Returns the names of model parameters, like they typically appear in the \code{summary()} output. For Bayesian models, the parameter names equal the column names of the posterior samples after coercion from \code{as.data.frame()}. } \details{ In most cases when models either return different "effects" (fixed, random) or "components" (conditional, zero-inflated, ...), the arguments \code{effects} and \code{component} can be used. Not all model classes that support these arguments are listed here in the 'Usage' section. } \examples{ data(mtcars) m <- lm(mpg ~ wt + cyl + vs, data = mtcars) find_parameters(m) } insight/man/find_statistic.Rd0000644000176200001440000000134613566471215016006 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/find_statistic.R \name{find_statistic} \alias{find_statistic} \title{Find statistic for model} \usage{ find_statistic(x, ...) } \arguments{ \item{x}{An object.} \item{...}{Currently not used.} } \value{ A character describing the type of statistic. If there is no statistic available with a distribution, \code{NULL} will be returned. } \description{ Returns the statistic for a regression model (\emph{t}-statistic, \emph{z}-statistic, etc.). Small helper that checks if a model is a regression model object and return the statistic used. } \examples{ # regression model object data(mtcars) m <- lm(mpg ~ wt + cyl + vs, data = mtcars) find_statistic(m) } insight/man/is_model_supported.Rd0000644000176200001440000000167013566471215016677 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/is_model_supported.R \name{is_model_supported} \alias{is_model_supported} \alias{supported_models} \title{Checks if an object is a regression model object supported in \pkg{insight} package.} \usage{ is_model_supported(x) supported_models() } \arguments{ \item{x}{An object.} } \value{ A logical, \code{TRUE} if \code{x} is a (supported) model object. } \description{ Small helper that checks if a model is a \emph{supported} (regression) model object. \code{supported_models()} prints a list of currently supported model classes. } \details{ This function returns \code{TRUE} if \code{x} is a model object that works with the package's functions. A list of supported models can also be found here: \url{https://github.com/easystats/insight}. } \examples{ data(mtcars) m <- lm(mpg ~ wt + cyl + vs, data = mtcars) is_model_supported(m) is_model_supported(mtcars) } insight/man/print_color.Rd0000644000176200001440000000157213566471215015332 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/print_color.R \name{print_color} \alias{print_color} \alias{print_colour} \title{Coloured console output} \usage{ print_color(text, color) print_colour(text, colour) } \arguments{ \item{text}{The text to print.} \item{color, colour}{Character vector, indicating the colour for printing. May be one of \code{"red"}, \code{"yellow"}, \code{"green"}, \code{"blue"}, \code{"violet"}, \code{"cyan"} or \code{"grey"}. Formatting is also possible with \code{"bold"} or \code{"italic"}.} } \value{ Nothing. } \description{ Convenient function that allows coloured output in the console. Mainly implemented to reduce package dependencies. } \details{ This function prints \code{text} directly to the console using \code{cat()}, so no string is returned. } \examples{ print_color("I'm blue dabedi dabedei", "blue") } insight/man/all_models_equal.Rd0000644000176200001440000000206613566471215016301 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/all_equal_models.R \name{all_models_equal} \alias{all_models_equal} \alias{all_models_same_class} \title{Checks if all objects are models of same class} \usage{ all_models_equal(..., verbose = FALSE) all_models_same_class(..., verbose = FALSE) } \arguments{ \item{...}{A list of objects.} \item{verbose}{Toggle off warnings.} } \value{ A logical, \code{TRUE} if \code{x} are all supported model objects of same class. } \description{ Small helper that checks if all objects are \emph{supported} (regression) model objects and of same class. } \examples{ library(lme4) data(mtcars) data(sleepstudy) m1 <- lm(mpg ~ wt + cyl + vs, data = mtcars) m2 <- lm(mpg ~ wt + cyl, data = mtcars) m3 <- lmer(Reaction ~ Days + (1 | Subject), data = sleepstudy) m4 <- glm(formula = vs ~ wt, family = binomial(), data = mtcars) all_models_same_class(m1, m2) all_models_same_class(m1, m2, m3) all_models_same_class(m1, m4, m2, m3, verbose = TRUE) all_models_same_class(m1, m4, mtcars, m2, m3, verbose = TRUE) } insight/man/find_variables.Rd0000644000176200001440000000560113602442163015734 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/find_variables.R \name{find_variables} \alias{find_variables} \title{Find names of all variables} \usage{ find_variables( x, effects = c("all", "fixed", "random"), component = c("all", "conditional", "zi", "zero_inflated", "dispersion", "instruments", "smooth_terms"), flatten = FALSE ) } \arguments{ \item{x}{A fitted model.} \item{effects}{Should variables for fixed effects, random effects or both be returned? Only applies to mixed models. May be abbreviated.} \item{component}{Should all predictor variables, predictor variables for the conditional model, the zero-inflated part of the model, the dispersion term or the instrumental variables be returned? Applies to models with zero-inflated and/or dispersion formula, or to models with instrumental variable (so called fixed-effects regressions). May be abbreviated. Note that the \emph{conditional} component is also called \emph{count} or \emph{mean} component, depending on the model.} \item{flatten}{Logical, if \code{TRUE}, the values are returned as character vector, not as list. Duplicated values are removed.} } \value{ A list with (depending on the model) following elements (character vectors): \itemize{ \item \code{response}, the name of the response variable \item \code{conditional}, the names of the predictor variables from the \emph{conditional} model (as opposed to the zero-inflated part of a model) \item \code{random}, the names of the random effects (grouping factors) \item \code{zero_inflated}, the names of the predictor variables from the \emph{zero-inflated} part of the model \item \code{zero_inflated_random}, the names of the random effects (grouping factors) \item \code{dispersion}, the name of the dispersion terms \item \code{instruments}, the names of instrumental variables } } \description{ Returns a list with the names of all variables, including response value and random effects. } \note{ The difference to \code{\link{find_terms}} is that \code{find_variables()} returns each variable name only once, while \code{find_terms()} may return a variable multiple times in case of transformations or when arithmetic expressions were used in the formula. } \examples{ library(lme4) data(cbpp) data(sleepstudy) # some data preparation... cbpp$trials <- cbpp$size - cbpp$incidence sleepstudy$mygrp <- sample(1:5, size = 180, replace = TRUE) sleepstudy$mysubgrp <- NA for (i in 1:5) { filter_group <- sleepstudy$mygrp == i sleepstudy$mysubgrp[filter_group] <- sample(1:30, size = sum(filter_group), replace = TRUE) } m1 <- glmer( cbind(incidence, size - incidence) ~ period + (1 | herd), data = cbpp, family = binomial ) find_variables(m1) m2 <- lmer( Reaction ~ Days + (1 | mygrp / mysubgrp) + (1 | Subject), data = sleepstudy ) find_variables(m2) find_variables(m2, flatten = TRUE) } insight/man/model_info.Rd0000644000176200001440000000637013615526401015105 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/model_info.R \name{model_info} \alias{model_info} \title{Access information from model objects} \usage{ model_info(x, ...) } \arguments{ \item{x}{A fitted model.} \item{...}{Currently not used.} } \value{ A list with information about the model, like family, link-function etc. (see 'Details'). } \description{ Retrieve information from model objects. } \details{ \code{model_info()} returns a list with information about the model for many different model objects. Following information is returned, where all values starting with \code{is_} are logicals. \itemize{ \item \code{is_binomial}: family is binomial (but not negative binomial) \item \code{is_poisson}: family is poisson \item \code{is_negbin}: family is negative binomial \item \code{is_count}: model is a count model (i.e. family is either poisson or negative binomial) \item \code{is_beta}: family is beta \item \code{is_betabinomial}: family is beta-binomial \item \code{is_dirichlet}: family is dirichlet \item \code{is_exponential}: family is exponential (e.g. Gamma or Weibull) \item \code{is_logit}: model has logit link \item \code{is_progit}: model has probit link \item \code{is_linear}: family is gaussian \item \code{is_tweedie}: family is tweedie \item \code{is_ordinal}: family is ordinal, multinomial, or cumulative link \item \code{is_cumulative}: family is ordinal, multinomial, or cumulative link \item \code{is_multinomial}: family is multinomial or categorical link \item \code{is_categorical}: family is categorical link \item \code{is_censored}: model is a censored model (has a censored response, including survival models) \item \code{is_truncated}: model is a truncated model (has a truncated response) \item \code{is_survival}: model is a survival model \item \code{is_zero_inflated}: model has zero-inflation component \item \code{is_hurdle}: model has zero-inflation component and is a hurdle-model (truncated family distribution) \item \code{is_mixed}: model is a mixed effects model (with random effects) \item \code{is_multivariate}: model is a multivariate response model (currently only works for \emph{brmsfit} objects) \item \code{is_trial}: model response contains additional information about the trials \item \code{is_bayesian}: model is a Bayesian model \item \code{is_anova}: model is an Anova object \item \code{link_function}: the link-function \item \code{family}: the family-object \item \code{n_obs}: number of observations \item \code{model_terms}: a list with all model terms, including terms such as random effects or from zero-inflated model parts. } } \examples{ ldose <- rep(0:5, 2) numdead <- c(1, 4, 9, 13, 18, 20, 0, 2, 6, 10, 12, 16) sex <- factor(rep(c("M", "F"), c(6, 6))) SF <- cbind(numdead, numalive = 20 - numdead) dat <- data.frame(ldose, sex, SF, stringsAsFactors = FALSE) m <- glm(SF ~ sex * ldose, family = binomial) model_info(m) \dontrun{ library(glmmTMB) data("Salamanders") m <- glmmTMB( count ~ spp + cover + mined + (1 | site), ziformula = ~ spp + mined, dispformula = ~DOY, data = Salamanders, family = nbinom2 ) } model_info(m) } insight/man/get_statistic.Rd0000644000176200001440000000435613613304134015635 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_statistic.R \name{get_statistic} \alias{get_statistic} \alias{get_statistic.default} \alias{get_statistic.glmmTMB} \alias{get_statistic.clm2} \alias{get_statistic.gee} \alias{get_statistic.betareg} \alias{get_statistic.DirichletRegModel} \title{Get statistic associated with estimates} \usage{ get_statistic(x, ...) \method{get_statistic}{default}(x, column_index = 3, ...) \method{get_statistic}{glmmTMB}( x, component = c("all", "conditional", "zi", "zero_inflated"), ... ) \method{get_statistic}{clm2}(x, component = c("all", "conditional", "scale"), ...) \method{get_statistic}{gee}(x, robust = FALSE, ...) \method{get_statistic}{betareg}(x, component = c("all", "conditional", "precision"), ...) \method{get_statistic}{DirichletRegModel}(x, component = c("all", "conditional", "precision"), ...) } \arguments{ \item{x}{A model.} \item{...}{Currently not used.} \item{column_index}{For model objects that have no defined \code{get_statistic()} method yet, the default method is called. This method tries to extract the statistic column from \code{coef(summary())}, where the index of the column that is being pulled is \code{column_index}. Defaults to 3, which is the default statistic column for most models' summary-output.} \item{component}{Should all parameters, parameters for the conditional model, or for the zero-inflated part of the model be returned? Applies to models with zero-inflated component. \code{component} may be one of \code{"conditional"}, \code{"zi"}, \code{"zero-inflated"} or \code{"all"} (default). For models with smooth terms, \code{component = "smooth_terms"} is also possible. May be abbreviated. Note that the \emph{conditional} component is also called \emph{count} or \emph{mean} component, depending on the model.} \item{robust}{Logical, if \code{TRUE}, test statistic based on robust standard errors is returned.} } \value{ A data frame with the model's parameter names and the related test statistic. } \description{ Returns the statistic (\emph{t}, \code{z}, ...) for model estimates. In most cases, this is the related column from \code{coef(summary())}. } \examples{ data(mtcars) m <- lm(mpg ~ wt + cyl + vs, data = mtcars) get_statistic(m) } insight/man/find_predictors.Rd0000644000176200001440000000476313602442163016152 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/find_predictors.R \name{find_predictors} \alias{find_predictors} \title{Find names of model predictors} \usage{ find_predictors( x, effects = c("fixed", "random", "all"), component = c("all", "conditional", "zi", "zero_inflated", "dispersion", "instruments", "correlation", "smooth_terms"), flatten = FALSE ) } \arguments{ \item{x}{A fitted model.} \item{effects}{Should variables for fixed effects, random effects or both be returned? Only applies to mixed models. May be abbreviated.} \item{component}{Should all predictor variables, predictor variables for the conditional model, the zero-inflated part of the model, the dispersion term or the instrumental variables be returned? Applies to models with zero-inflated and/or dispersion formula, or to models with instrumental variable (so called fixed-effects regressions). May be abbreviated. Note that the \emph{conditional} component is also called \emph{count} or \emph{mean} component, depending on the model.} \item{flatten}{Logical, if \code{TRUE}, the values are returned as character vector, not as list. Duplicated values are removed.} } \value{ A list of character vectors that represent the name(s) of the predictor variables. Depending on the combination of the arguments \code{effects} and \code{component}, the returned list has following elements: \itemize{ \item \code{conditional}, the "fixed effects" terms from the model \item \code{random}, the "random effects" terms from the model \item \code{zero_inflated}, the "fixed effects" terms from the zero-inflation component of the model \item \code{zero_inflated_random}, the "random effects" terms from the zero-inflation component of the model \item \code{dispersion}, the dispersion terms \item \code{instruments}, for fixed-effects regressions like \code{ivreg}, \code{felm} or \code{plm}, the instrumental variables \item \code{correlation}, for models with correlation-component like \code{gls}, the variables used to describe the correlation structure } } \description{ Returns the names of the predictor variables for the different parts of a model (like fixed or random effects, zero-inflated component, ...). Unlike \code{\link{find_parameters}}, the names from \code{find_predictors()} match the original variable names from the data that was used to fit the model. } \examples{ data(mtcars) m <- lm(mpg ~ wt + cyl + vs, data = mtcars) find_predictors(m) } insight/man/find_algorithm.Rd0000644000176200001440000000262313566471215015764 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/find_algorithm.R \name{find_algorithm} \alias{find_algorithm} \title{Find sampling algorithm and optimizers} \usage{ find_algorithm(x, ...) } \arguments{ \item{x}{A fitted model.} \item{...}{Currently not used.} } \value{ A list with elements depending on the model. \cr For frequentist models: \itemize{ \item \code{algorithm}, for instance \code{"OLS"} or \code{"ML"} \item \code{optimizer}, name of optimizing function, only applies to specific models (like \code{gam}) } For frequentist mixed models: \itemize{ \item \code{algorithm}, for instance \code{"REML"} or \code{"ML"} \item \code{optimizer}, name of optimizing function } For Bayesian models: \itemize{ \item \code{algorithm}, the algorithm \item \code{chains}, number of chains \item \code{iterations}, number of iterations per chain \item \code{warmup}, number of warmups per chain } } \description{ Returns information on the sampling or estimation algorithm as well as optimization functions, or for Bayesian model information on chains, iterations and warmup-samples. } \examples{ library(lme4) data(sleepstudy) m <- lmer(Reaction ~ Days + (1 | Subject), data = sleepstudy) find_algorithm(m) \dontrun{ library(rstanarm) m <- stan_lmer(Reaction ~ Days + (1 | Subject), data = sleepstudy) find_algorithm(m) } } insight/man/find_interactions.Rd0000644000176200001440000000353013571265241016472 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/find_interactions.R \name{find_interactions} \alias{find_interactions} \title{Find interaction terms from models} \usage{ find_interactions( x, component = c("all", "conditional", "zi", "zero_inflated", "dispersion", "instruments"), flatten = FALSE ) } \arguments{ \item{x}{A fitted model.} \item{component}{Should all predictor variables, predictor variables for the conditional model, the zero-inflated part of the model, the dispersion term or the instrumental variables be returned? Applies to models with zero-inflated and/or dispersion formula, or to models with instrumental variable (so called fixed-effects regressions). May be abbreviated. Note that the \emph{conditional} component is also called \emph{count} or \emph{mean} component, depending on the model.} \item{flatten}{Logical, if \code{TRUE}, the values are returned as character vector, not as list. Duplicated values are removed.} } \value{ A list of character vectors that represent the interaction terms. Depending on \code{component}, the returned list has following elements (or \code{NULL}, if model has no interaction term): \itemize{ \item \code{conditional}, interaction terms that belong to the "fixed effects" terms from the model \item \code{zero_inflated}, interaction terms that belong to the "fixed effects" terms from the zero-inflation component of the model \item \code{instruments}, for fixed-effects regressions like \code{ivreg}, \code{felm} or \code{plm}, interaction terms that belong to the instrumental variables } } \description{ Returns all lowest to highest order interaction terms from a model. } \examples{ data(mtcars) m <- lm(mpg ~ wt + cyl + vs, data = mtcars) find_interactions(m) m <- lm(mpg ~ wt * cyl + vs * hp * gear + carb, data = mtcars) find_interactions(m) } insight/man/find_response.Rd0000644000176200001440000000166713566471215015643 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/find_response.R \name{find_response} \alias{find_response} \title{Find name of the response variable} \usage{ find_response(x, combine = TRUE) } \arguments{ \item{x}{A fitted model.} \item{combine}{Logical, if \code{TRUE} and the response is a matrix-column, the name of the response matches the notation in formula, and would for instance also contain patterns like \code{"cbind(...)"}. Else, the original variable names from the matrix-column are returned. See 'Examples'.} } \value{ The name(s) of the response variable(s) from \code{x} as character vector. } \description{ Returns the name(s) of the response variable(s) from a model object. } \examples{ library(lme4) data(cbpp) cbpp$trials <- cbpp$size - cbpp$incidence m <- glm(cbind(incidence, trials) ~ period, data = cbpp, family = binomial) find_response(m, combine = TRUE) find_response(m, combine = FALSE) } insight/man/is_model.Rd0000644000176200001440000000107513566471215014571 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/is_model.R \name{is_model} \alias{is_model} \title{Checks if an object is a regression model object} \usage{ is_model(x) } \arguments{ \item{x}{An object.} } \value{ A logical, \code{TRUE} if \code{x} is a (supported) model object. } \description{ Small helper that checks if a model is a regression model object. } \details{ This function returns \code{TRUE} if \code{x} is a model object. } \examples{ data(mtcars) m <- lm(mpg ~ wt + cyl + vs, data = mtcars) is_model(m) is_model(mtcars) } insight/man/get_variance.Rd0000644000176200001440000001575013602214466015424 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_variances.R \name{get_variance} \alias{get_variance} \alias{get_variance_residual} \alias{get_variance_fixed} \alias{get_variance_random} \alias{get_variance_distribution} \alias{get_variance_dispersion} \alias{get_variance_intercept} \alias{get_variance_slope} \alias{get_correlation_slope_intercept} \title{Get variance components from random effects models} \usage{ get_variance( x, component = c("all", "fixed", "random", "residual", "distribution", "dispersion", "intercept", "slope", "rho01"), verbose = TRUE, ... ) get_variance_residual(x, ...) get_variance_fixed(x, ...) get_variance_random(x, ...) get_variance_distribution(x, ...) get_variance_dispersion(x, ...) get_variance_intercept(x, ...) get_variance_slope(x, ...) get_correlation_slope_intercept(x, ...) } \arguments{ \item{x}{A mixed effects model.} \item{component}{Character value, indicating the variance component that should be returned. By default, all variance components are returned. The distribution-specific (\code{"distribution"}) and residual (\code{"residual"}) variance are the most computational intensive components, and hence may take a few seconds to calculate.} \item{verbose}{Toggle off warnings.} \item{...}{Currently not used.} } \value{ A list with following elements: \itemize{ \item \code{var.fixed}, variance attributable to the fixed effects \item \code{var.random}, (mean) variance of random effects \item \code{var.residual}, residual variance (sum of dispersion and distribution) \item \code{var.distribution}, distribution-specific variance \item \code{var.dispersion}, variance due to additive dispersion \item \code{var.intercept}, the random-intercept-variance, or between-subject-variance (\ifelse{html}{\out{τ00}}{\eqn{\tau_{00}}}) \item \code{var.slope}, the random-slope-variance (\ifelse{html}{\out{τ11}}{\eqn{\tau_{11}}}) \item \code{cor.slope_intercept}, the random-slope-intercept-correlation (\ifelse{html}{\out{ρ01}}{\eqn{\rho_{01}}}) } } \description{ This function extracts the different variance components of a mixed model and returns the result as list. Functions like \code{get_variance_residual(x)} or \code{get_variance_fixed(x)} are shortcuts for \code{get_variance(x, component = "residual")} etc. } \details{ This function returns different variance components from mixed models, which are needed, for instance, to calculate r-squared measures or the intraclass-correlation coefficient (ICC). \subsection{Fixed effects variance}{ The fixed effects variance, \ifelse{html}{\out{σ2f}}{\eqn{\sigma^2_f}}, is the variance of the matrix-multiplication \ifelse{html}{\out{β∗X}}{\eqn{\beta*X}} (parameter vector by model matrix). } \subsection{Random effects variance}{ The random effect variance, \ifelse{html}{\out{σ2i}}{\eqn{\sigma^2_i}}, represents the \emph{mean} random effect variance of the model. Since this variance reflect the "average" random effects variance for mixed models, it is also appropriate for models with more complex random effects structures, like random slopes or nested random effects. Details can be found in \cite{Johnson 2014}, in particular equation 10. For simple random-intercept models, the random effects variance equals the random-intercept variance. } \subsection{Distribution-specific variance}{ The distribution-specific variance, \ifelse{html}{\out{σ2d}}{\eqn{\sigma^2_d}}, depends on the model family. For Gaussian models, it is \ifelse{html}{\out{σ2}}{\eqn{\sigma^2}} (i.e. \code{sigma(model)^2}). For models with binary outcome, it is \eqn{\pi^2 / 3} for logit-link and \code{1} for probit-link. For all other models, the distribution-specific variance is based on lognormal approximation, \eqn{log(1 + var(x) / \mu^2)} (see \cite{Nakagawa et al. 2017}). The expected variance of a zero-inflated model is computed according to \cite{Zuur et al. 2012, p277}. } \subsection{Variance for the additive overdispersion term}{ The variance for the additive overdispersion term, \ifelse{html}{\out{σ2e}}{\eqn{\sigma^2_e}}, represents \dQuote{the excess variation relative to what is expected from a certain distribution} (Nakagawa et al. 2017). In (most? many?) cases, this will be \code{0}. } \subsection{Residual variance}{ The residual variance, \ifelse{html}{\out{σ2ε}}{\eqn{\sigma^2_\epsilon}}, is simply \ifelse{html}{\out{σ2d + σ2e}}{\eqn{\sigma^2_d + \sigma^2_e}}. } \subsection{Random intercept variance}{ The random intercept variance, or \emph{between-subject} variance (\ifelse{html}{\out{τ00}}{\eqn{\tau_{00}}}), is obtained from \code{VarCorr()}. It indicates how much groups or subjects differ from each other, while the residual variance \ifelse{html}{\out{σ2ε}}{\eqn{\sigma^2_\epsilon}} indicates the \emph{within-subject variance}. } \subsection{Random slope variance}{ The random slope variance (\ifelse{html}{\out{τ11}}{\eqn{\tau_{11}}}) is obtained from \code{VarCorr()}. This measure is only available for mixed models with random slopes. } \subsection{Random slope-intercept correlation}{ The random slope-intercept correlation (\ifelse{html}{\out{ρ01}}{\eqn{\rho_{01}}}) is obtained from \code{VarCorr()}. This measure is only available for mixed models with random intercepts and slopes. } } \note{ This function supports models of class \code{merMod} (including models from \pkg{blme}), \code{clmm}, \code{cpglmm}, \code{glmmadmb}, \code{glmmTMB}, \code{MixMod}, \code{lme}, \code{mixed}, \code{rlmerMod}, \code{stanreg} or \code{wbm}. Support for objects of class \code{MixMod} (\pkg{GLMMadaptiv}) or \code{lme} (\pkg{nlme}) is experimental and may not work for all models. } \examples{ \dontrun{ library(lme4) data(sleepstudy) m <- lmer(Reaction ~ Days + (1 + Days | Subject), data = sleepstudy) get_variance(m) get_variance_fixed(m) get_variance_residual(m) } } \references{ \itemize{ \item Johnson, P. C. D. (2014). Extension of Nakagawa & Schielzeth’s R2 GLMM to random slopes models. Methods in Ecology and Evolution, 5(9), 944–946. \doi{10.1111/2041-210X.12225} \item Nakagawa, S., Johnson, P. C. D., & Schielzeth, H. (2017). The coefficient of determination R2 and intra-class correlation coefficient from generalized linear mixed-effects models revisited and expanded. Journal of The Royal Society Interface, 14(134), 20170213. \doi{10.1098/rsif.2017.0213} \item Zuur, A. F., Savel'ev, A. A., & Ieno, E. N. (2012). Zero inflated models and generalized linear mixed models with R. Newburgh, United Kingdom: Highland Statistics. } } insight/man/get_weights.Rd0000644000176200001440000000105513566471215015305 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_weights.R \name{get_weights} \alias{get_weights} \title{Get the values from model weights} \usage{ get_weights(x, ...) } \arguments{ \item{x}{A fitted model.} \item{...}{Currently not used.} } \value{ The weighting variable, or \code{NULL} if no weights were specified. } \description{ Returns weighting variable of a model. } \examples{ data(mtcars) mtcars$weight <- rnorm(nrow(mtcars), 1, .3) m <- lm(mpg ~ wt + cyl + vs, data = mtcars, weights = weight) get_weights(m) } insight/man/format_table.Rd0000644000176200001440000000206213566471215015432 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/format_table.R \name{format_table} \alias{format_table} \title{Dataframe and Tables Pretty Formatting} \usage{ format_table( x, sep = " | ", header = "-", digits = 2, protect_integers = TRUE, missing = "", width = NULL ) } \arguments{ \item{x}{A data frame.} \item{sep}{Column separator.} \item{header}{Header separator. Can be \code{NULL}.} \item{digits}{Number of significant digits.} \item{protect_integers}{Should integers be kept as integers (i.e., without decimals)?} \item{missing}{Value by which \code{NA} values are replaced. By default, an empty string (i.e. \code{""}) is returned for \code{NA}.} \item{width}{Minimum width of the returned string. If not \code{NULL} and \code{width} is larger than the string's length, leading whitespaces are added to the string.} } \value{ A data frame in character format. } \description{ Dataframe and Tables Pretty Formatting } \examples{ cat(format_table(iris)) cat(format_table(iris, sep = " ", header = "*", digits = 1)) } insight/man/has_intercept.Rd0000644000176200001440000000130513566471215015622 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/has_intercept.R \name{has_intercept} \alias{has_intercept} \title{Checks if model has an intercept} \usage{ has_intercept(x) } \arguments{ \item{x}{A model object.} } \value{ \code{TRUE} if \code{x} has an intercept, \code{FALSE} otherwise. } \description{ Checks if model has an intercept. } \examples{ model <- lm(mpg ~ 0 + gear, data = mtcars) has_intercept(model) model <- lm(mpg ~ gear, data = mtcars) has_intercept(model) library(lme4) model <- lmer(Reaction ~ 0 + Days + (Days | Subject), data = sleepstudy) has_intercept(model) model <- lmer(Reaction ~ Days + (Days | Subject), data = sleepstudy) has_intercept(model) } insight/man/download_model.Rd0000644000176200001440000000165313566471215015767 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/download_model.R \name{download_model} \alias{download_model} \title{Download circus models} \usage{ download_model(name, url = NULL) } \arguments{ \item{name}{Model name.} \item{url}{String with the URL from where to download the model data. Optional, and should only be used in case the repository-URL is changing. By default, models are downloaded from \code{https://raw.github.com/easystats/circus/master/data/}.} } \value{ A model from the \emph{circus}-repository. } \description{ Downloads pre-compiled models from the \emph{circus}-repository. The \emph{circus}-repository contains a variety of fitted models to help the systematic testing of other packages } \details{ The code that generated the model is available at the \url{https://easystats.github.io/circus/reference/index.html}. } \references{ \url{https://easystats.github.io/circus/} } insight/man/is_multivariate.Rd0000644000176200001440000000174013566471215016176 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/is_multivariate.R \name{is_multivariate} \alias{is_multivariate} \title{Checks if an object stems from a multivariate response model} \usage{ is_multivariate(x) } \arguments{ \item{x}{A model object, or an object returned by a function from this package.} } \value{ A logical, \code{TRUE} if either \code{x} is a model object and is a multivariate response model, or \code{TRUE} if a return value from a function of \pkg{insight} is from a multivariate response model. } \description{ Small helper that checks if a model is a multivariate response model, i.e. a model with multiple outcomes. } \examples{ \dontrun{ library(rstanarm) data("pbcLong") model <- stan_mvmer( formula = list( logBili ~ year + (1 | id), albumin ~ sex + year + (year | id) ), data = pbcLong, chains = 1, cores = 1, seed = 12345, iter = 1000 ) f <- find_formula(model) is_multivariate(model) is_multivariate(f) } } insight/man/is_nullmodel.Rd0000644000176200001440000000141513566471215015462 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/is_nullmodel.R \name{is_nullmodel} \alias{is_nullmodel} \title{Checks if model is a null-model (intercept-only)} \usage{ is_nullmodel(x) } \arguments{ \item{x}{A model object.} } \value{ \code{TRUE} if \code{x} is a null-model, \code{FALSE} otherwise. } \description{ Checks if model is a null-model (intercept-only), i.e. if the conditional part of the model has no predictors. } \examples{ model <- lm(mpg ~ 1, data = mtcars) is_nullmodel(model) model <- lm(mpg ~ gear, data = mtcars) is_nullmodel(model) library(lme4) model <- lmer(Reaction ~ 1 + (Days | Subject), data = sleepstudy) is_nullmodel(model) model <- lmer(Reaction ~ Days + (Days | Subject), data = sleepstudy) is_nullmodel(model) } insight/man/get_varcov.Rd0000644000176200001440000000511013613301122015105 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_varcov.R \name{get_varcov} \alias{get_varcov} \alias{get_varcov.betareg} \alias{get_varcov.DirichletRegModel} \alias{get_varcov.clm2} \alias{get_varcov.truncreg} \alias{get_varcov.gamlss} \alias{get_varcov.hurdle} \alias{get_varcov.MixMod} \alias{get_varcov.glmmTMB} \alias{get_varcov.brmsfit} \alias{get_varcov.mixor} \title{Get variance-covariance matrix from models} \usage{ get_varcov(x, ...) \method{get_varcov}{betareg}(x, component = c("conditional", "precision", "all"), ...) \method{get_varcov}{DirichletRegModel}(x, component = c("conditional", "precision", "all"), ...) \method{get_varcov}{clm2}(x, component = c("all", "conditional", "scale"), ...) \method{get_varcov}{truncreg}(x, component = c("conditional", "all"), ...) \method{get_varcov}{gamlss}(x, component = c("conditional", "all"), ...) \method{get_varcov}{hurdle}(x, component = c("conditional", "zero_inflated", "zi", "all"), ...) \method{get_varcov}{MixMod}(x, component = c("conditional", "zero_inflated", "zi", "all"), ...) \method{get_varcov}{glmmTMB}(x, component = c("conditional", "zero_inflated", "zi", "all"), ...) \method{get_varcov}{brmsfit}(x, component = c("conditional", "zero_inflated", "zi", "all"), ...) \method{get_varcov}{mixor}(x, effects = c("all", "fixed", "random"), ...) } \arguments{ \item{x}{A model.} \item{...}{Currently not used.} \item{component}{Should the complete variance-covariance matrix of the model be returned, or only for specific model components only (like count or zero-inflated model parts)? Applies to models with zero-inflated component, or models with precision (e.g. \code{betareg}) component. \code{component} may be one of \code{"conditional"}, \code{"zi"}, \code{"zero-inflated"}, \code{"precision"}, or \code{"all"}. May be abbreviated. Note that the \emph{conditional} component is also called \emph{count} or \emph{mean} component, depending on the model.} \item{effects}{Should the complete variance-covariance matrix of the model be returned, or only for specific model parameters only? Currently only applies to models of class \code{mixor}.} } \value{ The variance-covariance matrix, as \code{matrix}-object. } \description{ Returns the variance-covariance, as retrieved by \code{stats::vcov()}, but works for more model objects that probably don't provide a \code{vcov()}-method. } \note{ \code{get_varcov()} tries to return the nearest positive definite matrix in case of a negative variance-covariance matrix. } \examples{ data(mtcars) m <- lm(mpg ~ wt + cyl + vs, data = mtcars) get_varcov(m) } insight/man/format_ci.Rd0000644000176200001440000000313313602361463014730 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/format_ci.R \name{format_ci} \alias{format_ci} \title{Confidence/Credible Interval (CI) Formatting} \usage{ format_ci( CI_low, CI_high, ci = 0.95, digits = 2, brackets = TRUE, width = NULL, width_low = width, width_high = width ) } \arguments{ \item{CI_low}{Lower CI bound.} \item{CI_high}{Upper CI bound.} \item{ci}{CI level in percentage.} \item{digits}{Number of significant digits.} \item{brackets}{Logical, if \code{TRUE} (default), values are encompassed in square brackets.} \item{width}{Minimum width of the returned string. If not \code{NULL} and \code{width} is larger than the string's length, leading whitespaces are added to the string. If \code{width="auto"}, width will be set to the length of the longest string.} \item{width_low, width_high}{Like \code{width}, but only applies to the lower or higher confidence interval value. This can be used when the values for the lower and upper CI are of very different length.} } \value{ A formatted string. } \description{ Confidence/Credible Interval (CI) Formatting } \examples{ format_ci(1.20, 3.57, ci = 0.90) format_ci(1.20, 3.57, ci = NULL) format_ci(1.20, 3.57, ci = NULL, brackets = FALSE) format_ci(c(1.205645, 23.4), c(3.57, -1.35), ci = 0.90) format_ci(c(1.20, NA, NA), c(3.57, -1.35, NA), ci = 0.90) # automatic alignment of width, useful for printing multiple CIs in columns x <- format_ci(c(1.205, 23.4, 100.43), c(3.57, -13.35, 9.4)) cat(x, sep = "\n") x <- format_ci(c(1.205, 23.4, 100.43), c(3.57, -13.35, 9.4), width = "auto") cat(x, sep = "\n") } insight/man/clean_parameters.Rd0000644000176200001440000000414213566471215016301 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/clean_parameters.R \name{clean_parameters} \alias{clean_parameters} \title{Get clean names of model parameters} \usage{ clean_parameters(x, ...) } \arguments{ \item{x}{A fitted model.} \item{...}{Currently not used.} } \value{ A data frame with "cleaned" parameter names and information on effects, component and group where parameters belong to. To be consistent across different models, the returned data frame always has at least four columns \code{Parameter}, \code{Effects}, \code{Component} and \code{Cleaned_Parameter}. See 'Details'. } \description{ This function "cleans" names of model parameters by removing patterns like \code{"r_"} or \code{"b[]"} (mostly applicable to Stan models) and adding columns with information to which group or component parameters belong (i.e. fixed or random, count or zero-inflated...) \cr \cr The main purpose of this function is to easily filter and select model parameters, in particular of - but not limited to - posterior samples from Stan models, depending on certain characteristics. This might be useful when only selective results should be reported or results from all parameters should be filtered to return only certain results (see \code{\link{print_parameters}}). } \details{ The \code{Effects} column indicate if a parameter is a \emph{fixed} or \emph{random} effect. The \code{Component} can either be \emph{conditional} or \emph{zero_inflated}. For models with random effects, the \code{Group} column indicates the grouping factor of the random effects. For multivariate response models from \pkg{brms} or \pkg{rstanarm}, an additional \emph{Response} column is included, to indicate which parameters belong to which response formula. Furthermore, \emph{Cleaned_Parameter} column is returned that contains "human readable" parameter names (which are mostly identical to \code{Parameter}, except for for models from \pkg{brms} or \pkg{rstanarm}, or for specific terms like smooth- or spline-terms). } \examples{ \dontrun{ library(brms) model <- download_model("brms_zi_2") clean_parameters(model) } } insight/man/print_parameters.Rd0000644000176200001440000000745013566471215016360 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/print_parameters.R \name{print_parameters} \alias{print_parameters} \title{Prepare summary statistics of model parameters for printing} \usage{ print_parameters( x, ..., split_by = c("Effects", "Component", "Group", "Response") ) } \arguments{ \item{x}{A fitted model, or a data frame returned by \code{\link{clean_parameters}}.} \item{...}{One or more objects (data frames), which contain information about the model parameters and related statistics (like confidence intervals, HDI, ROPE, ...).} \item{split_by}{\code{split_by} should be a character vector with one or more of the following elements: \code{"Effects"}, \code{"Component"}, \code{"Response"} and \code{"Group"}. These are the column names returned by \code{\link{clean_parameters}}, which is used to extract the information from which the group or component model parameters belong. If \code{NULL}, the merged data frame is returned. Else, the data frame is split into a list, split by the values from those columns defined in \code{split_by}.} } \value{ A data frame or a list of data frames (if \code{split_by} is not \code{NULL}). If a list is returned, the element names reflect the model components where the extracted information in the data frames belong to, e.g. \code{`random.zero_inflated.Intercept: persons`}. This is the data frame that contains the parameters for the random effects from group-level "persons" from the zero-inflated model component. } \description{ This function takes a data frame, typically a data frame with information on summaries of model parameters like \code{\link[bayestestR]{hdi}} or \code{\link[bayestestR]{equivalence_test}}, as input and splits this information into several parts, depending on the model. See details below. } \details{ This function prepares data frames that contain information about model parameters for clear printing. \cr \cr First, \code{x} is required, which should either be a model object or a prepared data frame as returned by \code{\link{clean_parameters}}. If \code{x} is a model, \code{clean_parameters()} is called on that model object to get information with which model components the parameters are associated. \cr \cr Then, \code{...} take one or more data frames that also contain information about parameters from the same model, but also have additional information provided by other methods. For instance, a data frame in \code{...} might be the result of \code{\link[bayestestR]{hdi}}, where we have a) a \code{Parameters} column and b) columns with the HDI values. \cr \cr Now we have a data frame with model parameters and information about the association to the different model components, a data frame with model parameters, and some summary statistics. \code{print_parameters()} then merges these data frames, so the statistic of interest (in our example: the HDI) is also associated with the different model components. The data frame is split into a list, so for a clear printing. Users can loop over this list and print each component for a better overview. Further, parameter names are "cleaned", if necessary, also for a cleaner print. See also 'Examples'. } \examples{ \dontrun{ library(bayestestR) model <- download_model("brms_zi_2") x <- hdi(model, effects = "all", component = "all") # hdi() returns a data frame; here we use only the informaton on # parameter names and HDI values tmp <- as.data.frame(x)[, 1:4] tmp # Based on the "split_by" argument, we get a list of data frames that # is split into several parts that reflect the model components. print_parameters(model, tmp) # This is the standard print()-method for "bayestestR::hdi"-objects. # For printing methods, it is easy to print complex summary statistics # in a clean way to the console by splitting the information into # different model components. x } } insight/man/link_function.Rd0000644000176200001440000000237513613301122015622 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/link_function.R \name{link_function} \alias{link_function} \alias{link_function.gamlss} \alias{link_function.betareg} \alias{link_function.DirichletRegModel} \title{Get link-function from model object} \usage{ link_function(x, ...) \method{link_function}{gamlss}(x, what = c("mu", "sigma", "nu", "tau"), ...) \method{link_function}{betareg}(x, what = c("mean", "precision"), ...) \method{link_function}{DirichletRegModel}(x, what = c("mean", "precision"), ...) } \arguments{ \item{x}{A fitted model.} \item{...}{Currently not used.} \item{what}{For \code{gamlss} models, indicates for which distribution parameter the link (inverse) function should be returned; for \code{betareg} or \code{DirichletRegModel}, can be \code{"mean"} or \code{"precision"}.} } \value{ A function, describing the link-function from a model-object. For multivariate-response models, a list of functions is returned. } \description{ Returns the link-function from a model object. } \examples{ # example from ?stats::glm counts <- c(18, 17, 15, 20, 10, 20, 25, 13, 12) outcome <- gl(3, 1, 9) treatment <- gl(3, 3) m <- glm(counts ~ outcome + treatment, family = poisson()) link_function(m)(.3) # same as log(.3) } insight/man/figures/0000755000176200001440000000000013446526427014153 5ustar liggesusersinsight/man/figures/logo.png0000644000176200001440000035720513446526427015635 0ustar liggesusersPNG  IHDR [u` pHYs\F\FCA IDATx U}dّb9&+ jȑ-U)IBt{7N^.3+&Sfv(h&Lb%js"9;Рs}|?U }ν{<ijjZcL1f;i'B*hbczgagMoVPe]TWʂ W J*ho5,_OcN^Z ZBƘ K8"aʮE"4`jF{L- Ǫ~"X(Bha#7nÃyحCD ز81̮hA^3+ 8JoA\ˎPmxF@Bk/# 4T\E˪~..S(qS*B@%kx@*ԙ%8nAh}lE@Sv }J 4D4N vh͵0#Qqea3  :v+(ae.^N@Lj!\ 0@~`D(;fD# !=C ARoAToyn67tׇ#7/}j{6+ #,˯7y$ԥfIwp/S(a{ Uo]r'̏Wnpoglx@ xSo`Trz7I9n^#4xﳿ؊z z/&=mYx\4䨂6eð|7~2~"4xFOr0 f,{><u>"4xhO_GnsﭾӇ̟EinYAaV^[П6&' Mכt}[GhZY @[ʦ- <)uPX#4t8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#4eEcy)_Y|((t +Kx𮂳 Eh:N# kЉ+72?}_ŗЩƲB$4ΥW4^- `ӲY8{nBȴl)J~Hg 4MvW`, value = 0, color_if = "green", color_else = "red", digits = 2 ) colour_if( x, columns, predicate = `>`, value = 0, colour_if = "green", colour_else = "red", digits = 2 ) } \arguments{ \item{x}{A data frame} \item{columns}{Character vector with column names of \code{x} that should be formatted.} \item{predicate}{A function that takes \code{columns} and \code{value} as input and which should return \code{TRUE} or \code{FALSE}, based on if the condition (in comparison with \code{value}) is met.} \item{value}{The comparator. May be used in conjunction with \code{predicate} to quickly set up a function which compares elements in \code{colums} to \code{value}. May be ignored when \code{predicate} is a function that internally computes other comparisons. See 'Examples'.} \item{color_if, colour_if}{Character vector, indicating the color code used to format values in \code{x} that meet the condition of \code{predicate} and \code{value}. May be one of \code{"red"}, \code{"yellow"}, \code{"green"}, \code{"blue"}, \code{"violet"}, \code{"cyan"} or \code{"grey"}. Formatting is also possible with \code{"bold"} or \code{"italic"}.} \item{color_else, colour_else}{See \code{color_if}, but only for conditions that are \emph{not} met.} \item{digits}{Digits for rounded values.} } \value{ The . } \description{ Convenient function that formats columns in data frames with color codes, where the color is chosen based on certain conditions. Columns are then printed in color in the console. } \details{ The predicate-function simply works like this: \code{which(predicate(x[, columns], value))} } \examples{ # all values in Sepal.Length larger than 5 in green, all remaining in red x <- color_if(iris[1:10, ], columns = "Sepal.Length", predicate = `>`, value = 5) x cat(x$Sepal.Length) # all levels "setosa" in Species in green, all remaining in red x <- color_if(iris, columns = "Species", predicate = `==`, value = "setosa") cat(x$Species) # own function, argument "value" not needed here p <- function(x, y) { x >= 4.9 & x <= 5.1 } # all values in Sepal.Length between 4.9 and 5.1 in green, all remaining in red x <- color_if(iris[1:10, ], columns = "Sepal.Length", predicate = p) cat(x$Sepal.Length) } insight/man/link_inverse.Rd0000644000176200001440000000241213613301122015440 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/link_inverse.R \name{link_inverse} \alias{link_inverse} \alias{link_inverse.betareg} \alias{link_inverse.DirichletRegModel} \alias{link_inverse.gamlss} \title{Get link-inverse function from model object} \usage{ link_inverse(x, ...) \method{link_inverse}{betareg}(x, what = c("mean", "precision"), ...) \method{link_inverse}{DirichletRegModel}(x, what = c("mean", "precision"), ...) \method{link_inverse}{gamlss}(x, what = c("mu", "sigma", "nu", "tau"), ...) } \arguments{ \item{x}{A fitted model.} \item{...}{Currently not used.} \item{what}{For \code{gamlss} models, indicates for which distribution parameter the link (inverse) function should be returned; for \code{betareg} or \code{DirichletRegModel}, can be \code{"mean"} or \code{"precision"}.} } \value{ A function, describing the inverse-link function from a model-object. For multivariate-response models, a list of functions is returned. } \description{ Returns the link-inverse function from a model object. } \examples{ # example from ?stats::glm counts <- c(18, 17, 15, 20, 10, 20, 25, 13, 12) outcome <- gl(3, 1, 9) treatment <- gl(3, 3) m <- glm(counts ~ outcome + treatment, family = poisson()) link_inverse(m)(.3) # same as exp(.3) } insight/man/n_obs.Rd0000644000176200001440000000165713566471215014104 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/n_obs.R \name{n_obs} \alias{n_obs} \alias{n_obs.svyolr} \alias{n_obs.stanmvreg} \title{Get number of observations from a model} \usage{ n_obs(x, ...) \method{n_obs}{svyolr}(x, weighted = FALSE, ...) \method{n_obs}{stanmvreg}(x, select = NULL, ...) } \arguments{ \item{x}{A fitted model.} \item{...}{Currently not used.} \item{weighted}{For survey designs, returns the weighted sample size.} \item{select}{Optional name(s) of response variables for which to extract values. Can be used in case of regression models with multiple response variables.} } \value{ The number of observations used to fit the model, or \code{NULL} if this information is not available. } \description{ This method returns the number of observation that were used to fit the model, as numeric value. } \examples{ data(mtcars) m <- lm(mpg ~ wt + cyl + vs, data = mtcars) n_obs(m) } insight/man/get_response.Rd0000644000176200001440000000203013566471215015463 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_response.R \name{get_response} \alias{get_response} \title{Get the values from the response variable} \usage{ get_response(x, select = NULL) } \arguments{ \item{x}{A fitted model.} \item{select}{Optional name(s) of response variables for which to extract values. Can be used in case of regression models with multiple response variables.} } \value{ The values of the response variable, as vector, or a data frame if \code{x} has more than one defined response variable. } \description{ Returns the values the response variable(s) from a model object. If the model is a multivariate response model, a data frame with values from all response variables is returned. } \examples{ library(lme4) data(cbpp) data(mtcars) cbpp$trials <- cbpp$size - cbpp$incidence m <- glm(cbind(incidence, trials) ~ period, data = cbpp, family = binomial) head(get_response(m)) get_response(m, select = "incidence") m <- lm(mpg ~ wt + cyl + vs, data = mtcars) get_response(m) } insight/man/dot-colour_detect.Rd0000644000176200001440000000037213615562325016412 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/color_if.R \name{.colour_detect} \alias{.colour_detect} \title{Detect coloured cells} \usage{ .colour_detect(x) } \description{ Detect coloured cells } \keyword{internal} insight/man/get_random.Rd0000644000176200001440000000151313566471215015112 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_random.R \name{get_random} \alias{get_random} \title{Get the data from random effects} \usage{ get_random(x) } \arguments{ \item{x}{A fitted mixed model.} } \value{ The data from all random effects terms, as data frame. Or \code{NULL} if model has no random effects. } \description{ Returns the data from all random effects terms. } \examples{ library(lme4) data(sleepstudy) # prepare some data... sleepstudy$mygrp <- sample(1:5, size = 180, replace = TRUE) sleepstudy$mysubgrp <- NA for (i in 1:5) { filter_group <- sleepstudy$mygrp == i sleepstudy$mysubgrp[filter_group] <- sample(1:30, size = sum(filter_group), replace = TRUE) } m <- lmer( Reaction ~ Days + (1 | mygrp / mysubgrp) + (1 | Subject), data = sleepstudy ) head(get_random(m)) } insight/man/format_value.Rd0000644000176200001440000000246713615554000015455 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/format_value.R \name{format_value} \alias{format_value} \title{Numeric Values Formatting} \usage{ format_value( x, digits = 2, protect_integers = FALSE, missing = "", width = NULL, as_percent = FALSE, ... ) } \arguments{ \item{x}{Numeric value.} \item{digits}{Number of significant digits.} \item{protect_integers}{Should integers be kept as integers (i.e., without decimals)?} \item{missing}{Value by which \code{NA} values are replaced. By default, an empty string (i.e. \code{""}) is returned for \code{NA}.} \item{width}{Minimum width of the returned string. If not \code{NULL} and \code{width} is larger than the string's length, leading whitespaces are added to the string.} \item{as_percent}{Logical, if \code{TRUE}, value is formatted as percentage value.} \item{...}{Arguments passed to or from other methods.} } \value{ A formatted string. } \description{ Numeric Values Formatting } \examples{ format_value(1.20) format_value(1.2) format_value(1.2012313) format_value(c(0.0045, 234, -23)) format_value(c(0.0045, .12, .34)) format_value(c(0.0045, .12, .34), as_percent = TRUE) format_value(as.factor(c("A", "B", "A"))) format_value(iris$Species) format_value(3) format_value(3, protect_integers = TRUE) format_value(iris) } insight/man/find_formula.Rd0000644000176200001440000000416313613250326015433 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/find_formula.R \name{find_formula} \alias{find_formula} \title{Find model formula} \usage{ find_formula(x, ...) } \arguments{ \item{x}{A fitted model.} \item{...}{Currently not used.} } \value{ A list of formulas that describe the model. For simple models, only one list-element, \code{conditional}, is returned. For more complex models, the returned list may have following elements: \itemize{ \item \code{conditional}, the "fixed effects" part from the model. One exception are \code{DirichletRegModel} models from \pkg{DirichletReg}, which has two or three components, depending on \code{model}. \item \code{random}, the "random effects" part from the model (or the \code{id} for gee-models and similar) \item \code{zero_inflated}, the "fixed effects" part from the zero-inflation component of the model \item \code{zero_inflated_random}, the "random effects" part from the zero-inflation component of the model \item \code{dispersion}, the dispersion formula \item \code{instruments}, for fixed-effects regressions like \code{ivreg}, \code{felm} or \code{plm}, the instrumental variables \item \code{cluster}, for fixed-effects regressions like \code{felm}, the cluster specification \item \code{correlation}, for models with correlation-component like \code{gls}, the formula that describes the correlation structure \item \code{slopes}, for fixed-effects individual-slope models like \code{feis}, the formula for the slope parameters \item \code{precision}, for \code{DirichletRegModel} models from \pkg{DirichletReg}, when parametrization (i.e. \code{model}) is \code{"alternative"}. } } \description{ Returns the formula(s) for the different parts of a model (like fixed or random effects, zero-inflated component, ...). } \note{ For models of class \code{lme} or \code{gls} the correlation-component is only returned, when it is explicitly defined as named argument (\code{form}), e.g. \code{corAR1(form = ~1 | Mare)} } \examples{ data(mtcars) m <- lm(mpg ~ wt + cyl + vs, data = mtcars) find_formula(m) } insight/man/get_parameters.Rd0000644000176200001440000001332513613301122015757 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_parameters.R \name{get_parameters} \alias{get_parameters} \alias{get_parameters.rqss} \alias{get_parameters.cgam} \alias{get_parameters.betareg} \alias{get_parameters.DirichletRegModel} \alias{get_parameters.clm2} \alias{get_parameters.coxme} \alias{get_parameters.merMod} \alias{get_parameters.lme} \alias{get_parameters.mixed} \alias{get_parameters.MixMod} \alias{get_parameters.glmmTMB} \alias{get_parameters.BBmm} \alias{get_parameters.glimML} \alias{get_parameters.gamm} \alias{get_parameters.Gam} \alias{get_parameters.gam} \alias{get_parameters.vgam} \alias{get_parameters.zeroinfl} \alias{get_parameters.aovlist} \alias{get_parameters.MCMCglmm} \alias{get_parameters.BFBayesFactor} \alias{get_parameters.stanmvreg} \alias{get_parameters.brmsfit} \alias{get_parameters.stanreg} \alias{get_parameters.sim.merMod} \title{Get model parameters} \usage{ get_parameters(x, ...) \method{get_parameters}{rqss}(x, component = c("all", "conditional", "smooth_terms"), ...) \method{get_parameters}{cgam}(x, component = c("all", "conditional", "smooth_terms"), ...) \method{get_parameters}{betareg}(x, component = c("all", "conditional", "precision"), ...) \method{get_parameters}{DirichletRegModel}(x, component = c("all", "conditional", "precision"), ...) \method{get_parameters}{clm2}(x, component = c("all", "conditional", "scale"), ...) \method{get_parameters}{coxme}(x, effects = c("fixed", "random"), ...) \method{get_parameters}{merMod}(x, effects = c("fixed", "random"), ...) \method{get_parameters}{lme}(x, effects = c("fixed", "random"), ...) \method{get_parameters}{mixed}(x, effects = c("fixed", "random"), ...) \method{get_parameters}{MixMod}( x, effects = c("fixed", "random"), component = c("all", "conditional", "zi", "zero_inflated", "dispersion"), ... ) \method{get_parameters}{glmmTMB}( x, effects = c("fixed", "random"), component = c("all", "conditional", "zi", "zero_inflated", "dispersion"), ... ) \method{get_parameters}{BBmm}(x, effects = c("fixed", "random"), ...) \method{get_parameters}{glimML}(x, effects = c("fixed", "random", "all"), ...) \method{get_parameters}{gamm}(x, component = c("all", "conditional", "smooth_terms"), ...) \method{get_parameters}{Gam}(x, component = c("all", "conditional", "smooth_terms"), ...) \method{get_parameters}{gam}(x, component = c("all", "conditional", "smooth_terms"), ...) \method{get_parameters}{vgam}(x, component = c("all", "conditional", "smooth_terms"), ...) \method{get_parameters}{zeroinfl}( x, component = c("all", "conditional", "zi", "zero_inflated"), ... ) \method{get_parameters}{aovlist}(x, effects = c("fixed", "random", "all"), ...) \method{get_parameters}{MCMCglmm}(x, effects = c("fixed", "random", "all"), ...) \method{get_parameters}{BFBayesFactor}( x, effects = c("all", "fixed", "random"), component = c("all", "extra"), iterations = 4000, progress = FALSE, ... ) \method{get_parameters}{stanmvreg}( x, effects = c("fixed", "random", "all"), parameters = NULL, ... ) \method{get_parameters}{brmsfit}( x, effects = c("fixed", "random", "all"), component = c("all", "conditional", "zi", "zero_inflated", "dispersion", "simplex", "sigma", "smooth_terms"), parameters = NULL, ... ) \method{get_parameters}{stanreg}( x, effects = c("fixed", "random", "all"), parameters = NULL, ... ) \method{get_parameters}{sim.merMod}( x, effects = c("fixed", "random", "all"), parameters = NULL, ... ) } \arguments{ \item{x}{A fitted model.} \item{...}{Currently not used.} \item{component}{Should all parameters, parameters for the conditional model, the zero-inflated part of the model, the dispersion term or the instrumental variables be returned? Applies to models with zero-inflated and/or dispersion formula, or to models with instrumental variable (so called fixed-effects regressions). May be abbreviated. Note that the \emph{conditional} component is also called \emph{count} or \emph{mean} component, depending on the model.} \item{effects}{Should parameters for fixed effects, random effects or both be returned? Only applies to mixed models. May be abbreviated.} \item{iterations}{Number of posterior draws.} \item{progress}{Display progress.} \item{parameters}{Regular expression pattern that describes the parameters that should be returned.} } \value{ \itemize{ \item for non-Bayesian models and if \code{effects = "fixed"}, a data frame with two columns: the parameter names and the related point estimates \item if \code{effects = "random"}, a list of data frames with the random effects (as returned by \code{ranef()}), unless the random effects have the same simplified structure as fixed effects (e.g. for models from \pkg{MCMCglmm}) \item for Bayesian models, the posterior samples from the requested parameters as data frame \item for Anova (\code{aov()}) with error term, a list of parameters for the conditional and the random effects parameters \item for models with smooth terms or zero-inflation component, a data frame with three columns: the parameter names, the related point estimates and the component } } \description{ Returns the coefficients (or posterior samples for Bayesian models) from a model. } \details{ In most cases when models either return different "effects" (fixed, random) or "components" (conditional, zero-inflated, ...), the arguments \code{effects} and \code{component} can be used. \cr \cr \code{get_parameters()} is comparable to \code{coef()}, however, the coefficients are returned as data frame (with columns for names and point estimates of coefficients). For Bayesian models, the posterior samples of parameters are returned. } \examples{ data(mtcars) m <- lm(mpg ~ wt + cyl + vs, data = mtcars) get_parameters(m) } insight/man/get_data.Rd0000644000176200001440000000610013602432505014526 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_data.R \name{get_data} \alias{get_data} \alias{get_data.gee} \alias{get_data.rqss} \alias{get_data.hurdle} \alias{get_data.glmmTMB} \alias{get_data.merMod} \alias{get_data.glmmadmb} \alias{get_data.rlmerMod} \alias{get_data.clmm} \alias{get_data.mixed} \alias{get_data.lme} \alias{get_data.MixMod} \alias{get_data.brmsfit} \alias{get_data.stanreg} \alias{get_data.MCMCglmm} \title{Get the data that was used to fit the model} \usage{ get_data(x, ...) \method{get_data}{gee}(x, effects = c("all", "fixed", "random"), ...) \method{get_data}{rqss}(x, component = c("all", "conditional", "smooth_terms"), ...) \method{get_data}{hurdle}( x, component = c("all", "conditional", "zi", "zero_inflated", "dispersion"), ... ) \method{get_data}{glmmTMB}( x, effects = c("all", "fixed", "random"), component = c("all", "conditional", "zi", "zero_inflated", "dispersion"), ... ) \method{get_data}{merMod}(x, effects = c("all", "fixed", "random"), ...) \method{get_data}{glmmadmb}(x, effects = c("all", "fixed", "random"), ...) \method{get_data}{rlmerMod}(x, effects = c("all", "fixed", "random"), ...) \method{get_data}{clmm}(x, effects = c("all", "fixed", "random"), ...) \method{get_data}{mixed}(x, effects = c("all", "fixed", "random"), ...) \method{get_data}{lme}(x, effects = c("all", "fixed", "random"), ...) \method{get_data}{MixMod}( x, effects = c("all", "fixed", "random"), component = c("all", "conditional", "zi", "zero_inflated", "dispersion"), ... ) \method{get_data}{brmsfit}( x, effects = c("all", "fixed", "random"), component = c("all", "conditional", "zi", "zero_inflated"), ... ) \method{get_data}{stanreg}(x, effects = c("all", "fixed", "random"), ...) \method{get_data}{MCMCglmm}(x, effects = c("all", "fixed", "random"), ...) } \arguments{ \item{x}{A fitted model.} \item{...}{Currently not used.} \item{effects}{Should model data for fixed effects, random effects or both be returned? Only applies to mixed models.} \item{component}{Should all predictor variables, predictor variables for the conditional model, the zero-inflated part of the model, the dispersion term or the instrumental variables be returned? Applies to models with zero-inflated and/or dispersion formula, or to models with instrumental variable (so called fixed-effects regressions). May be abbreviated. Note that the \emph{conditional} component is also called \emph{count} or \emph{mean} component, depending on the model.} } \value{ The data that was used to fit the model. } \description{ This functions tries to get the data that was used to fit the model and returns it as data frame. } \note{ Unlike \code{model.frame()}, which may contain transformed variables (e.g. if \code{poly()} or \code{scale()} was used inside the formula to specify the model), \code{get_data()} aims at returning the "original", untransformed data. } \examples{ data(cbpp, package = "lme4") cbpp$trials <- cbpp$size - cbpp$incidence m <- glm(cbind(incidence, trials) ~ period, data = cbpp, family = binomial) head(get_data(m)) } insight/man/get_predictors.Rd0000644000176200001440000000073413615562325016012 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_predictors.R \name{get_predictors} \alias{get_predictors} \title{Get the data from model predictors} \usage{ get_predictors(x) } \arguments{ \item{x}{A fitted model.} } \value{ The data from all predictor variables, as data frame. } \description{ Returns the data from all predictor variables (fixed effects). } \examples{ m <- lm(mpg ~ wt + cyl + vs, data = mtcars) head(get_predictors(m)) } insight/DESCRIPTION0000644000176200001440000000507613615601156013441 0ustar liggesusersPackage: insight Type: Package Title: Easy Access to Model Information for Various Model Objects Description: A tool to provide an easy, intuitive and consistent access to information contained in various R models, like model formulas, model terms, information about random effects, data that was used to fit the model or data from response variables. 'insight' mainly revolves around two types of functions: Functions that find (the names of) information, starting with 'find_', and functions that get the underlying data, starting with 'get_'. The package has a consistent syntax and works with many different model objects, where otherwise functions to access these information are missing. Version: 0.8.1 Authors@R: c(person("Daniel", "Lüdecke", role = c("aut", "cre"), email = "d.luedecke@uke.de", comment = c(ORCID = "0000-0002-8895-3206")), person("Dominique", "Makowski", role = c("aut", "ctb"), email = "dom.makowski@gmail.com", comment = c(ORCID = "0000-0001-5375-9967")), person("Indrajeet", "Patil", role = c("aut", "ctb"), email = "patilindrajeet.science@gmail.com", comment = c(ORCID = "0000-0003-1995-6531")), person("Philip", "Waggoner", role = c("aut", "ctb"), email = "philip.waggoner@gmail.com", comment = c(ORCID = "0000-0002-7825-7573"))) Maintainer: Daniel Lüdecke License: GPL-3 URL: https://easystats.github.io/insight/ BugReports: https://github.com/easystats/insight/issues Depends: R (>= 3.2) Imports: methods, stats, utils Suggests: AER, afex, aod, BayesFactor, bayestestR, betareg, biglm, blavaan, blme, brms, censReg, cgam, coxme, cplm, crch, estimatr, feisr, fixest, gam, gamm4, gamlss, gbm, gee, geepack, GLMMadaptive, glmmTMB, gmnl, HRQoL, httr, lavaan, lfe, logistf, MASS, Matrix, MCMCglmm, mlogit, multgee, lme4, mgcv, nnet, nlme, ordinal, panelr, plm, pscl, quantreg, rms, robustbase, robustlmm, rstanarm, rstudioapi, speedglm, splines, statmod, survey, survival, tripack, truncreg, testthat, VGAM, knitr, rmarkdown, spelling Encoding: UTF-8 LazyData: true RoxygenNote: 7.0.2 VignetteBuilder: knitr Language: en-US NeedsCompilation: no Packaged: 2020-02-02 15:04:24 UTC; Daniel Author: Daniel Lüdecke [aut, cre] (), Dominique Makowski [aut, ctb] (), Indrajeet Patil [aut, ctb] (), Philip Waggoner [aut, ctb] () Repository: CRAN Date/Publication: 2020-02-02 17:10:06 UTC insight/build/0000755000176200001440000000000013615562367013034 5ustar liggesusersinsight/build/vignette.rds0000644000176200001440000000030313615562367015367 0ustar liggesusersb```b`fcb`b2 1# '+L( MAbJ tdqM, (&$y楀aM wjey~L6̜T!%ps QY_/( @hrNb1GRKҊA>insight/build/partial.rdb0000644000176200001440000002437113615562364015165 0ustar liggesusers}k{I| R80`d%P6j TQ :-R̔Tmmuzzw{v~;ϳG}Lo+9$e "2%3$ﱝ9qΉsNDF>b]."ub]gݟz?w]<j)e2_oo<˚0f5XTlȘYبр=W횯[|Cj>h%_p%?~9+v;\y4u#el5}8|b+Q(R%y(zrM)'_x6g9g/\|;%566FrCu^l)5yl HXZnojjn8X1PXGǺזW;TS$%iU(fL3XJv" uu'BN- $U% >[J^|KӗmM"l]qv|J+|;@i$a0ya-*z`£B= 1Zo!bC\YhB94.#-0Oy$7]q+"@n4l BO}zO/l tH+&}QqEd#UjciE]ln>XWDV:Tk8ۨ-5 ڨv!=z5d]FljeԂ#hh9[D0\C5™hRQiOy{`fA4 2V 1V qm0Jɘ^f_tW}AVgZo+bWD:ܕXLC5,3JqSs95.ofULF8z.B9d[o>4w'֒4p Z覝bNRzהMszflB\Gx Т0Z릭6XK=Y]BlcDBX^Ǘ!B 9!,`N ymBqܷz=IFW!F؂=P]hQ}!OZSG a J7rpz:SSV-/S;BUUҽ*OGLNaX@IZ]fmP;Bu}U0[Q) s ^'C<dF[J!j;  㠥YuV6rv6jb!.ɬz08gb;eKRj_㵠XW7XPBBhR1ȑ{Қآϴb:kj@{u#T@; %=,5b][T,%lKы$ӌqkc9Oy0{,YQ]S#F+WB|q]e-C&mUsJQw&^?6pb)7lh9-q;j|[ңk=y.':yPǁ@p˸q@i\Y*"e),5SM">B[).@? -PDyvqXdžmդe*}4l|Эam ˩fL#k3dE݀_ BD%bYm1qZ$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_~nް{n)NJUUϳFn~-_֓ƒO ӻV,Wm2n 5)ZIzVm}ߕֳklnP"=5\:u_Sl3S/KT_O0zzyhenP;&vu`)U#:+#OD'U`Й˱cw5mX )GtU' }8<`邒y6AtY L3 zLv۫;[ニ ^pqMy9>- atn',]O]),c>bHgǍ>U~_I +Vfx?:;e08\I=L2LMLb6io*Le1ioh(类kg'6$izH(n)of="ɔ/<^Kɔ 3.gsIͰMM^7EtK}e>Q]IIXuUb%?97+ ӊv?OWԧ\C7477o(m~oyS"|8v΃nen Qӷiaޜk&w>wRGbͬWS7zp-oka݉ԔEz6[wmv4"ix;qlkIת#h 40@kQV*>y9(N zxoezK5EQh躸`MB/A?llۉVS+kˏF 8!Xq'zw}Ta(Dk*(U[?A#+1vY$ZIx)+"p-'̂F>RPu$w?l$,*)N TԂzAZ2oя Tinsight/tests/0000755000176200001440000000000013563552732013074 5ustar liggesusersinsight/tests/spelling.R0000644000176200001440000000024013563552732015030 0ustar liggesusersif (requireNamespace("spelling", quietly = TRUE)) { spelling::spell_check_test( vignettes = TRUE, error = FALSE, skip_on_cran = TRUE ) } insight/tests/testthat/0000755000176200001440000000000013615601156014725 5ustar liggesusersinsight/tests/testthat/test-gamlss.R0000644000176200001440000000537213531007236017316 0ustar liggesusersif (require("testthat") && require("insight") && require("gamlss")) { context("insight, model_info") data(abdom) m1 <- gamlss( y ~ pb(x), sigma.formula = ~ pb(x), family = BCT, data = abdom, method = mixed(1, 20) ) test_that("model_info", { expect_true(model_info(m1)$is_linear) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = "x", sigma = "x")) expect_identical(find_predictors(m1, flatten = TRUE), "x") expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "y") }) test_that("get_response", { expect_equal(get_response(m1), abdom$y) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), "x") }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 610) expect_equal(colnames(get_data(m1)), c("y", "x")) }) test_that("find_formula", { expect_length(find_formula(m1), 4) expect_equal( find_formula(m1), list( conditional = as.formula("y ~ pb(x)"), sigma = as.formula("~pb(x)"), nu = as.formula("~1"), tau = as.formula("~1") ) ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "y", conditional = "x", sigma = "x" ) ) expect_equal(find_variables(m1, flatten = TRUE), c("y", "x")) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "y", conditional = "pb(x)", sigma = "pb(x)", nu = "1", tau = "1" ) ) }) test_that("n_obs", { expect_equal(n_obs(m1), 610) }) test_that("link_function", { expect_equal(link_function(m1)(.2), .2, tolerance = 1e-5) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "pb(x)"), sigma = c("(Intercept)", "pb(x)"), nu = "(Intercept)", tau = "(Intercept)" ) ) expect_equal(nrow(get_parameters(m1)), 6) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_algorithm", { expect_equal(find_algorithm(m1), list(algorithm = "mixed")) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") }) } insight/tests/testthat/test-clmm.R0000644000176200001440000001237513531713511016761 0ustar liggesusersif (require("testthat") && require("insight") && require("ordinal")) { context("insight, model_info") data(wine, package = "ordinal") data(soup) m1 <- clmm(rating ~ temp + contact + (1 | judge), data = wine) m2 <- clmm(SURENESS ~ PROD + (1 | RESP) + (1 | RESP:PROD), data = soup, link = "probit", threshold = "equidistant" ) test_that("model_info", { expect_true(model_info(m1)$is_ordinal) expect_true(model_info(m2)$is_ordinal) expect_true(model_info(m1)$is_logit) expect_true(model_info(m2)$is_probit) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("temp", "contact"))) expect_identical( find_predictors(m1, effects = "all"), list( conditional = c("temp", "contact"), random = "judge" ) ) expect_identical( find_predictors(m1, effects = "all", flatten = TRUE), c("temp", "contact", "judge") ) expect_identical(find_predictors(m2), list(conditional = "PROD")) expect_identical( find_predictors(m2, effects = "all"), list( conditional = "PROD", random = c("RESP", "PROD") ) ) expect_identical( find_predictors(m2, effects = "all", flatten = TRUE), c("PROD", "RESP") ) }) test_that("find_random", { expect_equal(find_random(m1), list(random = "judge")) expect_equal(find_random(m2), list(random = c("RESP", "RESP:PROD"))) expect_equal(find_random(m2, split_nested = TRUE), list(random = c("RESP", "PROD"))) }) test_that("get_random", { expect_equal(get_random(m1), wine[, "judge", drop = FALSE]) expect_equal(get_random(m2), soup[, c("RESP", "PROD"), drop = FALSE]) }) test_that("find_response", { expect_identical(find_response(m1), "rating") expect_identical(find_response(m2), "SURENESS") }) test_that("get_response", { expect_equal(get_response(m1), wine$rating) expect_equal(get_response(m2), soup$SURENESS) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("temp", "contact")) expect_equal(colnames(get_predictors(m2)), "PROD") }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), plogis(.2), tolerance = 1e-5) expect_equal(link_inverse(m2)(.2), pnorm(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 72) expect_equal( colnames(get_data(m1)), c("rating", "temp", "contact", "judge") ) expect_equal(nrow(get_data(m2)), 1847) expect_equal(colnames(get_data(m2)), c("SURENESS", "PROD", "RESP")) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_equal( find_formula(m1), list( conditional = as.formula("rating ~ temp + contact"), random = as.formula("~1 | judge") ) ) expect_length(find_formula(m2), 2) expect_equal( find_formula(m2), list( conditional = as.formula("SURENESS ~ PROD"), random = list(as.formula("~1 | RESP"), as.formula("~1 | RESP:PROD")) ) ) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "rating", conditional = c("temp", "contact"), random = "judge" ) ) expect_equal( find_terms(m1, flatten = TRUE), c("rating", "temp", "contact", "judge") ) expect_equal( find_terms(m2), list( response = "SURENESS", conditional = "PROD", random = c("RESP", "PROD") ) ) expect_equal( find_terms(m2, flatten = TRUE), c("SURENESS", "PROD", "RESP") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 72) expect_equal(n_obs(m2), 1847) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) expect_false(is.null(link_function(m2))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("1|2", "2|3", "3|4", "4|5", "tempwarm", "contactyes") ) ) expect_equal( find_parameters(m2), list(conditional = c("threshold.1", "spacing", "PRODTest")) ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) expect_false(is_multivariate(m2)) }) test_that("get_variance", { expect_equal( get_variance(m1), list( var.fixed = 3.23207765938872, var.random = 1.27946088209319, var.residual = 3.28986813369645, var.distribution = 3.28986813369645, var.dispersion = 0, var.intercept = c(judge = 1.27946088209319) ), tolerance = 1e-4 ) expect_equal( get_variance(m2), list( var.fixed = 0.132313576370902, var.random = 0.193186321588604, var.residual = 1, var.distribution = 1, var.dispersion = 0, var.intercept = c(`RESP:PROD` = 0.148265480396059, RESP = 0.0449208411925493) ), tolerance = 1e-4 ) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") expect_identical(find_statistic(m2), "z-statistic") }) } insight/tests/testthat/test-Gam2.R0000644000176200001440000000474313552364343016627 0ustar liggesusersif (require("testthat") && require("insight") && require("gam")) { context("insight, gam") data(kyphosis) m1 <- gam::gam( Kyphosis ~ s(Age, 4) + Number, family = binomial, data = kyphosis, trace = TRUE ) test_that("model_info", { expect_true(model_info(m1)$is_binomial) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("Age", "Number"))) expect_identical(find_predictors(m1, flatten = TRUE), c("Age", "Number")) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_response", { expect_identical(find_response(m1), "Kyphosis") }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), plogis(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 81) expect_equal(colnames(get_data(m1)), c("Kyphosis", "Age", "Number")) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("Kyphosis ~ s(Age, 4) + Number")) ) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "Kyphosis", conditional = c("s(Age, 4)", "Number") ) ) expect_equal( find_terms(m1, flatten = TRUE), c("Kyphosis", "s(Age, 4)", "Number") ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "Kyphosis", conditional = c("Age", "Number") ) ) expect_equal( find_variables(m1, flatten = TRUE), c("Kyphosis", "Age", "Number") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 81) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "Number"), smooth_terms = "s(Age, 4)" ) ) expect_equal(nrow(get_parameters(m1)), 3) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "Number", "s(Age, 4)") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_algorithm", { expect_equal(find_algorithm(m1), list(algorithm = "IWLS")) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "F-statistic") }) } insight/tests/testthat/test-geeglm.R0000644000176200001440000000552613552364343017301 0ustar liggesusersif (require("testthat") && require("insight") && require("geepack")) { context("insight, model_info") data(warpbreaks) m1 <- geeglm( breaks ~ tension, id = wool, data = warpbreaks, family = poisson, corstr = "ar1" ) test_that("model_info", { expect_true(model_info(m1)$is_count) expect_false(model_info(m1)$is_linear) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = "tension")) expect_identical(find_predictors(m1, flatten = TRUE), "tension") expect_identical( find_predictors(m1, effects = "random"), list(random = "wool") ) expect_identical( find_predictors(m1, effects = "all", flatten = TRUE), c("tension", "wool") ) }) test_that("find_response", { expect_identical(find_response(m1), "breaks") }) test_that("get_response", { expect_equal(get_response(m1), warpbreaks$breaks) }) test_that("find_random", { expect_equal(find_random(m1), list(random = "wool")) }) test_that("get_random", { expect_equal(get_random(m1), warpbreaks[, "wool", drop = FALSE]) }) test_that("get_predictors", { expect_equal(get_predictors(m1), warpbreaks[, "tension", drop = FALSE]) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), exp(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 54) expect_equal(colnames(get_data(m1)), c("breaks", "tension", "wool")) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_equal( find_formula(m1), list( conditional = as.formula("breaks ~ tension"), random = as.formula("~wool") ) ) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "breaks", conditional = "tension", random = "wool" ) ) expect_equal( find_terms(m1, flatten = TRUE), c("breaks", "tension", "wool") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 54) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list(conditional = c( "(Intercept)", "tensionM", "tensionH" )) ) expect_equal(nrow(get_parameters(m1)), 3) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "tensionM", "tensionH") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_algorithm", { expect_equal(find_algorithm(m1), list(algorithm = "ML")) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "chi-squared statistic") }) } insight/tests/testthat/test-lmer.R0000644000176200001440000002613013552364343016772 0ustar liggesusersif (require("testthat") && require("insight") && require("lme4")) { context("insight, find_predictors") data(sleepstudy) set.seed(123) sleepstudy$mygrp <- sample(1:5, size = 180, replace = TRUE) sleepstudy$mysubgrp <- NA for (i in 1:5) { filter_group <- sleepstudy$mygrp == i sleepstudy$mysubgrp[filter_group] <- sample(1:30, size = sum(filter_group), replace = TRUE) } m1 <- lme4::lmer(Reaction ~ Days + (1 + Days | Subject), data = sleepstudy ) m2 <- lme4::lmer(Reaction ~ Days + (1 | mygrp / mysubgrp) + (1 | Subject), data = sleepstudy ) test_that("model_info", { expect_true(model_info(m1)$is_linear) expect_true(model_info(m2)$is_linear) }) test_that("find_predictors", { expect_equal( find_predictors(m1, effects = "all"), list(conditional = "Days", random = "Subject") ) expect_equal( find_predictors(m1, effects = "all", flatten = TRUE), c("Days", "Subject") ) expect_equal( find_predictors(m1, effects = "fixed"), list(conditional = "Days") ) expect_equal( find_predictors(m1, effects = "fixed", flatten = TRUE), "Days" ) expect_equal( find_predictors(m1, effects = "random"), list(random = "Subject") ) expect_equal( find_predictors(m1, effects = "random", flatten = TRUE), "Subject" ) expect_equal( find_predictors(m2, effects = "all"), list( conditional = "Days", random = c("mysubgrp", "mygrp", "Subject") ) ) expect_equal( find_predictors(m2, effects = "all", flatten = TRUE), c("Days", "mysubgrp", "mygrp", "Subject") ) expect_equal( find_predictors(m2, effects = "fixed"), list(conditional = "Days") ) expect_equal(find_predictors(m2, effects = "random"), list(random = c("mysubgrp", "mygrp", "Subject"))) expect_null(find_predictors(m2, effects = "all", component = "zi")) expect_null(find_predictors(m2, effects = "fixed", component = "zi")) expect_null(find_predictors(m2, effects = "random", component = "zi")) }) test_that("find_random", { expect_equal(find_random(m1), list(random = "Subject")) expect_equal(find_random(m1, flatten = TRUE), "Subject") expect_equal(find_random(m2), list(random = c("mysubgrp:mygrp", "mygrp", "Subject"))) expect_equal(find_random(m2, split_nested = TRUE), list(random = c("mysubgrp", "mygrp", "Subject"))) expect_equal( find_random(m2, flatten = TRUE), c("mysubgrp:mygrp", "mygrp", "Subject") ) expect_equal( find_random(m2, split_nested = TRUE, flatten = TRUE), c("mysubgrp", "mygrp", "Subject") ) }) test_that("find_response", { expect_identical(find_response(m1), "Reaction") expect_identical(find_response(m2), "Reaction") }) test_that("get_response", { expect_equal(get_response(m1), sleepstudy$Reaction) }) test_that("link_inverse", { expect_identical(link_inverse(m1)(.2), .2) expect_identical(link_inverse(m2)(.2), .2) }) test_that("get_data", { expect_equal(colnames(get_data(m1)), c("Reaction", "Days", "Subject")) expect_equal(colnames(get_data(m1, effects = "all")), c("Reaction", "Days", "Subject")) expect_equal(colnames(get_data(m1, effects = "random")), "Subject") expect_equal( colnames(get_data(m2)), c("Reaction", "Days", "mygrp", "mysubgrp", "Subject") ) expect_equal( colnames(get_data(m2, effects = "all")), c("Reaction", "Days", "mygrp", "mysubgrp", "Subject") ) expect_equal(colnames(get_data(m2, effects = "random")), c("mysubgrp", "mygrp", "Subject")) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_length(find_formula(m2), 2) expect_equal( find_formula(m1, component = "conditional"), list( conditional = as.formula("Reaction ~ Days"), random = as.formula("~1 + Days | Subject") ) ) expect_equal( find_formula(m2, component = "conditional"), list( conditional = as.formula("Reaction ~ Days"), random = list( as.formula("~1 | mysubgrp:mygrp"), as.formula("~1 | mygrp"), as.formula("~1 | Subject") ) ) ) }) test_that("find_terms", { expect_identical( find_terms(m1), list( response = "Reaction", conditional = "Days", random = c("Days", "Subject") ) ) expect_identical( find_terms(m1, flatten = TRUE), c("Reaction", "Days", "Subject") ) expect_identical( find_terms(m2), list( response = "Reaction", conditional = "Days", random = c("mysubgrp", "mygrp", "Subject") ) ) expect_identical( find_terms(m2, flatten = TRUE), c("Reaction", "Days", "mysubgrp", "mygrp", "Subject") ) }) test_that("find_variables", { expect_identical( find_variables(m1), list( response = "Reaction", conditional = "Days", random = "Subject" ) ) expect_identical( find_variables(m1, flatten = TRUE), c("Reaction", "Days", "Subject") ) expect_identical( find_variables(m2), list( response = "Reaction", conditional = "Days", random = c("mysubgrp", "mygrp", "Subject") ) ) expect_identical( find_variables(m2, flatten = TRUE), c("Reaction", "Days", "mysubgrp", "mygrp", "Subject") ) }) test_that("get_response", { expect_identical(get_response(m1), sleepstudy$Reaction) }) test_that("get_predictors", { expect_identical(colnames(get_predictors(m1)), "Days") expect_identical(colnames(get_predictors(m2)), "Days") }) test_that("get_random", { expect_identical(colnames(get_random(m1)), "Subject") expect_identical(colnames(get_random(m2)), c("mysubgrp", "mygrp", "Subject")) }) test_that("clean_names", { expect_identical(clean_names(m1), c("Reaction", "Days", "Subject")) expect_identical( clean_names(m2), c("Reaction", "Days", "mysubgrp", "mygrp", "Subject") ) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) expect_false(is.null(link_function(m2))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "Days"), random = list(Subject = c("(Intercept)", "Days")) ) ) expect_equal(nrow(get_parameters(m1)), 2) expect_equal(get_parameters(m1)$Parameter, c("(Intercept)", "Days")) expect_equal( find_parameters(m2), list( conditional = c("(Intercept)", "Days"), random = list( `mysubgrp:mygrp` = "(Intercept)", Subject = "(Intercept)", mygrp = "(Intercept)" ) ) ) expect_equal(nrow(get_parameters(m2)), 2) expect_equal(get_parameters(m2)$Parameter, c("(Intercept)", "Days")) expect_equal( names(get_parameters(m2, effects = "random")), c("mysubgrp:mygrp", "Subject", "mygrp") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) expect_false(is_multivariate(m2)) }) test_that("get_variance", { skip_on_cran() skip_on_travis() expect_equal( get_variance(m1), list( var.fixed = 908.953362623165, var.random = 1698.23306388298, var.residual = 654.940795852432, var.distribution = 654.940795852432, var.dispersion = 0, var.intercept = c(Subject = 611.897607104638), var.slope = c(Subject.Days = 35.081069440305), cor.slope_intercept = c(Subject = 0.0656180314242511) ), tolerance = 1e-4 ) expect_equal(get_variance_fixed(m1), c(var.fixed = 908.95336262316459396970), tolerance = 1e-4 ) expect_equal(get_variance_random(m1), c(var.random = 1698.23306388298283309268), tolerance = 1e-4 ) expect_equal( get_variance_residual(m1), c(var.residual = 654.94079585243218843971), tolerance = 1e-4 ) expect_equal( get_variance_distribution(m1), c(var.distribution = 654.94079585243218843971), tolerance = 1e-4 ) expect_equal(get_variance_dispersion(m1), c(var.dispersion = 0), tolerance = 1e-4 ) expect_equal( get_variance_intercept(m1), c(var.intercept.Subject = 611.89760710463770010392), toleance = 1e-4 ) expect_equal( get_variance_slope(m1), c(var.slope.Subject.Days = 35.08106944030500073950), toleance = 1e-4 ) expect_equal( get_correlation_slope_intercept(m1), c(cor.slope_intercept.Subject = 0.06561803), toleance = 1e-4 ) expect_warning(expect_equal( get_variance(m2), list( var.fixed = 889.329700216337, var.residual = 941.817768377025, var.distribution = 941.817768377025, var.dispersion = 0, var.intercept = c( `mysubgrp:mygrp` = 0, Subject = 1357.35782386825, mygrp = 24.4073139080596 ) ), tolerance = 1e-4, )) }) test_that("find_algorithm", { expect_equal( find_algorithm(m1), list(algorithm = "REML", optimizer = "nloptwrap") ) }) test_that("find_random_slopes", { expect_equal(find_random_slopes(m1), list(random = "Days")) expect_null(find_random_slopes(m2)) }) m3 <- lme4::lmer(Reaction ~ (1 + Days | Subject), data = sleepstudy ) m4 <- lme4::lmer(Reaction ~ (1 | mygrp / mysubgrp) + (1 | Subject), data = sleepstudy ) m5 <- lme4::lmer(Reaction ~ 1 + (1 + Days | Subject), data = sleepstudy ) m6 <- lme4::lmer(Reaction ~ 1 + (1 | mygrp / mysubgrp) + (1 | Subject), data = sleepstudy ) test_that("find_formula", { expect_equal( find_formula(m3), list( conditional = as.formula("Reaction ~ 1"), random = as.formula("~1 + Days | Subject") ) ) expect_equal( find_formula(m5), list( conditional = as.formula("Reaction ~ 1"), random = as.formula("~1 + Days | Subject") ) ) expect_equal( find_formula(m4), list( conditional = as.formula("Reaction ~ 1"), random = list( as.formula("~1 | mysubgrp:mygrp"), as.formula("~1 | mygrp"), as.formula("~1 | Subject") ) ) ) expect_equal( find_formula(m6), list( conditional = as.formula("Reaction ~ 1"), random = list( as.formula("~1 | mysubgrp:mygrp"), as.formula("~1 | mygrp"), as.formula("~1 | Subject") ) ) ) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") expect_identical(find_statistic(m2), "t-statistic") }) } insight/tests/testthat/test-lme.R0000644000176200001440000001221613552364343016610 0ustar liggesusersif (require("testthat") && require("insight") && require("nlme") && require("lme4")) { context("insight, model_info") data("sleepstudy") data(Orthodont) m1 <- lme(Reaction ~ Days, random = ~ 1 + Days | Subject, data = sleepstudy ) m2 <- lme(distance ~ age + Sex, data = Orthodont, random = ~1) set.seed(123) sleepstudy$mygrp <- sample(1:5, size = 180, replace = TRUE) sleepstudy$mysubgrp <- NA for (i in 1:5) { filter_group <- sleepstudy$mygrp == i sleepstudy$mysubgrp[filter_group] <- sample(1:30, size = sum(filter_group), replace = TRUE) } m3 <- lme(Reaction ~ Days, random = ~ 1 | mygrp / mysubgrp, data = sleepstudy ) test_that("nested_varCorr", { skip_on_travis() skip_on_cran() expect_equal( insight:::.get_nested_lme_varcorr(m3), list( mysubgrp = structure( 7.508310765, .Dim = c(1L, 1L), .Dimnames = list("(Intercept)", "(Intercept)") ), mygrp = structure( 0.004897827, .Dim = c(1L, 1L), .Dimnames = list("(Intercept)", "(Intercept)") ) ), tolerance = 1e-4 ) }) test_that("model_info", { expect_true(model_info(m1)$is_linear) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = "Days")) expect_identical(find_predictors(m2), list(conditional = c("age", "Sex"))) expect_identical( find_predictors(m1, effects = "all"), list(conditional = "Days", random = "Subject") ) expect_identical(find_predictors(m2, effects = "all"), list(conditional = c("age", "Sex"))) expect_identical(find_predictors(m1, flatten = TRUE), "Days") expect_identical( find_predictors(m1, effects = "random"), list(random = "Subject") ) }) test_that("find_response", { expect_identical(find_response(m1), "Reaction") expect_identical(find_response(m2), "distance") }) test_that("get_response", { expect_equal(get_response(m1), sleepstudy$Reaction) }) test_that("find_random", { expect_equal(find_random(m1), list(random = "Subject")) expect_null(find_random(m2)) }) test_that("get_random", { expect_equal(get_random(m1), data.frame(Subject = sleepstudy$Subject)) expect_warning(get_random(m2)) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 180) expect_equal(colnames(get_data(m1)), c("Reaction", "Days", "Subject")) expect_equal(colnames(get_data(m2)), c("distance", "age", "Sex")) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_equal( find_formula(m1), list( conditional = as.formula("Reaction ~ Days"), random = as.formula("~1 + Days | Subject") ) ) expect_length(find_formula(m2), 2) expect_equal( find_formula(m2), list( conditional = as.formula("distance ~ age + Sex"), random = as.formula("~1") ) ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "Reaction", conditional = "Days", random = "Subject" ) ) expect_equal( find_variables(m1, flatten = TRUE), c("Reaction", "Days", "Subject") ) expect_equal( find_variables(m2), list( response = "distance", conditional = c("age", "Sex") ) ) }) test_that("n_obs", { expect_equal(n_obs(m1), 180) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "Days"), random = c("(Intercept)", "Days") ) ) expect_equal(nrow(get_parameters(m1)), 2) expect_equal(get_parameters(m1)$Parameter, c("(Intercept)", "Days")) expect_equal( find_parameters(m2), list( conditional = c("(Intercept)", "age", "SexFemale"), random = c("(Intercept)") ) ) }) test_that("find_algorithm", { expect_equal( find_algorithm(m1), list(algorithm = "REML", optimizer = "nlminb") ) }) test_that("get_variance", { skip_on_cran() expect_equal( get_variance(m1), list( var.fixed = 908.95336262308865116211, var.random = 1698.06593646939654718153, var.residual = 654.94240352794997761521, var.distribution = 654.94240352794997761521, var.dispersion = 0, var.intercept = c(Subject = 612.07951112963326067984), var.slope = c(Subject.Days = 35.07130179308116169068), cor.slope_intercept = 0.06600000000000000311 ), tolerance = 1e-4 ) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") expect_identical(find_statistic(m2), "t-statistic") expect_identical(find_statistic(m3), "t-statistic") }) } insight/tests/testthat/test-truncreg.R0000644000176200001440000000363513552364343017671 0ustar liggesusersif (require("testthat") && require("insight") && require("truncreg") && require("survival")) { context("insight, truncreg") data("tobin", package = "survival") m1 <- truncreg(durable ~ age + quant, data = tobin, subset = durable > 0) test_that("model_info", { expect_true(model_info(m1)$is_linear) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("age", "quant"))) expect_identical(find_predictors(m1, flatten = TRUE), c("age", "quant")) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_response", { expect_identical(find_response(m1), "durable") }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 7) expect_equal(colnames(get_data(m1)), c("durable", "age", "quant")) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("durable ~ age + quant")) ) }) test_that("find_terms", { expect_equal(find_terms(m1), list( response = "durable", conditional = c("age", "quant") )) expect_equal(find_terms(m1, flatten = TRUE), c("durable", "age", "quant")) }) test_that("n_obs", { expect_equal(n_obs(m1), 7) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list(conditional = c( "(Intercept)", "age", "quant", "sigma" )) ) expect_equal(nrow(get_parameters(m1)), 4) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "age", "quant", "sigma") ) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") }) } insight/tests/testthat/test-bigglm.R0000644000176200001440000000700513552364343017274 0ustar liggesusers.runThisTest <- Sys.getenv("RunAllinsightTests") == "yes" if (.runThisTest || Sys.getenv("USER") == "travis") { if (require("testthat") && require("insight") && require("glmmTMB") && require("biglm")) { context("insight, model_info") data(Salamanders) Salamanders$cover <- abs(Salamanders$cover) m1 <- bigglm(count ~ mined + log(cover) + sample, family = poisson(), data = Salamanders ) test_that("model_info", { expect_true(model_info(m1)$is_poisson) expect_true(model_info(m1)$is_count) expect_false(model_info(m1)$is_negbin) expect_false(model_info(m1)$is_binomial) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("mined", "cover", "sample"))) expect_identical( find_predictors(m1, flatten = TRUE), c("mined", "cover", "sample") ) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "count") }) test_that("get_response", { expect_equal(get_response(m1), Salamanders$count) }) test_that("get_predictors", { expect_equal( colnames(get_predictors(m1)), c("mined", "cover", "sample") ) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), exp(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 644) expect_equal( colnames(get_data(m1)), c( "site", "mined", "cover", "sample", "DOP", "Wtemp", "DOY", "spp", "count" ) ) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("count ~ mined + log(cover) + sample")) ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "count", conditional = c("mined", "cover", "sample") ) ) expect_equal( find_variables(m1, flatten = TRUE), c("count", "mined", "cover", "sample") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 644) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "minedno", "log(cover)", "sample") ) ) expect_equal(nrow(get_parameters(m1)), 4) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "minedno", "log(cover)", "sample") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "count", conditional = c("mined", "log(cover)", "sample") ) ) }) test_that("find_algorithm", { expect_equal(find_algorithm(m1), list(algorithm = "ML")) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") }) } } insight/tests/testthat/test-tobit.R0000644000176200001440000000660513552364343017161 0ustar liggesusersif (require("testthat") && require("insight") && require("AER")) { context("insight, AER") data("Affairs", package = "AER") m1 <- AER::tobit(affairs ~ age + yearsmarried + religiousness + occupation + rating, data = Affairs ) test_that("model_info", { expect_true(model_info(m1)$is_linear) expect_true(model_info(m1)$is_censored) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list( conditional = c( "age", "yearsmarried", "religiousness", "occupation", "rating" ) )) expect_identical( find_predictors(m1, flatten = TRUE), c( "age", "yearsmarried", "religiousness", "occupation", "rating" ) ) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "affairs") }) test_that("get_response", { expect_equal(get_response(m1), Affairs$affairs) }) test_that("get_predictors", { expect_equal( colnames(get_predictors(m1)), c( "age", "yearsmarried", "religiousness", "occupation", "rating" ) ) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 601) expect_equal( colnames(get_data(m1)), c( "affairs", "age", "yearsmarried", "religiousness", "occupation", "rating" ) ) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list( conditional = as.formula( "affairs ~ age + yearsmarried + religiousness + occupation + rating" ) ) ) }) test_that("find_terms", { expect_equal(find_terms(m1), list( response = "affairs", conditional = c( "age", "yearsmarried", "religiousness", "occupation", "rating" ) )) expect_equal( find_terms(m1, flatten = TRUE), c( "affairs", "age", "yearsmarried", "religiousness", "occupation", "rating" ) ) }) test_that("n_obs", { expect_equal(n_obs(m1), 601) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c( "(Intercept)", "age", "yearsmarried", "religiousness", "occupation", "rating" ) ) ) expect_equal(nrow(get_parameters(m1)), 6) expect_equal( get_parameters(m1)$Parameter, c( "(Intercept)", "age", "yearsmarried", "religiousness", "occupation", "rating" ) ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") }) } insight/tests/testthat/test-coxme.R0000644000176200001440000001215513552364343017150 0ustar liggesusersif (require("testthat") && require("insight") && require("survival") && require("coxme")) { context("insight, model_info") data(lung) set.seed(1234) lung$inst2 <- sample(1:10, size = nrow(lung), replace = T) lung <- subset(lung, subset = ph.ecog %in% 0:2) lung$ph.ecog <- factor(lung$ph.ecog, labels = c("good", "ok", "limited")) m1 <- coxme(Surv(time, status) ~ ph.ecog + age + (1 | inst), lung) m2 <- coxme(Surv(time, status) ~ ph.ecog + age + (1 | inst) + (1 | inst2), lung) test_that("model_info", { expect_true(model_info(m1)$is_logit) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("ph.ecog", "age"))) expect_identical( find_predictors(m1, effects = "random"), list(random = "inst") ) expect_identical(find_predictors(m2), list(conditional = c("ph.ecog", "age"))) expect_identical(find_predictors(m2, effects = "random"), list(random = c("inst", "inst2"))) }) test_that("find_response", { expect_identical(find_response(m1), "Surv(time, status)") expect_identical(find_response(m1, combine = FALSE), c("time", "status")) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), plogis(.2), tolerance = 1e-5) expect_equal(link_inverse(m2)(.2), plogis(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 226) expect_equal( colnames(get_data(m1)), c( "time", "status", "Surv(time, status)", "ph.ecog", "age", "inst" ) ) expect_equal( colnames(get_data(m2)), c( "time", "status", "Surv(time, status)", "ph.ecog", "age", "inst", "inst2" ) ) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_equal( find_formula(m1), list( conditional = as.formula("Surv(time, status) ~ ph.ecog + age"), random = as.formula("~1 | inst") ) ) expect_length(find_formula(m2), 2) expect_equal( find_formula(m2), list( conditional = as.formula("Surv(time, status) ~ ph.ecog + age"), random = list(as.formula("~1 | inst"), as.formula("~1 | inst2")) ) ) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "Surv(time, status)", conditional = c("ph.ecog", "age"), random = "inst" ) ) expect_equal( find_terms(m1, flatten = TRUE), c("Surv(time, status)", "ph.ecog", "age", "inst") ) expect_equal( find_terms(m2), list( response = "Surv(time, status)", conditional = c("ph.ecog", "age"), random = c("inst", "inst2") ) ) expect_equal( find_terms(m2, flatten = TRUE), c("Surv(time, status)", "ph.ecog", "age", "inst", "inst2") ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = c("time", "status"), conditional = c("ph.ecog", "age"), random = "inst" ) ) expect_equal( find_variables(m1, flatten = TRUE), c("time", "status", "ph.ecog", "age", "inst") ) expect_equal( find_variables(m2), list( response = c("time", "status"), conditional = c("ph.ecog", "age"), random = c("inst", "inst2") ) ) expect_equal( find_variables(m2, flatten = TRUE), c("time", "status", "ph.ecog", "age", "inst", "inst2") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 225) expect_equal(n_obs(m2), 225) }) test_that("get_response", { expect_equal(colnames(get_response(m1)), c("time", "status")) expect_equal(nrow(get_response(m1)), 226) expect_equal(colnames(get_response(m1)), c("time", "status")) expect_equal(nrow(get_response(m2)), 226) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) expect_false(is.null(link_function(m2))) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("ph.ecogok", "ph.ecoglimited", "age"), random = "inst" ) ) expect_equal( find_parameters(m2), list( conditional = c("ph.ecogok", "ph.ecoglimited", "age"), random = c("inst", "inst2") ) ) expect_equal(nrow(get_parameters(m1)), 3) expect_equal( get_parameters(m1)$Parameter, c("ph.ecogok", "ph.ecoglimited", "age") ) expect_equal(nrow(get_parameters(m2)), 3) expect_equal( get_parameters(m2)$Parameter, c("ph.ecogok", "ph.ecoglimited", "age") ) expect_length(get_parameters(m2, effects = "random"), 2) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") expect_identical(find_statistic(m2), "z-statistic") }) } insight/tests/testthat/test-feis.R0000644000176200001440000000707513552364343016770 0ustar liggesusersif (require("testthat") && require("insight") && require("feisr")) { context("insight, feisr") data(mwp) m1 <- feis( lnw ~ marry + enrol + as.factor(yeargr) | exp + I(exp^2), data = mwp, id = "id", robust = TRUE ) test_that("model_info", { expect_true(model_info(m1)$is_linear) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list( conditional = c("marry", "enrol", "yeargr"), slopes = "exp" )) expect_identical(find_predictors(m1, effects = "random"), list(random = "id")) expect_identical( find_predictors(m1, effects = "all", flatten = TRUE), c("marry", "enrol", "yeargr", "exp", "id") ) }) test_that("find_random", { expect_identical(find_random(m1), list(random = "id")) }) test_that("get_random", { expect_identical(colnames(get_random(m1)), "id") }) test_that("find_response", { expect_identical(find_response(m1), "lnw") }) test_that("get_response", { expect_equal(get_response(m1), mwp$lnw) }) test_that("get_predictors", { expect_equal( colnames(get_predictors(m1)), c("marry", "enrol", "yeargr", "exp") ) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 3100) expect_equal( colnames(get_data(m1)), c("lnw", "marry", "enrol", "yeargr", "exp", "id") ) }) test_that("find_formula", { expect_length(find_formula(m1), 3) expect_equal( find_formula(m1), list( conditional = as.formula("lnw ~ marry + enrol + as.factor(yeargr)"), slopes = as.formula("~exp + I(exp^2)"), random = as.formula("~id") ) ) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "lnw", conditional = c("marry", "enrol", "as.factor(yeargr)"), slopes = c("exp", "I(exp^2)"), random = "id" ) ) expect_equal( find_terms(m1, flatten = TRUE), c( "lnw", "marry", "enrol", "as.factor(yeargr)", "exp", "I(exp^2)", "id" ) ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "lnw", conditional = c("marry", "enrol", "yeargr"), slopes = "exp", random = "id" ) ) expect_equal( find_variables(m1, flatten = TRUE), c("lnw", "marry", "enrol", "yeargr", "exp", "id") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 3100) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c( "marry", "enrol", "as.factor(yeargr)2", "as.factor(yeargr)3", "as.factor(yeargr)4", "as.factor(yeargr)5" ) ) ) expect_equal(nrow(get_parameters(m1)), 6) expect_equal( get_parameters(m1)$Parameter, c( "marry", "enrol", "as.factor(yeargr)2", "as.factor(yeargr)3", "as.factor(yeargr)4", "as.factor(yeargr)5" ) ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") }) } insight/tests/testthat/test-glmrob_base.R0000644000176200001440000000636013552364343020312 0ustar liggesusersif (require("testthat") && require("insight") && require("robustbase")) { context("insight, model_info") data(carrots) m1 <- glmrob( cbind(success, total - success) ~ logdose + block, family = binomial, data = carrots, method = "Mqle", control = glmrobMqle.control(tcc = 1.2) ) test_that("model_info", { expect_true(model_info(m1)$is_binomial) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("logdose", "block"))) expect_identical(find_predictors(m1, flatten = TRUE), c("logdose", "block")) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "cbind(success, total - success)") expect_identical(find_response(m1, combine = FALSE), c("success", "total")) }) test_that("get_response", { expect_equal(get_response(m1), carrots[, c("success", "total")]) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("logdose", "block")) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 24) expect_equal( colnames(get_data(m1)), c( "cbind(success, total - success)", "logdose", "block", "success", "total" ) ) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list( conditional = as.formula("cbind(success, total - success) ~ logdose + block") ) ) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "cbind(success, total - success)", conditional = c("logdose", "block") ) ) expect_equal( find_terms(m1, flatten = TRUE), c("cbind(success, total - success)", "logdose", "block") ) }) test_that("find_variables", { expect_equal(find_variables(m1), list( response = c("success", "total"), conditional = c("logdose", "block") )) expect_equal( find_variables(m1, flatten = TRUE), c("success", "total", "logdose", "block") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 24) }) test_that("link_function", { expect_equal(link_function(m1)(.2), qlogis(.2), tolerance = 1e-5) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), plogis(.2), tolerance = 1e-5) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "logdose", "blockB2", "blockB3") ) ) expect_equal(nrow(get_parameters(m1)), 4) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "logdose", "blockB2", "blockB3") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_algorithm", { expect_equal(find_algorithm(m1), list(algorithm = "Mqle")) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") }) } insight/tests/testthat/test-gee.R0000644000176200001440000000530413552364343016573 0ustar liggesusersif (require("testthat") && require("insight") && require("gee")) { context("insight, model_info") data(warpbreaks) m1 <- gee(breaks ~ tension, id = wool, data = warpbreaks) test_that("model_info", { expect_true(model_info(m1)$is_linear) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = "tension")) expect_identical(find_predictors(m1, flatten = TRUE), "tension") expect_identical( find_predictors(m1, effects = "random"), list(random = "wool") ) expect_identical( find_predictors(m1, effects = "all", flatten = TRUE), c("tension", "wool") ) }) test_that("find_response", { expect_identical(find_response(m1), "breaks") }) test_that("get_response", { expect_equal(get_response(m1), warpbreaks$breaks) }) test_that("find_random", { expect_equal(find_random(m1), list(random = "wool")) }) test_that("get_random", { expect_equal(get_random(m1), warpbreaks[, "wool", drop = FALSE]) }) test_that("get_predictors", { expect_equal(get_predictors(m1), warpbreaks[, "tension", drop = FALSE]) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 54) expect_equal(colnames(get_data(m1)), c("breaks", "tension", "wool")) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_equal( find_formula(m1), list( conditional = as.formula("breaks ~ tension"), random = as.formula("~wool") ) ) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "breaks", conditional = "tension", random = "wool" ) ) expect_equal( find_terms(m1, flatten = TRUE), c("breaks", "tension", "wool") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 54) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list(conditional = c( "(Intercept)", "tensionM", "tensionH" )) ) expect_equal(nrow(get_parameters(m1)), 3) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "tensionM", "tensionH") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_algorithm", { expect_equal(find_algorithm(m1), list(algorithm = "ML")) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") }) } insight/tests/testthat/test-crch.R0000644000176200001440000000554313552364343016757 0ustar liggesusersif (require("testthat") && require("insight") && require("crch")) { context("insight, model_info") data("RainIbk") RainIbk$sqrtensmean <- apply(sqrt(RainIbk[, grep("^rainfc", names(RainIbk))]), 1, mean) RainIbk$sqrtenssd <- apply(sqrt(RainIbk[, grep("^rainfc", names(RainIbk))]), 1, sd) m1 <- crch(sqrt(rain) ~ sqrtensmean, data = RainIbk, dist = "gaussian") test_that("model_info", { expect_true(model_info(m1)$is_linear) expect_true(model_info(m1)$is_censored) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("sqrtensmean"))) expect_identical(find_predictors(m1, flatten = TRUE), c("sqrtensmean")) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "rain") }) test_that("get_response", { expect_equal(get_response(m1), sqrt(RainIbk$rain)) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("sqrtensmean")) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 4971) expect_equal(colnames(get_data(m1)), c("rain", "sqrtensmean")) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("sqrt(rain) ~ sqrtensmean")) ) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "sqrt(rain)", conditional = c("sqrtensmean") ) ) expect_equal( find_terms(m1, flatten = TRUE), c("sqrt(rain)", "sqrtensmean") ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "rain", conditional = c("sqrtensmean") ) ) expect_equal( find_variables(m1, flatten = TRUE), c("rain", "sqrtensmean") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 4971) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "sqrtensmean", "(scale)_(Intercept)") ) ) expect_equal(nrow(get_parameters(m1)), 3) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "sqrtensmean", "(scale)_(Intercept)") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") }) } insight/tests/testthat/test-lm.R0000644000176200001440000001357713565540604016456 0ustar liggesusersif (require("testthat") && require("insight") && require("stats")) { context("insight, lm") data(iris) data(mtcars) m1 <- lm(Sepal.Length ~ Petal.Width + Species, data = iris) m2 <- lm(log(mpg) ~ log(hp) + cyl + I(cyl^2) + poly(wt, degree = 2, raw = TRUE), data = mtcars ) test_that("model_info", { expect_true(model_info(m1)$is_linear) expect_false(model_info(m1)$is_bayesian) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("Petal.Width", "Species"))) expect_identical( find_predictors(m1, flatten = TRUE), c("Petal.Width", "Species") ) expect_null(find_predictors(m1, effects = "random")) expect_identical(find_predictors(m2), list(conditional = c("hp", "cyl", "wt"))) expect_identical(find_predictors(m2, flatten = TRUE), c("hp", "cyl", "wt")) expect_null(find_predictors(m2, effects = "random")) }) test_that("find_response", { expect_identical(find_response(m1), "Sepal.Length") expect_identical(find_response(m2), "mpg") }) test_that("link_inverse", { expect_identical(link_inverse(m1)(.2), .2) expect_identical(link_inverse(m2)(.2), .2) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 150) expect_equal( colnames(get_data(m1)), c("Sepal.Length", "Petal.Width", "Species") ) expect_equal(nrow(get_data(m2)), 32) expect_equal(colnames(get_data(m2)), c("mpg", "hp", "cyl", "wt")) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("Sepal.Length ~ Petal.Width + Species")) ) expect_length(find_formula(m2), 1) expect_equal( find_formula(m2), list( conditional = as.formula( "log(mpg) ~ log(hp) + cyl + I(cyl^2) + poly(wt, degree = 2, raw = TRUE)" ) ) ) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "Sepal.Length", conditional = c("Petal.Width", "Species") ) ) expect_equal( find_terms(m2), list( response = "log(mpg)", conditional = c( "log(hp)", "cyl", "I(cyl^2)", "poly(wt, degree = 2, raw = TRUE)" ) ) ) expect_equal( find_terms(m1, flatten = TRUE), c("Sepal.Length", "Petal.Width", "Species") ) expect_equal( find_terms(m2, flatten = TRUE), c( "log(mpg)", "log(hp)", "cyl", "I(cyl^2)", "poly(wt, degree = 2, raw = TRUE)" ) ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "Sepal.Length", conditional = c("Petal.Width", "Species") ) ) expect_equal(find_variables(m2), list( response = "mpg", conditional = c("hp", "cyl", "wt") )) expect_equal( find_variables(m1, flatten = TRUE), c("Sepal.Length", "Petal.Width", "Species") ) expect_equal( find_variables(m2, flatten = TRUE), c("mpg", "hp", "cyl", "wt") ) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c( "(Intercept)", "Petal.Width", "Speciesversicolor", "Speciesvirginica" ) ) ) expect_equal(nrow(get_parameters(m1)), 4) expect_equal( get_parameters(m1)$Parameter, c( "(Intercept)", "Petal.Width", "Speciesversicolor", "Speciesvirginica" ) ) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) expect_false(is.null(link_function(m2))) }) test_that("find_algorithm", { expect_equal(find_algorithm(m1), list(algorithm = "OLS")) }) test_that("get_variance", { expect_warning(expect_null(get_variance(m1))) expect_warning(expect_null(get_variance_dispersion(m1))) expect_warning(expect_null(get_variance_distribution(m1))) expect_warning(expect_null(get_variance_fixed(m1))) expect_warning(expect_null(get_variance_intercept(m1))) expect_warning(expect_null(get_variance_random(m1))) expect_warning(expect_null(get_variance_residual(m1))) }) test_that("is_model", { expect_true(is_model(m1)) }) test_that("all_models_equal", { expect_true(all_models_equal(m1, m2)) }) test_that("get_varcov", { expect_equal(diag(get_varcov(m1)), diag(vcov(m1))) }) test_that("get_statistic", { expect_equal(get_statistic(m1)$Statistic, c(57.5427, 4.7298, -0.2615, -0.1398), tolerance = 1e-3) }) test_that("find_statistic", { expect_equal(find_statistic(m1), "t-statistic") }) data("DNase") DNase1 <- subset(DNase, Run == 1) m3 <- stats::nls( density ~ stats::SSlogis(log(conc), Asym, xmid, scal), DNase1, start = list( Asym = 1, xmid = 1, scal = 1 ) ) ## Dobson (1990) Page 93: Randomized Controlled Trial : counts <- c(18, 17, 15, 20, 10, 20, 25, 13, 12) outcome <- gl(3, 1, 9) treatment <- gl(3, 3) m4 <- glm(counts ~ outcome + treatment, family = poisson()) test_that("is_model", { expect_true(is_model(m3)) }) test_that("is_model", { expect_false(is_model_supported(m3)) }) test_that("all_models_equal", { expect_false(all_models_equal(m1, m2, m3)) expect_false(all_models_equal(m1, m2, m4)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") expect_identical(find_statistic(m2), "t-statistic") expect_identical(find_statistic(m3), "t-statistic") expect_identical(find_statistic(m4), "z-statistic") }) } insight/tests/testthat/test-is_nullmodel.R0000644000176200001440000000122513531007236020507 0ustar liggesusersif (require("testthat") && require("insight")) { context("insight, is_nullmodel") library(lme4) data(mtcars) data(sleepstudy) m1 <- lm(mpg ~ 1, data = mtcars) m2 <- lm(mpg ~ gear, data = mtcars) m3 <- lmer(Reaction ~ 1 + (Days | Subject), data = sleepstudy) m4 <- lmer(Reaction ~ Days + (Days | Subject), data = sleepstudy) m5 <- suppressWarnings(lmer(Reaction ~ 0 + (Days | Subject), data = sleepstudy)) test_that("is_nullmodel", { expect_true(is_nullmodel(m1)) expect_false(is_nullmodel(m2)) expect_true(is_nullmodel(m3)) expect_false(is_nullmodel(m4)) expect_true(is_nullmodel(m5)) }) } insight/tests/testthat/test-namespace.R0000644000176200001440000000613613552364343017773 0ustar liggesusersif (require("testthat") && require("insight") && require("splines")) { context("insight, namespace, splines") data(iris) m1 <- lm(Sepal.Length ~ splines::bs(Petal.Width, df = 4) + Species, data = iris) test_that("model_info", { expect_true(model_info(m1)$is_linear) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("Petal.Width", "Species"))) expect_identical( find_predictors(m1, flatten = TRUE), c("Petal.Width", "Species") ) expect_null(find_predictors(m1, effects = "random")) }) test_that("get_predictors", { expect_equal(get_predictors(m1), iris[, c("Petal.Width", "Species")]) }) test_that("find_response", { expect_identical(find_response(m1), "Sepal.Length") }) test_that("get_response", { expect_identical(get_response(m1), iris$Sepal.Length) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-4) }) test_that("link_function", { expect_equal(link_function(m1)(.2), .2, tolerance = 1e-4) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 150) expect_equal( colnames(get_data(m1)), c("Sepal.Length", "Species", "Petal.Width") ) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list( conditional = as.formula("Sepal.Length ~ splines::bs(Petal.Width, df = 4) + Species") ) ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "Sepal.Length", conditional = c("Petal.Width", "Species") ) ) expect_equal( find_variables(m1, flatten = TRUE), c("Sepal.Length", "Petal.Width", "Species") ) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c( "(Intercept)", "splines::bs(Petal.Width, df = 4)1", "splines::bs(Petal.Width, df = 4)2", "splines::bs(Petal.Width, df = 4)3", "splines::bs(Petal.Width, df = 4)4", "Speciesversicolor", "Speciesvirginica" ) ) ) }) test_that("get_parameters", { expect_equal(nrow(get_parameters(m1)), 7) expect_equal( get_parameters(m1)$Parameter, c( "(Intercept)", "splines::bs(Petal.Width, df = 4)1", "splines::bs(Petal.Width, df = 4)2", "splines::bs(Petal.Width, df = 4)3", "splines::bs(Petal.Width, df = 4)4", "Speciesversicolor", "Speciesvirginica" ) ) }) test_that("find_algorithm", { expect_equal(find_algorithm(m1), list(algorithm = "OLS")) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "Sepal.Length", conditional = c("splines", "bs(Petal.Width, df = 4)", "Species") ) ) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") }) } insight/tests/testthat/test-lmrob_base.R0000644000176200001440000000456113552364343020144 0ustar liggesusersif (require("testthat") && require("insight") && require("robustbase")) { context("insight, model_info") data(mtcars) m1 <- lmrob(mpg ~ gear + wt + cyl, data = mtcars) test_that("model_info", { expect_true(model_info(m1)$is_linear) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("gear", "wt", "cyl"))) expect_identical(find_predictors(m1, flatten = TRUE), c("gear", "wt", "cyl")) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "mpg") }) test_that("get_response", { expect_equal(get_response(m1), mtcars$mpg) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("gear", "wt", "cyl")) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 32) expect_equal(colnames(get_data(m1)), c("mpg", "gear", "wt", "cyl")) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("mpg ~ gear + wt + cyl")) ) }) test_that("find_terms", { expect_equal(find_terms(m1), list( response = "mpg", conditional = c("gear", "wt", "cyl") )) expect_equal(find_terms(m1, flatten = TRUE), c("mpg", "gear", "wt", "cyl")) }) test_that("n_obs", { expect_equal(n_obs(m1), 32) }) test_that("link_function", { expect_equal(link_function(m1)(.2), .2, tolerance = 1e-5) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list(conditional = c("(Intercept)", "gear", "wt", "cyl")) ) expect_equal(nrow(get_parameters(m1)), 4) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "gear", "wt", "cyl") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_algorithm", { expect_equal(find_algorithm(m1), list(algorithm = "SM")) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") }) } insight/tests/testthat/test-vgam.R0000644000176200001440000001344013552364343016765 0ustar liggesusers.runThisTest <- Sys.getenv("RunAllinsightTests") == "yes" if (.runThisTest && Sys.getenv("USER") != "travis") { if (require("testthat") && require("insight") && require("VGAM")) { context("insight, model_info") data("hunua") m1 <- download_model("vgam_1") m2 <- download_model("vgam_2") test_that("model_info", { expect_true(model_info(m1)$is_binomial) expect_true(model_info(m2)$is_binomial) expect_false(model_info(m1)$is_bayesian) expect_false(model_info(m2)$is_bayesian) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("vitluc", "altitude"))) expect_identical( find_predictors(m1, flatten = TRUE), c("vitluc", "altitude") ) expect_null(find_predictors(m1, effects = "random")) expect_identical(find_predictors(m2), list(conditional = c("vitluc", "altitude"))) expect_identical( find_predictors(m2, flatten = TRUE), c("vitluc", "altitude") ) expect_null(find_predictors(m2, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) expect_null(find_random(m2)) }) test_that("get_random", { expect_warning(get_random(m1)) expect_warning(get_random(m2)) }) test_that("find_response", { expect_identical(find_response(m1), "agaaus") expect_identical(find_response(m2), "cbind(agaaus, kniexc)") expect_identical(find_response(m2, combine = FALSE), c("agaaus", "kniexc")) }) test_that("get_response", { expect_equal(get_response(m1), hunua$agaaus) expect_equal( get_response(m2), data.frame(agaaus = hunua$agaaus, kniexc = hunua$kniexc) ) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("vitluc", "altitude")) expect_equal(colnames(get_predictors(m2)), c("vitluc", "altitude")) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), plogis(.2), tolerance = 1e-5) expect_equal(link_inverse(m2)(.2), plogis(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 392) expect_equal(nrow(get_data(m2)), 392) expect_equal(colnames(get_data(m1)), c("agaaus", "vitluc", "altitude")) expect_equal( colnames(get_data(m2)), c("agaaus", "kniexc", "vitluc", "altitude") ) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("agaaus ~ vitluc + s(altitude, df = 2)")) ) expect_length(find_formula(m2), 1) expect_equal( find_formula(m2), list( conditional = as.formula("cbind(agaaus, kniexc) ~ vitluc + s(altitude, df = c(2, 3))") ) ) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "agaaus", conditional = c("vitluc", "s(altitude, df = 2)") ) ) expect_equal( find_terms(m1, flatten = TRUE), c("agaaus", "vitluc", "s(altitude, df = 2)") ) expect_equal( find_terms(m2), list( response = "cbind(agaaus, kniexc)", conditional = c("vitluc", "s(altitude, df = c(2, 3))") ) ) expect_equal( find_terms(m2, flatten = TRUE), c( "cbind(agaaus, kniexc)", "vitluc", "s(altitude, df = c(2, 3))" ) ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "agaaus", conditional = c("vitluc", "altitude") ) ) expect_equal( find_variables(m1, flatten = TRUE), c("agaaus", "vitluc", "altitude") ) expect_equal(find_variables(m2), list( response = c("agaaus", "kniexc"), conditional = c("vitluc", "altitude") )) expect_equal( find_variables(m2, flatten = TRUE), c("agaaus", "kniexc", "vitluc", "altitude") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 392) expect_equal(n_obs(m2), 392) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) expect_false(is.null(link_function(m2))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "vitluc"), smooth_terms = "s(altitude, df = 2)" ) ) expect_equal(nrow(get_parameters(m1)), 3) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "vitluc", "s(altitude, df = 2)") ) expect_equal( find_parameters(m2), list( conditional = c( "(Intercept):1", "(Intercept):2", "vitluc:1", "vitluc:2" ), smooth_terms = c("s(altitude, df = c(2, 3)):1", "s(altitude, df = c(2, 3)):2") ) ) expect_equal(nrow(get_parameters(m2)), 6) expect_equal( get_parameters(m2)$Parameter, c( "(Intercept):1", "(Intercept):2", "vitluc:1", "vitluc:2", "s(altitude, df = c(2, 3)):1", "s(altitude, df = c(2, 3)):2" ) ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) expect_false(is_multivariate(m2)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "chi-squared statistic") expect_identical(find_statistic(m2), "chi-squared statistic") }) } } insight/tests/testthat/test-rstanarm.R0000644000176200001440000002243413615512624017662 0ustar liggesusers.runThisTest <- Sys.getenv("RunAllinsightTests") == "yes" if (.runThisTest || Sys.getenv("USER") == "travis") { if (suppressWarnings(require("testthat") && require("insight") && require("BayesFactor") && require("rstanarm"))) { m1 <- insight::download_model("stanreg_merMod_5") m2 <- insight::download_model("stanreg_glm_6") m3 <- insight::download_model("stanreg_glm_1") data("puzzles") m4 <- stan_glm( RT ~ color * shape, data = puzzles, prior = rstanarm::cauchy(0, c(3, 1, 2)), iter = 500, chains = 2 ) m5 <- stan_glm( RT ~ color * shape, data = puzzles, prior = rstanarm::cauchy(0, c(1, 2, 3)), iter = 500, chains = 2 ) m6 <- insight::download_model("stanreg_gamm4_1") test_that("get_priors", { expect_equal( colnames(get_priors(m1)), c("Parameter", "Distribution", "Location", "Scale") ) expect_equal( colnames(get_priors(m2)), c( "Parameter", "Distribution", "Location", "Scale", "Adjusted_Scale" ) ) expect_equal(get_priors(m1)$Scale, c(10.0, 2.5, 2.5, 2.5, 2.5), tolerance = 1e-3 ) expect_equal( get_priors(m2)$Adjusted_Scale, c( 4.35866284936698, 1.08966571234175, 1.08966571234175, 0.617270040728345, 0.536028320794122, 0.411970489526739 ), tolerance = 1e-3 ) expect_equal(get_priors(m3)$Adjusted_Scale, c(NA, 2.555042), tolerance = 1e-3 ) expect_equal( get_priors(m4)$Adjusted_Scale, c( 25.5992021152256, 7.67976063456768, 2.55992021152256, 5.11984042304512 ), tolerance = 1e-3 ) expect_equal( get_priors(m5)$Adjusted_Scale, c( 25.5992021152256, 2.55992021152256, 5.11984042304512, 7.67976063456768 ), tolerance = 1e-3 ) expect_equal( get_priors(m6), data.frame( Parameter = "(Intercept)", Distribution = "normal", Location = 0, Scale = 10, Adjusted_Scale = 4.35866284936698, stringsAsFactors = FALSE, row.names = NULL ), tolerance = 1e-3 ) }) test_that("clean_names", { expect_identical( clean_names(m1), c("incidence", "size", "period", "herd") ) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("size", "period"))) expect_identical(find_predictors(m1, flatten = TRUE), c("size", "period")) expect_identical( find_predictors(m1, effects = "all", component = "all"), list( conditional = c("size", "period"), random = "herd" ) ) expect_identical( find_predictors( m1, effects = "all", component = "all", flatten = TRUE ), c("size", "period", "herd") ) }) test_that("find_response", { expect_equal( find_response(m1, combine = TRUE), "cbind(incidence, size - incidence)" ) expect_equal( find_response(m1, combine = FALSE), c("incidence", "size") ) }) test_that("get_response", { expect_equal(nrow(get_response(m1)), 56) expect_equal(colnames(get_response(m1)), c("incidence", "size")) }) test_that("find_random", { expect_equal(find_random(m1), list(random = "herd")) }) test_that("get_random", { expect_equal(get_random(m1), lme4::cbpp[, "herd", drop = FALSE]) }) test_that("find_terms", { expect_identical( find_terms(m1), list( response = "cbind(incidence, size - incidence)", conditional = c("size", "period"), random = "herd" ) ) }) test_that("find_variables", { expect_identical( find_variables(m1), list( response = c("incidence", "size"), conditional = c("size", "period"), random = "herd" ) ) expect_identical( find_variables(m1, effects = "fixed"), list( response = c("incidence", "size"), conditional = c("size", "period") ) ) expect_null(find_variables(m1, component = "zi")) }) test_that("n_obs", { expect_equal(n_obs(m1), 56) }) test_that("find_paramaters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "size", "period2", "period3", "period4"), random = sprintf("b[(Intercept) herd:%i]", 1:15) ) ) expect_equal( find_parameters(m1, flatten = TRUE), c( "(Intercept)", "size", "period2", "period3", "period4", sprintf("b[(Intercept) herd:%i]", 1:15) ) ) }) test_that("find_paramaters", { expect_equal( colnames(get_parameters(m1)), c("(Intercept)", "size", "period2", "period3", "period4") ) expect_equal( colnames(get_parameters(m1, effects = "all")), c( "(Intercept)", "size", "period2", "period3", "period4", sprintf("b[(Intercept) herd:%i]", 1:15) ) ) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), plogis(.2), tolerance = 1e-4) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 56) expect_equal( colnames(get_data(m1)), c("incidence", "size", "period", "herd") ) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_equal( find_formula(m1), list( conditional = as.formula("cbind(incidence, size - incidence) ~ size + period"), random = as.formula("~1 | herd") ) ) }) test_that("get_variance", { expect_equal( get_variance(m1), list( var.fixed = 0.3710157, var.random = 0.6113405, var.residual = 3.289868, var.distribution = 3.289868, var.dispersion = 0, var.intercept = c(herd = 0.6113405) ), tolerance = 1e-4 ) expect_equal(get_variance_fixed(m1), c(var.fixed = 0.3710157), tolerance = 1e-4 ) expect_equal(get_variance_random(m1), c(var.random = 0.6113405), tolerance = 1e-4 ) expect_equal(get_variance_residual(m1), c(var.residual = 3.289868), tolerance = 1e-4 ) expect_equal(get_variance_distribution(m1), c(var.distribution = 3.289868), tolerance = 1e-4 ) expect_equal(get_variance_dispersion(m1), c(var.dispersion = 0), tolerance = 1e-4 ) }) test_that("find_algorithm", { expect_equal( find_algorithm(m1), list( algorithm = "sampling", chains = 2, iterations = 500, warmup = 250 ) ) }) test_that("clean_parameters", { expect_equal( clean_parameters(m2), structure( list( Parameter = c( "(Intercept)", "Speciesversicolor", "Speciesvirginica", "Petal.Length", "Speciesversicolor:Petal.Length", "Speciesvirginica:Petal.Length" ), Effects = c( "fixed", "fixed", "fixed", "fixed", "fixed", "fixed" ), Component = c( "conditional", "conditional", "conditional", "conditional", "conditional", "conditional" ), Cleaned_Parameter = c( "(Intercept)", "Speciesversicolor", "Speciesvirginica", "Petal.Length", "Speciesversicolor:Petal.Length", "Speciesvirginica:Petal.Length" ) ), class = c("clean_parameters", "data.frame"), row.names = c(NA, -6L) ) ) }) test_that("find_statistic", { expect_null(find_statistic(m1)) expect_null(find_statistic(m2)) expect_null(find_statistic(m3)) expect_null(find_statistic(m4)) expect_null(find_statistic(m5)) expect_null(find_statistic(m6)) }) model <- stan_glm( disp ~ carb, data = mtcars, priors = NULL, prior_intercept = NULL ) test_that("flat_priors", { p <- get_priors(model) expect_equal(p$Distribution, c("uniform", "normal")) expect_equal(p$Location, c(NA, 0), tolerance = 1e-3) }) } } insight/tests/testthat/test-find_predictor_nested_re.R0000644000176200001440000000126213554405404023051 0ustar liggesusersif (require("testthat") && require("insight") && require("lme4")) { context("insight, find_predictors") set.seed(1984) dat <- data.frame( y = rnorm(1000 * 5, sd = 1 - .20), time = rep(1:10, 100 * 5), g1 = sort(rep(1:100, 10 * 5)), g2 = sort(rep(1:10, 100 * 5)) ) dat$g0 <- paste(dat$time, dat$g1) dat$time1 <- dat$time - 8 dat$post <- 0 dat$post[dat$time >= 8] <- 1 m <- lmer(y ~ post + time1 + (1 | g2 / g1 / g0) + (post + time1 - 1 | g2), data = dat) test_that("clean_names", { expect_equal( find_predictors(m, effects = "all"), list(conditional = c("post", "time1"), random = c("g0", "g1", "g2")) ) }) } insight/tests/testthat/test-clm.R0000644000176200001440000000504613552364343016611 0ustar liggesusersif (require("testthat") && require("insight") && require("ordinal")) { context("insight, model_info") data(wine, package = "ordinal") m1 <- clm(rating ~ temp * contact, data = wine) test_that("model_info", { expect_true(model_info(m1)$is_ordinal) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("temp", "contact"))) expect_identical(find_predictors(m1, flatten = TRUE), c("temp", "contact")) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "rating") }) test_that("get_response", { expect_equal(get_response(m1), wine$rating) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("temp", "contact")) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), plogis(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 72) expect_equal(colnames(get_data(m1)), c("rating", "temp", "contact")) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("rating ~ temp * contact")) ) }) test_that("find_terms", { expect_equal(find_terms(m1), list( response = "rating", conditional = c("temp", "contact") )) expect_equal( find_terms(m1, flatten = TRUE), c("rating", "temp", "contact") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 72) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c( "1|2", "2|3", "3|4", "4|5", "tempwarm", "contactyes", "tempwarm:contactyes" ) ) ) expect_equal(nrow(get_parameters(m1)), 7) expect_equal( get_parameters(m1)$Parameter, c( "1|2", "2|3", "3|4", "4|5", "tempwarm", "contactyes", "tempwarm:contactyes" ) ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") }) } insight/tests/testthat/test-logistf.R0000644000176200001440000000546713552364343017514 0ustar liggesusersif (require("testthat") && require("insight") && require("logistf")) { context("insight, model_info") data(sex2) m1 <- logistf(case ~ age + oc + vic + vicl + vis + dia, data = sex2) test_that("model_info", { expect_true(model_info(m1)$is_binomial) expect_true(model_info(m1)$is_logit) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c( "age", "oc", "vic", "vicl", "vis", "dia" ))) expect_identical( find_predictors(m1, flatten = TRUE), c("age", "oc", "vic", "vicl", "vis", "dia") ) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "case") }) test_that("get_response", { expect_equal(get_response(m1), sex2$case) }) test_that("get_predictors", { expect_equal( colnames(get_predictors(m1)), c("age", "oc", "vic", "vicl", "vis", "dia") ) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), plogis(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 239) expect_equal( colnames(get_data(m1)), c("case", "age", "oc", "vic", "vicl", "vis", "dia") ) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("case ~ age + oc + vic + vicl + vis + dia")) ) }) test_that("find_terms", { expect_equal(find_terms(m1), list( response = "case", conditional = c("age", "oc", "vic", "vicl", "vis", "dia") )) expect_equal( find_terms(m1, flatten = TRUE), c("case", "age", "oc", "vic", "vicl", "vis", "dia") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 239) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("linkinverse", { expect_false(is.null(link_inverse(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "age", "oc", "vic", "vicl", "vis", "dia") ) ) expect_equal(nrow(get_parameters(m1)), 7) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "age", "oc", "vic", "vicl", "vis", "dia") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_algorithm", { expect_equal(find_algorithm(m1), list(algorithm = "Penalized ML")) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "chi-squared statistic") }) } insight/tests/testthat/test-clm2.R0000644000176200001440000000577213552364343016701 0ustar liggesusersif (require("testthat") && require("insight") && require("ordinal") && require("MASS")) { context("insight, model_info") data(housing, package = "MASS") m1 <- clm2(Sat ~ Infl + Type + Cont, weights = Freq, data = housing) test_that("model_info", { expect_true(model_info(m1)$is_ordinal) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("Infl", "Type", "Cont"))) expect_identical( find_predictors(m1, flatten = TRUE), c("Infl", "Type", "Cont") ) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "Sat") }) test_that("get_response", { expect_equal(get_response(m1), housing$Sat) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("Infl", "Type", "Cont")) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), plogis(.2), tolerance = 1e-5) }) test_that("find_weights", { expect_equal(find_weights(m1), "Freq") }) test_that("get_weights", { expect_equal(get_weights(m1), housing$Freq) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 72) expect_equal( colnames(get_data(m1)), c("Sat", "Infl", "Type", "Cont", "(weights)", "Freq") ) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("Sat ~ Infl + Type + Cont")) ) }) test_that("find_terms", { expect_equal(find_terms(m1), list( response = "Sat", conditional = c("Infl", "Type", "Cont") )) expect_equal( find_terms(m1, flatten = TRUE), c("Sat", "Infl", "Type", "Cont") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 1681) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("linkinv", { expect_false(is.null(link_inverse(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c( "Low|Medium", "Medium|High", "InflMedium", "InflHigh", "TypeApartment", "TypeAtrium", "TypeTerrace", "ContHigh" ) ) ) expect_equal(nrow(get_parameters(m1)), 8) expect_equal( get_parameters(m1)$Parameter, c( "Low|Medium", "Medium|High", "InflMedium", "InflHigh", "TypeApartment", "TypeAtrium", "TypeTerrace", "ContHigh" ) ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") }) } insight/tests/testthat/test-negbin.R0000644000176200001440000001014413552364343017273 0ustar liggesusers.runThisTest <- Sys.getenv("RunAllinsightTests") == "yes" if (.runThisTest && Sys.getenv("USER") != "travis") { if (require("testthat") && require("insight") && require("aod")) { context("insight, negbin") data(dja) m1 <- aod::negbin(y ~ group + offset(log(trisk)), random = ~village, data = dja ) test_that("model_info", { expect_true(model_info(m1)$is_negbin) expect_true(model_info(m1)$is_mixed) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("group", "trisk"))) expect_identical(find_predictors(m1, flatten = TRUE), c("group", "trisk")) expect_identical( find_predictors(m1, effects = "random"), list(random = "village") ) expect_identical( find_predictors(m1, effects = "all"), list( conditional = c("group", "trisk"), random = "village" ) ) }) test_that("find_random", { expect_identical(find_random(m1), list(random = "village")) }) test_that("get_random", { expect_equal(get_random(m1), dja[, "village", drop = FALSE]) }) test_that("find_response", { expect_identical(find_response(m1), "y") expect_identical(find_response(m1, combine = FALSE), "y") }) test_that("get_response", { expect_equal(get_response(m1), dja[, "y"]) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("group", "trisk")) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), exp(.2), tolerance = 1e-5) }) test_that("link_function", { expect_equal(link_function(m1)(.2), log(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 75) expect_equal(colnames(get_data(m1)), c("y", "group", "trisk", "village")) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_equal( find_formula(m1), list( conditional = as.formula("y ~ group + offset(log(trisk))"), random = as.formula("~village") ) ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "y", conditional = c("group", "trisk"), random = "village" ) ) expect_equal( find_variables(m1, flatten = TRUE), c("y", "group", "trisk", "village") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 75) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "groupTREAT"), random = c( "phi.villageBAK", "phi.villageBAM", "phi.villageBAN", "phi.villageBIJ", "phi.villageBOU", "phi.villageBYD", "phi.villageDEM", "phi.villageDIA", "phi.villageHAM", "phi.villageLAM", "phi.villageLAY", "phi.villageMAF", "phi.villageMAH", "phi.villageMAK", "phi.villageMED", "phi.villageNAB", "phi.villageSAG", "phi.villageSAM", "phi.villageSOU" ) ) ) expect_equal(nrow(get_parameters(m1)), 2) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "groupTREAT") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "y", conditional = c("group", "offset(log(trisk))"), random = "village" ) ) }) test_that("find_algorithm", { expect_equal(find_algorithm(m1), list(algorithm = "ML")) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") }) } } insight/tests/testthat/test-BayesFactorBF.R0000644000176200001440000001316413602213235020435 0ustar liggesusersif (require("testthat") && require("insight") && require("stats") && require("BayesFactor")) { context("BF correlation") x <- correlationBF(y = iris$Sepal.Length, x = iris$Sepal.Width) test_that("get_data", { expect_true(is.data.frame(get_data(x))) }) test_that("find_formula", { expect_null(find_formula(x)) }) test_that("get_parameters", { expect_equal(nrow(get_parameters(x)), 4000) }) # --------------------------- # context("BF t.test one sample") # data(sleep) # # x <- ttestBF(x = sleep$extra[sleep$group == 1], # y = sleep$extra[sleep$group == 2], # paired = TRUE) # # test_that("get_data", { # expect_true(is.data.frame(get_data(x))) # }) # test_that("find_formula", { # expect_null(find_formula(x)) # }) # test_that("get_parameters", { # expect_equal(nrow(get_parameters(x)), 4000) # }) # --------------------------- context("BF t.test two samples") data(chickwts) chickwts <- chickwts[chickwts$feed %in% c("horsebean", "linseed"), ] chickwts$feed <- factor(chickwts$feed) x <- ttestBF(formula = weight ~ feed, data = chickwts) test_that("get_data", { expect_true(is.data.frame(get_data(x))) }) test_that("find_formula", { expect_null(find_formula(x)) }) test_that("get_parameters", { expect_equal(nrow(get_parameters(x)), 4000) }) # --------------------------- context("BF t.test meta-analytic") t <- c(-.15, 2.39, 2.42, 2.43) N <- c(100, 150, 97, 99) x <- meta.ttestBF(t = t, n1 = N, rscale = 1) test_that("get_data", { expect_true(is.data.frame(get_data(x))) }) test_that("find_formula", { expect_null(find_formula(x)) }) test_that("get_parameters", { expect_equal(nrow(get_parameters(x)), 4000) }) # --------------------------- context("BF ANOVA") data(ToothGrowth) ToothGrowth$dose <- factor(ToothGrowth$dose) levels(ToothGrowth$dose) <- c("Low", "Medium", "High") x <- anovaBF(len ~ supp * dose, data = ToothGrowth) test_that("get_data", { expect_true(is.data.frame(get_data(x))) }) test_that("find_formula", { expect_equal(find_formula(x), list(conditional = as.formula("len ~ supp + dose + supp:dose"))) }) test_that("get_parameters", { expect_equal(colnames(get_parameters(x)), c("mu", "supp-OJ", "supp-VC", "sig2", "g_supp")) }) # --------------------------- context("BF ANOVA Random") data(puzzles) x <- anovaBF(RT ~ shape * color + ID, data = puzzles, whichRandom = "ID") test_that("get_data", { expect_true(is.data.frame(get_data(x))) }) test_that("find_formula", { expect_equal( find_formula(x), list( conditional = as.formula("RT ~ shape + color + shape:color"), random = as.formula("~ID") ) ) }) test_that("get_parameters", { expect_equal( colnames(get_parameters(x)), c( "mu", "shape-round", "shape-square", "ID-1", "ID-2", "ID-3", "ID-4", "ID-5", "ID-6", "ID-7", "ID-8", "ID-9", "ID-10", "ID-11", "ID-12", "sig2", "g_shape", "g_ID" ) ) }) test_that("find_response", { expect_equal(find_response(x), "RT") }) test_that("find_random", { expect_equal(find_random(x), list(random = "ID")) }) test_that("find_variables", { expect_equal( find_variables(x), list( response = "RT", conditional = c("shape", "color"), random = "ID" ) ) }) test_that("find_terms", { expect_equal( find_terms(x), list( response = "RT", conditional = c("shape", "color"), random = "ID" ) ) }) test_that("get_priors", { expect_equal( get_priors(x), data.frame( Parameter = c("fixed", "random", "continuous"), Distribution = c("cauchy", "cauchy", "cauchy"), Location = c(0, 0, 0), Scale = c(0.5, 1, 0.353553390593274), stringsAsFactors = FALSE, row.names = NULL ), tolerance = 1e-5 ) }) # --------------------------- context("BF lm") x <- lmBF(len ~ supp + dose, data = ToothGrowth) test_that("get_data", { expect_true(is.data.frame(get_data(x))) }) test_that("find_formula", { expect_equal(find_formula(x), list(conditional = as.formula("len ~ supp + dose"))) }) test_that("get_parameters", { expect_equal( colnames(get_parameters(x)), c( "mu", "supp-OJ", "supp-VC", "dose-Low", "dose-Medium", "dose-High", "sig2", "g_supp", "g_dose" ) ) }) x2 <- lmBF(len ~ supp + dose + supp:dose, data = ToothGrowth) x <- x / x2 test_that("get_data", { expect_true(is.data.frame(get_data(x))) }) test_that("find_formula", { expect_equal(find_formula(x), list(conditional = as.formula("len ~ supp + dose"))) }) test_that("get_parameters", { expect_equal( colnames(get_parameters(x)), c( "mu", "supp-OJ", "supp-VC", "dose-Low", "dose-Medium", "dose-High", "sig2", "g_supp", "g_dose" ) ) }) test_that("get_priors", { expect_equal( get_priors(x), data.frame( Parameter = c("fixed", "random", "continuous"), Distribution = c("cauchy", "cauchy", "cauchy"), Location = c(0, 0, 0), Scale = c(0.5, 1, 0.353553390593274), stringsAsFactors = FALSE, row.names = NULL ), tolerance = 1e-5 ) }) test_that("find_statistic", { expect_null(find_statistic(x)) }) } insight/tests/testthat/test-betabin.R0000644000176200001440000000712013552364343017435 0ustar liggesusersif (require("testthat") && require("insight") && require("aod")) { context("insight, betabin") data(dja) m1 <- betabin(cbind(y, n - y) ~ group * trisk, ~village, data = dja) test_that("model_info", { expect_true(model_info(m1)$is_binomial) expect_true(model_info(m1)$is_betabinomial) expect_true(model_info(m1)$is_mixed) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("group", "trisk"))) expect_identical(find_predictors(m1, flatten = TRUE), c("group", "trisk")) expect_identical(find_predictors(m1, effects = "random"), list(random = "village")) expect_identical( find_predictors(m1, effects = "all"), list( conditional = c("group", "trisk"), random = "village" ) ) }) test_that("find_random", { expect_identical(find_random(m1), list(random = "village")) }) test_that("get_random", { expect_equal(get_random(m1), dja[, "village", drop = FALSE]) }) test_that("find_response", { expect_identical(find_response(m1), "cbind(y, n - y)") expect_identical(find_response(m1, combine = FALSE), c("y", "n")) }) test_that("get_response", { expect_equal(get_response(m1), dja[, c("y", "n")]) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("group", "trisk")) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), plogis(.2), tolerance = 1e-5) }) test_that("link_function", { expect_equal(link_function(m1)(.2), qlogis(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 75) expect_equal(colnames(get_data(m1)), c("y", "n", "group", "trisk", "village")) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_equal( find_formula(m1), list( conditional = as.formula("cbind(y, n - y) ~ group * trisk"), random = as.formula("~village") ) ) }) test_that("find_variables", { expect_equal(find_variables(m1), list(response = c("y", "n"), conditional = c("group", "trisk"), random = "village")) expect_equal(find_variables(m1, flatten = TRUE), c("y", "n", "group", "trisk", "village")) }) test_that("n_obs", { expect_equal(n_obs(m1), 75) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "groupTREAT", "trisk", "groupTREAT:trisk"), random = c( "phi.villageBAK", "phi.villageBAM", "phi.villageBAN", "phi.villageBIJ", "phi.villageBOU", "phi.villageBYD", "phi.villageDEM", "phi.villageDIA", "phi.villageHAM", "phi.villageLAM", "phi.villageLAY", "phi.villageMAF", "phi.villageMAH", "phi.villageMAK", "phi.villageMED", "phi.villageNAB", "phi.villageSAG", "phi.villageSAM", "phi.villageSOU" ) ) ) expect_equal(nrow(get_parameters(m1)), 4) expect_equal(get_parameters(m1)$Parameter, c("(Intercept)", "groupTREAT", "trisk", "groupTREAT:trisk")) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "cbind(y, n - y)", conditional = c("group", "trisk"), random = "village" ) ) }) test_that("find_algorithm", { expect_equal(find_algorithm(m1), list(algorithm = "ML")) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") }) } insight/tests/testthat/test-BBreg.R0000644000176200001440000000573613552364343017025 0ustar liggesusersif (require("testthat") && require("insight") && require("HRQoL")) { context("insight, BBreg") set.seed(18) k <- 1000 m <- 10 x <- rnorm(k, 5, 3) x2 <- rnorm(k, 7, 3.5) j <- runif(k, 0, 5) fac <- sample(letters[1:4], k, TRUE) beta <- c(-10, 2) p <- 1 / (1 + exp(-(beta[1] + beta[2] * x))) phi <- 1.2 y <- HRQoL::rBB(k, m, p, phi) dat <- data.frame(y, x, x2, j, fac) m1 <- BBreg(y ~ x + x2 + j + fac, m, data = dat) test_that("model_info", { expect_true(model_info(m1)$is_binomial) expect_true(model_info(m1)$is_betabinomial) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("x", "x2", "j", "fac"))) expect_identical(find_predictors(m1, flatten = TRUE), c("x", "x2", "j", "fac")) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "y") }) test_that("get_response", { expect_equal(get_response(m1), dat$y) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("x", "x2", "j", "fac")) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), plogis(.2), tolerance = 1e-5) }) test_that("link_function", { expect_equal(link_function(m1)(.2), qlogis(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 1000) expect_equal(colnames(get_data(m1)), c("y", "x", "x2", "j", "fac")) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("y ~ x + x2 + j + fac")) ) }) test_that("find_variables", { expect_equal(find_variables(m1), list( response = "y", conditional = c("x", "x2", "j", "fac") )) expect_equal( find_variables(m1, flatten = TRUE), c("y", "x", "x2", "j", "fac") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 1000) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("Intercept", "x", "x2", "j", "facb", "facc", "facd") ) ) expect_equal(nrow(get_parameters(m1)), 7) expect_equal( get_parameters(m1)$Parameter, c("Intercept", "x", "x2", "j", "facb", "facc", "facd") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "y", conditional = c("x", "x2", "j", "fac") ) ) }) test_that("find_algorithm", { expect_equal(find_algorithm(m1), list(algorithm = "ML")) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") }) } insight/tests/testthat/test-censReg.R0000644000176200001440000000744413552364343017430 0ustar liggesusersif (require("testthat") && require("insight") && require("censReg") && require("AER")) { context("insight, censReg") data("Affairs", package = "AER") m1 <- censReg(affairs ~ age + yearsmarried + religiousness + occupation + rating, data = Affairs ) test_that("model_info", { expect_true(model_info(m1)$is_linear) expect_true(model_info(m1)$is_censored) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list( conditional = c( "age", "yearsmarried", "religiousness", "occupation", "rating" ) )) expect_identical( find_predictors(m1, flatten = TRUE), c( "age", "yearsmarried", "religiousness", "occupation", "rating" ) ) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "affairs") }) test_that("get_response", { expect_equal(get_response(m1), Affairs$affairs) }) test_that("get_predictors", { expect_equal( colnames(get_predictors(m1)), c( "age", "yearsmarried", "religiousness", "occupation", "rating" ) ) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 601) expect_equal( colnames(get_data(m1)), c( "affairs", "age", "yearsmarried", "religiousness", "occupation", "rating" ) ) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list( conditional = as.formula( "affairs ~ age + yearsmarried + religiousness + occupation + rating" ) ) ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "affairs", conditional = c( "age", "yearsmarried", "religiousness", "occupation", "rating" ) ) ) expect_equal( find_variables(m1, flatten = TRUE), c( "affairs", "age", "yearsmarried", "religiousness", "occupation", "rating" ) ) }) test_that("n_obs", { expect_equal(n_obs(m1), 601) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c( "(Intercept)", "age", "yearsmarried", "religiousness", "occupation", "rating", "logSigma" ) ) ) expect_equal(nrow(get_parameters(m1)), 7) expect_equal( get_parameters(m1)$Parameter, c( "(Intercept)", "age", "yearsmarried", "religiousness", "occupation", "rating", "logSigma" ) ) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "affairs", conditional = c( "age", "yearsmarried", "religiousness", "occupation", "rating" ) ) ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") }) } insight/tests/testthat/test-gbm.R0000644000176200001440000000630213552364343016577 0ustar liggesusers.runThisTest <- Sys.getenv("RunAllinsightTests") == "yes" if (.runThisTest || Sys.getenv("USER") == "travis") { if (require("testthat") && require("insight") && require("gbm")) { context("insight, gbm") set.seed(102) # for reproducibility m1 <- gbm( mpg ~ gear + cyl + wt, data = mtcars, var.monotone = c(0, 0, 0), distribution = "gaussian", shrinkage = 0.1, interaction.depth = 1, bag.fraction = 0.5, train.fraction = 0.5, n.minobsinnode = 1, cv.folds = 3, keep.data = TRUE, verbose = FALSE, n.cores = 1 ) test_that("model_info", { expect_true(model_info(m1)$is_linear) expect_false(model_info(m1)$is_binomial) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("gear", "cyl", "wt"))) expect_identical( find_predictors(m1, flatten = TRUE), c("gear", "cyl", "wt") ) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "mpg") }) test_that("get_response", { expect_equal(get_response(m1), mtcars$mpg) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("gear", "cyl", "wt")) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 32) expect_equal(colnames(get_data(m1)), c("mpg", "gear", "cyl", "wt")) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("mpg ~ gear + cyl + wt")) ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "mpg", conditional = c("gear", "cyl", "wt") ) ) expect_equal( find_variables(m1, flatten = TRUE), c("mpg", "gear", "cyl", "wt") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 32) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { skip_on_travis() expect_equal( find_parameters(m1), list(conditional = c("wt", "gear", "cyl")) ) expect_equal(nrow(get_parameters(m1)), 3) expect_equal(get_parameters(m1)$Parameter, c("wt", "gear", "cyl")) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "mpg", conditional = c("gear", "cyl", "wt") ) ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_algorithm", { expect_warning(expect_null(find_algorithm(m1))) }) test_that("find_statistic", { expect_null(find_statistic(m1)) }) } } insight/tests/testthat/test-glmmTMB.R0000644000176200001440000005246313576214614017343 0ustar liggesusersif (require("testthat") && require("insight") && require("glmmTMB")) { context("insight, glmmTMB") # fish <- read.csv("https://stats.idre.ucla.edu/stat/data/fish.csv") # fish$nofish <- as.factor(fish$nofish) # fish$livebait <- as.factor(fish$livebait) # fish$camper <- as.factor(fish$camper) m1 <- download_model("glmmTMB_zi_1") m2 <- download_model("glmmTMB_1") m3 <- download_model("glmmTMB_zi_2") m4 <- download_model("glmmTMB_zi_5") m7 <- download_model("glmmTMB_zi_6") fish <- get_data(m7) data(Salamanders) m5 <- glmmTMB( count ~ mined + (1 | site), ziformula = ~mined, family = poisson, data = Salamanders ) m6 <- glmmTMB(count ~ 1, ziformula = ~1, family = poisson(), data = Salamanders ) test_that("find_weights", { expect_null(find_weights(m2)) }) test_that("get_weights", { expect_null(get_weights(m2)) }) test_that("model_info", { expect_true(model_info(m1)$is_zero_inflated) expect_false(model_info(m2)$is_zero_inflated) expect_true(model_info(m3)$is_count) expect_true(model_info(m3)$is_pois) expect_false(model_info(m3)$is_negbin) expect_true(model_info(m6)$is_count) }) test_that("clean_names", { expect_identical(clean_names(m1), c("count", "child", "camper", "persons")) expect_identical(clean_names(m2), c("count", "child", "camper", "persons")) expect_identical( clean_names(m3), c("count", "child", "camper", "persons", "livebait") ) expect_identical( clean_names(m4), c( "count", "child", "camper", "persons", "livebait", "ID", "xb" ) ) expect_identical(clean_names(m6), c("count")) }) test_that("find_predictors", { expect_identical( find_predictors(m1, effects = "all"), list( conditional = c("child", "camper"), random = "persons", zero_inflated = c("child", "camper"), zero_inflated_random = "persons" ) ) expect_identical( find_predictors(m1, effects = "all", flatten = TRUE), c("child", "camper", "persons") ) expect_identical( find_predictors(m1, effects = "random"), list(random = "persons", zero_inflated_random = "persons") ) expect_identical( find_predictors(m1, effects = "random", flatten = TRUE), "persons" ) expect_identical( find_predictors(m1, effects = "random", component = "conditional"), list(random = "persons") ) expect_identical( find_predictors( m1, effects = "random", component = "conditional", flatten = TRUE ), "persons" ) expect_identical( find_predictors(m1), list( conditional = c("child", "camper"), zero_inflated = c("child", "camper") ) ) expect_identical(find_predictors(m1, flatten = TRUE), c("child", "camper")) expect_identical( find_predictors(m2, effects = "all"), list( conditional = c("child", "camper"), random = "persons" ) ) expect_identical( find_predictors(m2, effects = "all", flatten = TRUE), c("child", "camper", "persons") ) expect_identical( find_predictors(m2, effects = "random"), list(random = "persons") ) expect_identical( find_predictors(m2, effects = "random", flatten = TRUE), "persons" ) expect_identical(find_predictors(m2), list(conditional = c("child", "camper"))) expect_null(find_predictors(m6)) }) test_that("find_response", { expect_identical(find_response(m1), "count") expect_identical(find_response(m2), "count") expect_identical(find_response(m6), "count") }) test_that("link_inverse", { expect_identical(link_inverse(m1)(.2), exp(.2)) expect_identical(link_inverse(m2)(.2), exp(.2)) }) test_that("get_data", { expect_equal( colnames(get_data(m1)), c("count", "child", "camper", "persons") ) expect_equal( colnames(get_data(m1, effects = "all")), c("count", "child", "camper", "persons") ) expect_equal(colnames(get_data(m1, effects = "random")), "persons") expect_equal( colnames(get_data(m2)), c("count", "child", "camper", "persons") ) expect_equal( colnames(get_data(m2, effects = "all")), c("count", "child", "camper", "persons") ) expect_equal(colnames(get_data(m2, effects = "random")), "persons") get_data(m3) expect_equal(colnames(get_data(m6)), "count") expect_null(get_data(m6, effects = "random")) }) test_that("find_predictors", { expect_identical( find_predictors(m3, effects = "fixed", component = "conditional"), list(conditional = c("child", "camper")) ) expect_identical( find_predictors( m3, effects = "fixed", component = "conditional", flatten = TRUE ), c("child", "camper") ) expect_identical( find_predictors(m3, effects = "fixed", component = "zero_inflated"), list(zero_inflated = c("child", "livebait")) ) expect_identical( find_predictors( m3, effects = "fixed", component = "zero_inflated", flatten = TRUE ), c("child", "livebait") ) expect_identical( find_predictors(m3, effects = "all", component = "conditional"), list( conditional = c("child", "camper"), random = "persons" ) ) expect_identical( find_predictors( m3, effects = "all", component = "conditional", flatten = TRUE ), c("child", "camper", "persons") ) expect_identical( find_predictors(m3, effects = "all", component = "zero_inflated"), list( zero_inflated = c("child", "livebait"), zero_inflated_random = "persons" ) ) expect_identical( find_predictors( m3, effects = "all", component = "zero_inflated", flatten = TRUE ), c("child", "livebait", "persons") ) expect_identical( find_predictors(m3, effects = "random", component = "conditional"), list(random = "persons") ) expect_identical( find_predictors( m3, effects = "random", component = "conditional", flatten = TRUE ), "persons" ) expect_identical( find_predictors(m3, effects = "random", component = "zero_inflated"), list(zero_inflated_random = "persons") ) expect_identical( find_predictors( m3, effects = "random", component = "zero_inflated", flatten = TRUE ), "persons" ) expect_identical( find_predictors(m3, effects = "fixed", component = "all"), list( conditional = c("child", "camper"), zero_inflated = c("child", "livebait") ) ) expect_identical( find_predictors( m3, effects = "fixed", component = "all", flatten = TRUE ), c("child", "camper", "livebait") ) expect_identical( find_predictors(m3, effects = "all", component = "all"), list( conditional = c("child", "camper"), random = "persons", zero_inflated = c("child", "livebait"), zero_inflated_random = "persons" ) ) expect_identical( find_predictors( m3, effects = "all", component = "all", flatten = TRUE ), c("child", "camper", "persons", "livebait") ) expect_identical( find_predictors(m3, effects = "random", component = "all"), list(random = "persons", zero_inflated_random = "persons") ) expect_identical( find_predictors( m3, effects = "random", component = "all", flatten = TRUE ), "persons" ) expect_null(find_predictors( m6, effects = "random", component = "all", flatten = TRUE )) }) test_that("find_formula", { expect_length(find_formula(m4), 5) expect_equal( find_formula(m4), list( conditional = as.formula("count ~ child + camper"), random = as.formula("~1 | persons"), zero_inflated = as.formula("~child + livebait"), zero_inflated_random = as.formula("~1 | ID"), dispersion = as.formula("~xb") ) ) expect_equal(find_formula(m6), list(conditional = as.formula("count ~ 1"))) }) test_that("find_predictors", { expect_identical( find_predictors(m4), list( conditional = c("child", "camper"), zero_inflated = c("child", "livebait"), dispersion = "xb" ) ) expect_identical( find_predictors(m4, flatten = TRUE), c("child", "camper", "livebait", "xb") ) expect_identical( find_predictors(m4, effects = "random"), list(random = "persons", zero_inflated_random = "ID") ) expect_identical( find_predictors(m4, effects = "all", flatten = TRUE), c("child", "camper", "persons", "livebait", "ID", "xb") ) expect_identical( find_predictors(m4, effects = "all"), list( conditional = c("child", "camper"), random = "persons", zero_inflated = c("child", "livebait"), zero_inflated_random = "ID", dispersion = "xb" ) ) expect_identical( find_predictors(m4, component = "conditional", flatten = TRUE), c("child", "camper") ) expect_identical( find_predictors(m4, component = "conditional", flatten = FALSE), list(conditional = c("child", "camper")) ) expect_identical( find_predictors(m4, effects = "random", component = "conditional"), list(random = "persons") ) expect_identical( find_predictors(m4, effects = "all", component = "conditional"), list( conditional = c("child", "camper"), random = "persons" ) ) expect_identical( find_predictors(m4, component = "zero_inflated"), list(zero_inflated = c("child", "livebait")) ) expect_identical( find_predictors(m4, effects = "random", component = "zero_inflated"), list(zero_inflated_random = "ID") ) expect_identical( find_predictors( m4, effects = "all", component = "zero_inflated", flatten = TRUE ), c("child", "livebait", "ID") ) expect_identical( find_predictors(m4, component = "dispersion"), list(dispersion = "xb") ) expect_identical( find_predictors(m4, component = "dispersion", flatten = TRUE), "xb" ) expect_null(find_predictors(m4, effects = "random", component = "dispersion")) expect_identical( find_predictors(m4, effects = "all", component = "dispersion"), list(dispersion = "xb") ) expect_identical( find_predictors( m4, effects = "all", component = "dispersion", flatten = TRUE ), "xb" ) }) test_that("find_random", { expect_identical( find_random(m4), list(random = "persons", zero_inflated_random = "ID") ) expect_identical(find_random(m4, flatten = TRUE), c("persons", "ID")) expect_null(find_random(m6, flatten = TRUE)) }) test_that("find_respone", { expect_identical(find_response(m4), "count") expect_identical(find_response(m6), "count") }) test_that("find_terms", { expect_identical( find_terms(m4), list( response = "count", conditional = c("child", "camper"), random = "persons", zero_inflated = c("child", "livebait"), zero_inflated_random = "ID", dispersion = "xb" ) ) expect_identical( find_terms(m4, flatten = TRUE), c( "count", "child", "camper", "persons", "livebait", "ID", "xb" ) ) expect_identical(find_terms(m6), list(response = "count", conditional = "1")) expect_identical(find_terms(m6, flatten = TRUE), c("count", "1")) }) test_that("find_variables", { expect_identical( find_variables(m4), list( response = "count", conditional = c("child", "camper"), random = "persons", zero_inflated = c("child", "livebait"), zero_inflated_random = "ID", dispersion = "xb" ) ) expect_identical( find_variables(m4, flatten = TRUE), c( "count", "child", "camper", "persons", "livebait", "ID", "xb" ) ) expect_identical(find_variables(m6), list(response = "count")) expect_identical(find_variables(m6, flatten = TRUE), "count") }) test_that("get_response", { expect_identical(get_response(m4), fish$count) expect_identical(get_response(m6), Salamanders$count) }) test_that("get_predictors", { expect_identical( colnames(get_predictors(m4)), c("child", "camper", "livebait", "xb") ) expect_null(get_predictors(m6)) }) test_that("get_random", { expect_identical(colnames(get_random(m4)), c("persons", "ID")) expect_warning(expect_null(get_random(m6))) }) test_that("get_data", { expect_identical( colnames(get_data(m4)), c( "count", "child", "camper", "livebait", "xb", "persons", "ID" ) ) expect_identical( colnames(get_data(m4, effects = "fixed")), c("count", "child", "camper", "livebait", "xb") ) expect_identical(colnames(get_data(m4, effects = "random")), c("persons", "ID")) expect_identical(colnames(get_data(m4, component = "zi")), c("count", "child", "livebait", "ID")) expect_identical(colnames(get_data( m4, component = "zi", effects = "fixed" )), c("count", "child", "livebait")) expect_identical(colnames(get_data( m4, component = "zi", effects = "random" )), "ID") expect_identical( colnames(get_data(m4, component = "cond")), c("count", "child", "camper", "persons") ) expect_identical(colnames(get_data( m4, component = "cond", effects = "fixed" )), c("count", "child", "camper")) expect_identical(colnames(get_data( m4, component = "cond", effects = "random" )), "persons") expect_identical(colnames(get_data(m4, component = "disp")), c("count", "xb")) expect_identical(colnames(get_data( m4, component = "disp", effects = "fixed" )), c("count", "xb")) expect_null(get_data(m4, component = "disp", effects = "random")) }) test_that("find_paramaters", { expect_equal( find_parameters(m4), list( conditional = c("(Intercept)", "child", "camper1"), random = list(persons = "(Intercept)"), zero_inflated = c("(Intercept)", "child", "livebait1"), zero_inflated_random = list(ID = "(Intercept)") ) ) expect_equal( find_parameters(m4, flatten = TRUE), c("(Intercept)", "child", "camper1", "livebait1") ) expect_equal( find_parameters(m6), list( conditional = "(Intercept)", zero_inflated = "(Intercept)" ) ) expect_equal( find_parameters(m3), list( conditional = c("(Intercept)", "child", "camper1"), random = list(persons = "(Intercept)"), zero_inflated = c("(Intercept)", "child", "livebait1"), zero_inflated_random = list(persons = "(Intercept)") ) ) expect_equal( find_parameters(m3), list( conditional = c("(Intercept)", "child", "camper1"), random = list(persons = "(Intercept)"), zero_inflated = c("(Intercept)", "child", "livebait1"), zero_inflated_random = list(persons = "(Intercept)") ) ) expect_equal( find_parameters(m3, effects = "fixed"), list( conditional = c("(Intercept)", "child", "camper1"), zero_inflated = c("(Intercept)", "child", "livebait1") ) ) expect_equal( find_parameters(m3, effects = "random", component = "zi"), list(zero_inflated_random = list(persons = "(Intercept)")) ) expect_equal( find_parameters( m3, effects = "fixed", component = "zi", flatten = TRUE ), c("(Intercept)", "child", "livebait1") ) }) test_that("get_paramaters", { expect_equal(nrow(get_parameters(m4)), 6) expect_equal( colnames(get_parameters(m4)), c("Parameter", "Estimate", "Component") ) expect_equal( get_parameters(m4)$Parameter, c( "(Intercept)", "child", "camper1", "(Intercept)", "child", "livebait1" ) ) expect_equal( get_parameters(m4)$Component, c( "conditional", "conditional", "conditional", "zero_inflated", "zero_inflated", "zero_inflated" ) ) expect_equal( get_parameters(m6)$Parameter, c("(Intercept)", "(Intercept)") ) expect_equal( get_parameters(m2)$Parameter, c("(Intercept)", "child", "camper1") ) expect_equal( get_parameters(m2, component = "all")$Parameter, c("(Intercept)", "child", "camper1") ) expect_null(get_parameters(m2, component = "zi")) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) expect_false(is.null(link_function(m2))) expect_false(is.null(link_function(m3))) expect_false(is.null(link_function(m4))) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) expect_false(is_multivariate(m2)) expect_false(is_multivariate(m3)) expect_false(is_multivariate(m4)) }) # test_that("get_variance", { # # expect_warning(expect_equal(get_variance(m5), list( # var.fixed = 0.32588694431268194762, # var.random = 0.07842738279575413307, # var.residual = 0.41218000030914692111, # var.distribution = 0.41218000030914692111, # var.dispersion = 0, # var.intercept = c(site = 0.07842738279575474369) # ), # tolerance = 1e-3)) # # expect_warning(expect_equal(get_variance_fixed(m1), c(var.fixed = 1.09712435712435052437), tolerance = 1e-3)) # expect_warning(expect_equal(get_variance_random(m1), c(var.random = 0.86712737445492238386), tolerance = 1e-3)) # expect_warning(expect_equal(get_variance_residual(m1), c(var.residual = 0.02634500773355940087 ), tolerance = 1e-3)) # expect_warning(expect_equal(get_variance_distribution(m1), c(var.distribution = 0.02634500773355940087 ), tolerance = 1e-3)) # expect_warning(expect_equal(get_variance_dispersion(m1), c(var.dispersion = 0), tolerance = 1e-3)) # }) test_that("find_algorithm", { expect_equal( find_algorithm(m1), list(algorithm = "ML", optimizer = "nlminb") ) }) test_that("find_random_slopes", { skip_on_cran() skip_on_travis() expect_null(find_random_slopes(m6)) expect_equal( find_random_slopes(m7), list( random = "xb", zero_inflated_random = c("zg", "nofish") ) ) }) test_that("clean_parameters", { expect_equal( clean_parameters(m1), structure( list( Parameter = c( "(Intercept)", "child", "camper1", "(Intercept)", "(Intercept)", "child", "camper1", "(Intercept)" ), Effects = c( "fixed", "fixed", "fixed", "random", "fixed", "fixed", "fixed", "random" ), Component = c( "conditional", "conditional", "conditional", "conditional", "zero_inflated", "zero_inflated", "zero_inflated", "zero_inflated" ), Group = c("", "", "", "persons", "", "", "", "persons"), Cleaned_Parameter = c( "(Intercept)", "child", "camper1", "(Intercept)", "(Intercept)", "child", "camper1", "(Intercept)" ) ), class = c("clean_parameters", "data.frame"), row.names = c(NA, -8L) ) ) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") expect_identical(find_statistic(m2), "z-statistic") expect_identical(find_statistic(m3), "z-statistic") expect_identical(find_statistic(m4), "z-statistic") expect_identical(find_statistic(m5), "z-statistic") expect_identical(find_statistic(m6), "z-statistic") expect_identical(find_statistic(m7), "z-statistic") }) } insight/tests/testthat/test-all_models_equal.R0000644000176200001440000000125213524331052021321 0ustar liggesusersif (require("testthat") && require("insight")) { context("insight, all_models_equal") library(lme4) data(mtcars) data(sleepstudy) m1 <- lm(mpg ~ wt + cyl + vs, data = mtcars) m2 <- lm(mpg ~ wt + cyl, data = mtcars) m3 <- lmer(Reaction ~ Days + (1 | Subject), data = sleepstudy) m4 <- glm(formula = vs ~ wt, family = binomial(), data = mtcars) test_that("all_models_equal", { expect_true(all_models_equal(m1, m2)) expect_false(all_models_equal(m1, m2, m3)) expect_message(expect_false(all_models_equal(m1, m4, m2, m3, verbose = TRUE))) expect_true(is_model_supported(m1)) expect_false(is_model_supported(mtcars)) }) } insight/tests/testthat/test-panelr.R0000644000176200001440000001371613556644712017327 0ustar liggesusersif (require("testthat") && require("insight") && require("panelr")) { context("insight, panelr") data("WageData") wages <- panel_data(WageData, id = id, wave = t) m1 <- wbm(lwage ~ lag(union) + wks | blk + fem | blk * lag(union), data = wages) m2 <- wbm(lwage ~ lag(union) + wks | blk + t | (t | id), data = wages) test_that("model_info", { expect_true(model_info(m1)$is_linear) expect_true(model_info(m2)$is_linear) }) test_that("find_predictors", { expect_identical( find_predictors(m1), list( conditional = c("union", "wks"), instruments = c("blk", "fem"), interactions = c("blk", "union") ) ) expect_identical( find_predictors(m1, flatten = TRUE), c("union", "wks", "blk", "fem") ) expect_null(find_predictors(m1, effects = "random")) expect_identical( find_predictors(m2), list( conditional = c("union", "wks"), instruments = c("blk", "t") ) ) expect_identical(find_predictors(m2, effects = "random"), list(random = "id")) }) test_that("find_random", { expect_null(find_random(m1)) expect_identical(find_random(m2), list(random = "id")) }) test_that("get_random", { expect_null(expect_warning(get_random(m1))) expect_equal(get_random(m2)[[1]], model.frame(m2)$id) }) test_that("find_response", { expect_identical(find_response(m1), "lwage") }) test_that("get_response", { expect_equal(get_response(m1), model.frame(m1)$lwage) }) test_that("get_predictors", { expect_equal( colnames(get_predictors(m1)), c("lag(union)", "wks", "blk", "fem") ) expect_equal( colnames(get_predictors(m2)), c("lag(union)", "wks", "blk", "t") ) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 3570) expect_equal( colnames(get_data(m1)), c( "lwage", "id", "t", "lag(union)", "wks", "blk", "fem", "imean(lag(union))", "imean(wks)", "lag(union)*blk", "imean(lag(union):blk)", "lag(union):blk" ) ) expect_equal( colnames(get_data(m2)), c( "lwage", "id", "t", "lag(union)", "wks", "blk", "imean(lag(union))", "imean(wks)" ) ) }) test_that("find_formula", { expect_length(find_formula(m1), 3) expect_equal( find_formula(m1), list( conditional = as.formula("lwage ~ lag(union) + wks"), instruments = as.formula("~blk + fem"), interactions = as.formula("~blk * lag(union)") ) ) expect_equal( find_formula(m2), list( conditional = as.formula("lwage ~ lag(union) + wks"), instruments = as.formula("~blk + t"), random = as.formula("~t | id") ) ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "lwage", conditional = c("union", "wks"), instruments = c("blk", "fem"), interactions = c("blk", "union") ) ) expect_equal( find_variables(m1, flatten = TRUE), c("lwage", "union", "wks", "blk", "fem") ) expect_equal( find_variables(m2), list( response = "lwage", conditional = c("union", "wks"), instruments = c("blk", "t"), random = "id" ) ) expect_equal( find_variables(m2, flatten = TRUE), c("lwage", "union", "wks", "blk", "t", "id") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 3570) expect_equal(n_obs(m2), 3570) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("lag(union)", "wks"), instruments = c("(Intercept)", "imean(lag(union))", "imean(wks)", "blk", "fem"), random = "lag(union):blk" ) ) expect_equal(nrow(get_parameters(m1)), 8) expect_equal( find_parameters(m2), list( conditional = c("lag(union)", "wks"), instruments = c("(Intercept)", "imean(lag(union))", "imean(wks)", "blk", "t") ) ) }) test_that("get_parameters", { expect_equal( get_parameters(m1), data.frame( Parameter = c( "lag(union)", "wks", "(Intercept)", "imean(lag(union))", "imean(wks)", "blk", "fem", "lag(union):blk" ), Estimate = c( 0.0582474262882615, -0.00163678667081885, 6.59813245629044, -0.0279959204722801, 0.00438047648390025, -0.229414915661438, -0.441756913071962, -0.127319623945541 ), Component = c( "within", "within", "between", "between", "between", "between", "between", "interactions" ), stringsAsFactors = FALSE ), tolerance = 1e-4 ) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "lwage", conditional = c("lag(union)", "wks"), instruments = c("blk", "fem"), interactions = c("blk", "lag(union)") ) ) expect_equal( find_terms(m2), list( response = "lwage", conditional = c("lag(union)", "wks"), instruments = c("blk", "t"), random = c("t", "id") ) ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") expect_identical(find_statistic(m2), "t-statistic") }) } insight/tests/testthat/test-survey.R0000644000176200001440000000414613552364343017373 0ustar liggesusersif (require("testthat") && require("insight") && require("survey")) { context("insight, svyglm") data(api) dstrat <- svydesign( id = ~1, strata = ~stype, weights = ~pw, data = apistrat, fpc = ~fpc ) m1 <- svyglm(api00 ~ ell + meals + mobility, design = dstrat) test_that("model_info", { expect_true(model_info(m1)$is_linear) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("ell", "meals", "mobility"))) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_response", { expect_identical(find_response(m1), "api00") }) test_that("get_response", { expect_equal(get_response(m1), apistrat$api00) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 200) expect_equal( colnames(get_data(m1)), c("api00", "ell", "meals", "mobility", "(weights)") ) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("api00 ~ ell + meals + mobility")) ) }) test_that("find_terms", { expect_equal(find_terms(m1), list( response = "api00", conditional = c("ell", "meals", "mobility") )) expect_equal( find_terms(m1, flatten = TRUE), c("api00", "ell", "meals", "mobility") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 200) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list(conditional = c( "(Intercept)", "ell", "meals", "mobility" )) ) expect_equal(nrow(get_parameters(m1)), 4) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "ell", "meals", "mobility") ) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") }) } insight/tests/testthat/test-rqss.R0000644000176200001440000000437213602457455017032 0ustar liggesusersif (require("testthat") && require("insight") && require("quantreg") && require("tripack")) { context("insight, model_info") data("CobarOre") set.seed(123) CobarOre$w <- rnorm(nrow(CobarOre)) # model m1 <- rqss(z ~ w + qss(cbind(x, y), lambda = .08), data = CobarOre) test_that("model_info", { expect_true(model_info(m1)$is_linear) }) test_that("find_predictors", { expect_identical( find_predictors(m1), list(conditional = c("w", "x", "y")) ) expect_identical( find_predictors(m1, flatten = TRUE), c("w", "x", "y") ) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "z") }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("z ~ w + qss(cbind(x, y), lambda = 0.08)")) ) }) test_that("find_terms", { expect_equal( find_terms(m1), list(response = "z", conditional = c("w", "qss(cbind(x, y), lambda = 0.08)")) ) expect_equal( find_terms(m1, flatten = TRUE), c("z", "w", "qss(cbind(x, y), lambda = 0.08)") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 38) }) test_that("link_function", { expect_equal(link_function(m1)(.2), .2, tolerance = 1e-5) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list(conditional = c("(Intercept)", "w"), smooth_terms = "cbind(x, y)") ) expect_equal(nrow(get_parameters(m1)), 3) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "w", "cbind(x, y)") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_algorithm", { expect_equal(find_algorithm(m1), list(algorithm = "sfn")) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") }) } insight/tests/testthat/test-speedglm.R0000644000176200001440000000605513552364343017637 0ustar liggesusersif (require("testthat") && require("insight") && require("speedglm") && require("glmmTMB")) { context("insight, model_info") data(Salamanders) Salamanders$cover <- abs(Salamanders$cover) m1 <- speedglm(count ~ mined + log(cover) + sample, family = poisson(), data = Salamanders ) test_that("model_info", { expect_true(model_info(m1)$is_poisson) expect_true(model_info(m1)$is_count) expect_false(model_info(m1)$is_negbin) expect_false(model_info(m1)$is_binomial) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("mined", "cover", "sample"))) expect_identical( find_predictors(m1, flatten = TRUE), c("mined", "cover", "sample") ) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "count") }) test_that("get_response", { expect_equal(get_response(m1), Salamanders$count) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("mined", "cover", "sample")) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), exp(.2), tolerance = 1e-5) }) test_that("linkfun", { expect_equal(link_function(m1)(.2), log(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 644) expect_equal( colnames(get_data(m1)), c("count", "mined", "cover", "sample") ) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("count ~ mined + log(cover) + sample")) ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "count", conditional = c("mined", "cover", "sample") ) ) expect_equal( find_variables(m1, flatten = TRUE), c("count", "mined", "cover", "sample") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 644) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "minedno", "log(cover)", "sample") ) ) expect_equal(nrow(get_parameters(m1)), 4) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "minedno", "log(cover)", "sample") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "count", conditional = c("mined", "log(cover)", "sample") ) ) }) test_that("find_algorithm", { expect_equal(find_algorithm(m1), list(algorithm = "eigen")) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") }) } insight/tests/testthat/test-nlmer.R0000644000176200001440000000062713602213235017140 0ustar liggesusersif (require("testthat") && require("insight") && require("lme4")) { set.seed(123) startvec <- c(Asym = 200, xmid = 725, scal = 350) nm1 <- lme4::nlmer( formula = circumference ~ SSlogis(age, Asym, xmid, scal) ~ Asym | Tree, data = Orange, start = startvec ) test_that("find_statistic", { expect_identical(find_statistic(nm1), "t-statistic") }) } insight/tests/testthat/test-survfit.R0000644000176200001440000000364213572501701017531 0ustar liggesusersif (require("testthat") && require("insight") && require("survival")) { data("lung") m1 <- survfit(Surv(time, status) ~ sex + age + ph.ecog, data = lung) test_that("model_info", { expect_true(model_info(m1)$is_logit) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("sex", "age", "ph.ecog"))) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_response", { expect_identical(find_response(m1), "Surv(time, status)") expect_identical(find_response(m1, combine = FALSE), c("time", "status")) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), plogis(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 227) expect_equal( colnames(get_data(m1)), c("time", "status", "age", "sex", "ph.ecog") ) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula( "Surv(time, status) ~ sex + age + ph.ecog" )) ) }) test_that("find_variables", { expect_equal(find_variables(m1), list( response = c("time", "status"), conditional = c("sex", "age", "ph.ecog") )) expect_equal( find_variables(m1, flatten = TRUE), c("time", "status", "sex", "age", "ph.ecog") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 227) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "Surv(time, status)", conditional = c("sex", "age", "ph.ecog") ) ) }) test_that("find_statistic", { expect_null(find_statistic(m1)) }) } insight/tests/testthat/test-aovlist.R0000644000176200001440000000761213552364343017520 0ustar liggesusersif (require("testthat") && require("insight") && require("stats")) { context("insight, aovlist") data(npk) m1 <- aov(yield ~ N * P * K + Error(block), data = npk) m2 <- aov(yield ~ N * P * K, data = npk) test_that("model_info", { expect_true(model_info(m1)$is_linear) expect_true(model_info(m1)$is_anova) expect_true(model_info(m2)$is_linear) expect_true(model_info(m2)$is_anova) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("N", "P", "K", "block"))) expect_identical(find_predictors(m2), list(conditional = c("N", "P", "K"))) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "yield") expect_identical(find_response(m2), "yield") }) test_that("get_response", { expect_equal(get_response(m1), npk$yield) expect_equal(get_response(m2), npk$yield) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("N", "P", "K", "block")) expect_equal(colnames(get_predictors(m2)), c("N", "P", "K")) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) expect_equal(link_inverse(m2)(.2), .2, tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 24) expect_equal(nrow(get_data(m2)), 24) expect_equal(colnames(get_data(m1)), c("yield", "N", "P", "K", "block")) expect_equal(colnames(get_data(m2)), c("yield", "N", "P", "K")) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("yield ~ N * P * K + Error(block)")) ) expect_length(find_formula(m2), 1) expect_equal( find_formula(m2), list(conditional = as.formula("yield ~ N * P * K")) ) }) test_that("find_terms", { expect_equal(find_terms(m1), list( response = "yield", conditional = c("N", "P", "K", "Error(block)") )) expect_equal( find_terms(m1, flatten = TRUE), c("yield", "N", "P", "K", "Error(block)") ) expect_equal(find_terms(m2), list( response = "yield", conditional = c("N", "P", "K") )) expect_equal(find_terms(m2, flatten = TRUE), c("yield", "N", "P", "K")) }) test_that("n_obs", { expect_equal(n_obs(m1), 24) expect_equal(n_obs(m2), 24) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) expect_false(is.null(link_function(m2))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "N1:P1:K1"), random = c("N1", "P1", "K1", "N1:P1", "N1:K1", "P1:K1") ) ) expect_equal(length(get_parameters(m1)), 2) expect_equal(nrow(get_parameters(m1, effects = "all")), 8) expect_equal( get_parameters(m1, effects = "all")$Effects, c( "fixed", "fixed", "random", "random", "random", "random", "random", "random" ) ) expect_equal( find_parameters(m2), list( conditional = c( "(Intercept)", "N1", "P1", "K1", "N1:P1", "N1:K1", "P1:K1", "N1:P1:K1" ) ) ) expect_equal(nrow(get_parameters(m2)), 8) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) expect_false(is_multivariate(m2)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "F-statistic") expect_identical(find_statistic(m2), "F-statistic") }) } insight/tests/testthat/test-felm.R0000644000176200001440000000760513554512447016766 0ustar liggesusersif (require("testthat") && require("insight") && require("lfe")) { context("insight, lfe") x <- rnorm(1000) x2 <- rnorm(length(x)) id <- factor(sample(20, length(x), replace = TRUE)) firm <- factor(sample(13, length(x), replace = TRUE)) id.eff <- rnorm(nlevels(id)) firm.eff <- rnorm(nlevels(firm)) u <- rnorm(length(x)) y <- x + 0.5 * x2 + id.eff[id] + firm.eff[firm] + u x3 <- rnorm(length(x)) x4 <- sample(12, length(x), replace = TRUE) Q <- 0.3 * x3 + x + 0.2 * x2 + id.eff[id] + 0.3 * log(x4) - 0.3 * y + rnorm(length(x), sd = 0.3) W <- 0.7 * x3 - 2 * x + 0.1 * x2 - 0.7 * id.eff[id] + 0.8 * cos(x4) - 0.2 * y + rnorm(length(x), sd = 0.6) # add them to the outcome y <- y + Q + W dat <- data.frame(y, x, x2, x3, x4, id, firm, Q, W) m1 <- felm(y ~ x + x2 | id + firm | (Q | W ~ x3 + factor(x4)), data = dat) test_that("model_info", { expect_true(model_info(m1)$is_linear) }) test_that("find_predictors", { expect_identical( find_predictors(m1), list( conditional = c("x", "x2"), instruments = c("Q", "W", "x3", "x4") ) ) expect_identical(find_predictors(m1, effects = "random"), list(random = c("id", "firm"))) expect_identical( find_predictors(m1, effects = "all", flatten = TRUE), c("x", "x2", "id", "firm", "Q", "W", "x3", "x4") ) }) test_that("find_random", { expect_identical(find_random(m1), list(random = c("id", "firm"))) }) test_that("get_random", { expect_identical(colnames(get_random(m1)), c("id", "firm")) }) test_that("find_response", { expect_identical(find_response(m1), "y") }) test_that("get_response", { expect_equal(get_response(m1), dat$y) }) test_that("get_predictors", { expect_equal( colnames(get_predictors(m1)), c("x", "x2", "Q", "W", "x3", "x4") ) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 1000) expect_equal( colnames(get_data(m1)), c("y", "x", "x2", "id", "firm", "Q", "W", "x3", "x4") ) }) test_that("find_formula", { expect_length(find_formula(m1), 3) expect_equal( find_formula(m1), list( conditional = as.formula("y ~ x + x2"), random = as.formula("~id + firm"), instruments = as.formula("~(Q | W ~ x3 + factor(x4))") ) ) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "y", conditional = c("x", "x2"), random = c("id", "firm"), instruments = c("(Q", "W x3", "factor(x4))") ) ) expect_equal( find_terms(m1, flatten = TRUE), c("y", "x", "x2", "id", "firm", "(Q", "W x3", "factor(x4))") ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "y", conditional = c("x", "x2"), random = c("id", "firm"), instruments = c("Q", "W", "x3", "x4") ) ) expect_equal( find_variables(m1, flatten = TRUE), c("y", "x", "x2", "id", "firm", "Q", "W", "x3", "x4") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 1000) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list(conditional = c("x", "x2", "Q(fit)", "W(fit)")) ) expect_equal(nrow(get_parameters(m1)), 4) expect_equal( get_parameters(m1)$Parameter, c("x", "x2", "Q(fit)", "W(fit)") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") }) } insight/tests/testthat/test-spatial.R0000644000176200001440000000746613554405404017477 0ustar liggesusers.runThisTest <- Sys.getenv("RunAllinsightTests") == "yes" if (.runThisTest || Sys.getenv("USER") == "travis") { if (require("testthat") && require("insight") && require("glmmTMB")) { context("insight, glmmTMB") m1 <- download_model("glmmTMB_spatial_1") test_that("find_weights", { expect_null(find_weights(m1)) }) test_that("model_info", { expect_true(model_info(m1)$is_linear) }) test_that("clean_names", { expect_identical(clean_names(m1), c("calcium", "elevation", "region", "pos", "ID")) }) test_that("find_predictors", { expect_identical( find_predictors(m1, effects = "all"), list(conditional = c("elevation", "region"), random = c("pos", "ID")) ) expect_identical( find_predictors(m1, effects = "all", flatten = TRUE), c("elevation", "region", "pos", "ID") ) expect_identical( find_predictors(m1, effects = "random"), list(random = "ID") ) expect_identical(find_predictors(m1, effects = "random", flatten = TRUE), "ID") }) test_that("find_response", { expect_identical(find_response(m1), "calcium") }) test_that("link_inverse", { expect_identical(link_inverse(m1)(.2), .2) }) test_that("get_data", { expect_equal( colnames(get_data(m1)), c("calcium", "elevation", "region", "pos", "ID") ) expect_equal( colnames(get_data(m1, effects = "all")), c("calcium", "elevation", "region", "pos", "ID") ) }) test_that("find_predictors", { expect_identical( find_predictors(m1, effects = "fixed", component = "conditional"), list(conditional = c("elevation", "region")) ) expect_identical( find_predictors(m1), list(conditional = c("elevation", "region")) ) expect_identical( find_predictors(m1, effects = "all"), list( conditional = c("elevation", "region"), random = c("pos", "ID") ) ) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_equal( find_formula(m1), list( conditional = as.formula("calcium ~ elevation + region"), random = as.formula("~pos + 0 | ID") ) ) }) test_that("find_random", { expect_identical( find_random(m1), list(random = "ID") ) }) test_that("find_terms", { expect_identical( find_terms(m1), list( response = "calcium", conditional = c("elevation", "region"), random = c("pos", "ID") ) ) }) test_that("find_variables", { expect_identical( find_variables(m1), list( response = "calcium", conditional = c("elevation", "region"), random = c("pos", "ID") ) ) }) test_that("get_predictors", { expect_identical( colnames(get_predictors(m1)), c("elevation", "region") ) }) test_that("get_random", { expect_identical(colnames(get_random(m1)), c("pos", "ID")) }) test_that("get_data", { expect_identical( colnames(get_data(m1)), c("calcium", "elevation", "region", "pos", "ID") ) }) test_that("get_paramaters", { expect_equal(nrow(get_parameters(m1)), 4) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "elevation", "region2", "region3") ) }) test_that("find_random_slopes", { skip_on_cran() skip_on_travis() expect_equal( find_random_slopes(m1), list(random = "pos") ) }) } } insight/tests/testthat/test-betareg.R0000644000176200001440000000643613613304321017437 0ustar liggesusersif (require("testthat") && require("insight") && require("betareg")) { data("GasolineYield") data("FoodExpenditure") m1 <- betareg(yield ~ batch + temp, data = GasolineYield) m2 <- betareg(I(food / income) ~ income + persons, data = FoodExpenditure) test_that("model_info", { expect_true(model_info(m1)$is_beta) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("batch", "temp"))) expect_identical(find_predictors(m1, flatten = TRUE), c("batch", "temp")) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_response", { expect_identical(find_response(m1), "yield") expect_identical(find_response(m2), "I(food/income)") expect_identical(find_response(m2, combine = FALSE), c("food", "income")) }) test_that("get_response", { expect_equal(get_response(m1), GasolineYield$yield) expect_equal(get_response(m2), FoodExpenditure[, c("food", "income")]) }) test_that("link_inverse", { expect_identical(link_inverse(m1)(.2), plogis(.2)) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 32) expect_equal(colnames(get_data(m1)), c("yield", "batch", "temp")) expect_equal(nrow(get_data(m2)), 38) expect_equal( colnames(get_data(m2)), c("I(food/income)", "income", "persons", "food", "income.1") ) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("yield ~ batch + temp")) ) expect_equal( find_formula(m2), list(conditional = as.formula("I(food/income) ~ income + persons")) ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "yield", conditional = c("batch", "temp") ) ) expect_equal( find_variables(m1, flatten = TRUE), c("yield", "batch", "temp") ) expect_equal( find_variables(m2, flatten = TRUE), c("food", "income", "persons") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 32) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "batch1", "batch2", "batch3", "batch4", "batch5", "batch6", "batch7", "batch8", "batch9", "temp"), precision = "(phi)" ) ) expect_equal(nrow(get_parameters(m1)), 12) expect_equal( get_parameters(m1)$Parameter, c( "(Intercept)", "batch1", "batch2", "batch3", "batch4", "batch5", "batch6", "batch7", "batch8", "batch9", "temp", "(phi)" ) ) }) test_that("find_terms", { expect_equal( find_terms(m2), list( response = "I(food/income)", conditional = c("income", "persons") ) ) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") expect_identical(find_statistic(m2), "z-statistic") }) } insight/tests/testthat/test-coxph.R0000644000176200001440000000512413552364343017154 0ustar liggesusersif (require("testthat") && require("insight") && require("survival")) { context("insight, coxph") data("lung") lung <- subset(lung, subset = ph.ecog %in% 0:2) lung$sex <- factor(lung$sex, labels = c("male", "female")) lung$ph.ecog <- factor(lung$ph.ecog, labels = c("good", "ok", "limited")) m1 <- coxph(Surv(time, status) ~ sex + age + ph.ecog, data = lung) test_that("model_info", { expect_true(model_info(m1)$is_logit) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("sex", "age", "ph.ecog"))) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_response", { expect_identical(find_response(m1), "Surv(time, status)") expect_identical(find_response(m1, combine = FALSE), c("time", "status")) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), plogis(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 226) expect_equal( colnames(get_data(m1)), c( "time", "status", "Surv(time, status)", "sex", "age", "ph.ecog" ) ) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula( "Surv(time, status) ~ sex + age + ph.ecog" )) ) }) test_that("find_variables", { expect_equal(find_variables(m1), list( response = c("time", "status"), conditional = c("sex", "age", "ph.ecog") )) expect_equal( find_variables(m1, flatten = TRUE), c("time", "status", "sex", "age", "ph.ecog") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 226) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("sexfemale", "age", "ph.ecogok", "ph.ecoglimited") ) ) expect_equal(nrow(get_parameters(m1)), 4) expect_equal( get_parameters(m1)$Parameter, c("sexfemale", "age", "ph.ecogok", "ph.ecoglimited") ) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "Surv(time, status)", conditional = c("sex", "age", "ph.ecog") ) ) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") }) } insight/tests/testthat/test-gamm4.R0000644000176200001440000000545213567303210017034 0ustar liggesusersunloadNamespace("gam") if (require("testthat") && require("insight") && require("gamm4")) { set.seed(0) dat <- gamSim(1, n = 400, scale = 2) ## simulate 4 term additive truth dat$fac <- fac <- as.factor(sample(1:20, 400, replace = TRUE)) dat$y <- dat$y + model.matrix(~ fac - 1) %*% rnorm(20) * .5 m1 <- gamm4(y ~ s(x0) + x1 + s(x2), data = dat, random = ~ (1 | fac) ) test_that("model_info", { expect_true(model_info(m1)$is_linear) }) test_that("clean_names", { expect_equal(clean_names(m1), c("y", "x0", "x1", "x2")) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("x0", "x1", "x2"))) expect_identical(find_predictors(m1, flatten = TRUE), c("x0", "x1", "x2")) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_response", { expect_identical(find_response(m1), "y") }) test_that("get_response", { expect_equal(get_response(m1), unname(dat$y[, 1])) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 400) expect_equal( colnames(get_data(m1)), c( "y", "x1", "x0", "x2", "fac", "y.0", "Xr", "Xr.0", "X.(Intercept)", "X.x1", "X.s(x0)Fx1", "X.s(x2)Fx1" ) ) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("y ~ s(x0) + x1 + s(x2)")) ) }) test_that("find_terms", { expect_equal(find_terms(m1), list( response = "y", conditional = c("s(x0)", "x1", "s(x2)") )) expect_equal( find_terms(m1, flatten = TRUE), c("y", "s(x0)", "x1", "s(x2)") ) }) test_that("find_variables", { expect_equal(find_variables(m1), list( response = "y", conditional = c("x0", "x1", "x2") )) expect_equal(find_variables(m1, flatten = TRUE), c("y", "x0", "x1", "x2")) }) test_that("n_obs", { expect_equal(n_obs(m1), 400) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "x1"), smooth_terms = c("s(x0)", "s(x2)") ) ) expect_equal(nrow(get_parameters(m1)), 4) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "x1", "s(x0)", "s(x2)") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_statistic", { expect_error(find_statistic(m1)) }) } insight/tests/testthat/test-polr.R0000644000176200001440000000537513552364343017017 0ustar liggesusersif (require("testthat") && require("insight") && require("MASS")) { context("insight, polr") data(housing, package = "MASS") m1 <- polr(Sat ~ Infl + Type + Cont, data = housing, weights = Freq) test_that("model_info", { expect_true(model_info(m1)$is_ordinal) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("Infl", "Type", "Cont"))) expect_identical( find_predictors(m1, flatten = TRUE), c("Infl", "Type", "Cont") ) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_response", { expect_identical(find_response(m1), "Sat") }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), plogis(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 72) expect_equal( colnames(get_data(m1)), c("Sat", "Infl", "Type", "Cont", "(weights)", "Freq") ) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("Sat ~ Infl + Type + Cont")) ) }) test_that("find_terms", { expect_equal(find_terms(m1), list( response = "Sat", conditional = c("Infl", "Type", "Cont") )) expect_equal( find_terms(m1, flatten = TRUE), c("Sat", "Infl", "Type", "Cont") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 1681) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c( "Intercept: Low|Medium", "Intercept: Medium|High", "InflMedium", "InflHigh", "TypeApartment", "TypeAtrium", "TypeTerrace", "ContHigh" ) ) ) }) test_that("get_parameters", { expect_equal( get_parameters(m1), data.frame( Parameter = c( "Intercept: Low|Medium", "Intercept: Medium|High", "InflMedium", "InflHigh", "TypeApartment", "TypeAtrium", "TypeTerrace", "ContHigh" ), Estimate = c( -0.4961353438375, 0.690708290379271, 0.566393738890106, 1.28881906381232, -0.572350146429611, -0.366186566153346, -1.09101490767244, 0.360284149947385 ), stringsAsFactors = FALSE, row.names = NULL ) ) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") }) } insight/tests/testthat/test-response_data2.R0000644000176200001440000000670213531007237020740 0ustar liggesusersif (suppressWarnings(require("testthat") && require("insight") && require("lme4"))) { context("insight, find_response") data(cbpp) cbpp$trials <- cbpp$size - cbpp$incidence m1 <- glmer(cbind(incidence, trials) ~ period + (1 | herd), data = cbpp, family = binomial ) m2 <- glmer( cbind(incidence, size - incidence) ~ period + (1 | herd), data = cbpp, family = binomial ) m3 <- glm(cbind(incidence, trials) ~ period, data = cbpp, family = binomial ) m4 <- glm(cbind(incidence, size - incidence) ~ period, data = cbpp, family = binomial ) m5 <- glmer(cbind(incidence, size - incidence) ~ (1 | herd), data = cbpp, family = binomial ) test_that("find_response", { expect_equal( find_response(m1, combine = TRUE), "cbind(incidence, trials)" ) expect_equal( find_response(m2, combine = TRUE), "cbind(incidence, size - incidence)" ) expect_equal( find_response(m3, combine = TRUE), "cbind(incidence, trials)" ) expect_equal( find_response(m4, combine = TRUE), "cbind(incidence, size - incidence)" ) expect_equal( find_response(m5, combine = TRUE), "cbind(incidence, size - incidence)" ) expect_equal( find_response(m1, combine = FALSE), c("incidence", "trials") ) expect_equal(find_response(m2, combine = FALSE), c("incidence", "size")) expect_equal( find_response(m3, combine = FALSE), c("incidence", "trials") ) expect_equal(find_response(m4, combine = FALSE), c("incidence", "size")) expect_equal(find_response(m5, combine = FALSE), c("incidence", "size")) }) test_that("get_response", { expect_equal(colnames(get_response(m1)), c("incidence", "trials")) expect_equal(colnames(get_response(m2)), c("incidence", "size")) expect_equal(colnames(get_response(m3)), c("incidence", "trials")) expect_equal(colnames(get_response(m4)), c("incidence", "size")) expect_equal(colnames(get_response(m5)), c("incidence", "size")) }) test_that("get_data", { expect_equal( colnames(get_data(m1)), c( "cbind(incidence, trials)", "period", "herd", "incidence", "trials" ) ) expect_equal( colnames(get_data(m2)), c( "cbind(incidence, size - incidence)", "period", "herd", "incidence", "size" ) ) get_data(m3) get_data(m4) expect_equal( colnames(get_data(m5)), c( "cbind(incidence, size - incidence)", "herd", "incidence", "size" ) ) }) set.seed(123) data(mtcars) m6 <- stats::aov( formula = mpg ~ wt + qsec + Error(disp / am), data = mtcars ) # TO DO # test_that("mod-info", { # get_data(m6) # find_response(m6) # get_response(m6) # find_formula(m6) # }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") expect_identical(find_statistic(m2), "z-statistic") expect_identical(find_statistic(m3), "z-statistic") expect_identical(find_statistic(m4), "z-statistic") expect_identical(find_statistic(m5), "z-statistic") expect_identical(find_statistic(m6), "F-statistic") }) } insight/tests/testthat/test-gmnl.R0000644000176200001440000000400013531007236016750 0ustar liggesusersif (require("testthat") && require("insight") && require("gmnl") && require("mlogit") && require("MASS")) { context("insight, polr") data(housing, package = "MASS") dat <- mlogit.data(housing, choice = "Sat", shape = "wide") m1 <- gmnl(Sat ~ Infl + Type + Cont | 1, data = dat, model = "smnl", R = 100 ) test_that("model_info", { expect_true(model_info(m1)$is_ordinal) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("Infl", "Type", "Cont"))) expect_identical( find_predictors(m1, flatten = TRUE), c("Infl", "Type", "Cont") ) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_response", { expect_identical(find_response(m1), "Sat") }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), plogis(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 216) expect_equal(colnames(get_data(m1)), c("Sat", "Infl", "Type", "Cont")) }) test_that("find_formula", { expect_length(find_formula(m1), 1) }) test_that("find_terms", { expect_equal(find_terms(m1), list( response = "Sat", conditional = c("Infl", "Type", "Cont", "1") )) expect_equal( find_terms(m1, flatten = TRUE), c("Sat", "Infl", "Type", "Cont", "1") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 72) }) test_that("find_variables", { expect_equal(find_variables(m1), list( response = "Sat", conditional = c("Infl", "Type", "Cont") )) expect_equal( find_variables(m1, flatten = TRUE), c("Sat", "Infl", "Type", "Cont") ) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") }) } insight/tests/testthat/test-survreg.R0000644000176200001440000000476713552364343017544 0ustar liggesusersif (require("testthat") && require("insight") && require("survival")) { context("insight, model_info") data("ovarian") m1 <- survreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, dist = "exponential" ) test_that("model_info", { expect_false(model_info(m1)$is_linear) expect_true(model_info(m1)$is_exponential) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("ecog.ps", "rx"))) expect_identical(find_predictors(m1, flatten = TRUE), c("ecog.ps", "rx")) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "Surv(futime, fustat)") }) test_that("get_response", { expect_equal(get_response(m1), ovarian[, c("futime", "fustat")]) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("ecog.ps", "rx")) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), exp(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 26) expect_equal( colnames(get_data(m1)), c("futime", "fustat", "Surv(futime, fustat)", "ecog.ps", "rx") ) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("Surv(futime, fustat) ~ ecog.ps + rx")) ) }) test_that("find_variables", { expect_equal(find_variables(m1), list( response = c("futime", "fustat"), conditional = c("ecog.ps", "rx") )) expect_equal( find_variables(m1, flatten = TRUE), c("futime", "fustat", "ecog.ps", "rx") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 26) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list(conditional = c("(Intercept)", "ecog.ps", "rx")) ) expect_equal(nrow(get_parameters(m1)), 3) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "ecog.ps", "rx") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") }) } insight/tests/testthat/test-GLMMadaptive.R0000644000176200001440000002122313552364343020303 0ustar liggesusers.runThisTest <- Sys.getenv("RunAllinsightTests") == "yes" if (.runThisTest || Sys.getenv("USER") == "travis") { if (require("testthat") && require("insight") && require("GLMMadaptive") && require("lme4")) { context("insight, model_info") m <- download_model("GLMMadaptive_zi_2") m2 <- download_model("GLMMadaptive_zi_1") data(cbpp) m3 <- GLMMadaptive::mixed_model( cbind(incidence, size - incidence) ~ period, random = ~ 1 | herd, data = cbpp, family = binomial ) test_that("model_info", { expect_true(model_info(m)$is_zero_inflated) expect_true(model_info(m)$is_count) expect_true(model_info(m)$is_pois) expect_false(model_info(m)$is_negbin) }) test_that("find_predictors", { expect_identical( find_predictors(m, effects = "fixed")$conditional, c("child", "camper") ) expect_identical( find_predictors(m, effects = "fixed")$zero_inflated, c("child", "livebait") ) expect_identical( find_predictors(m, effects = "all", flatten = TRUE), c("child", "camper", "persons", "livebait") ) expect_identical( find_predictors(m, effects = "all")$zero_inflated_random, c("persons") ) expect_identical(find_predictors(m, effects = "random")$random, "persons") expect_identical( find_predictors( m, effects = "fixed", component = "cond", flatten = TRUE ), c("child", "camper") ) expect_identical( find_predictors( m, effects = "all", component = "cond", flatten = TRUE ), c("child", "camper", "persons") ) expect_identical( find_predictors(m, effects = "all", component = "cond")$conditional, c("child", "camper") ) expect_identical( find_predictors( m, effects = "random", component = "cond", flatten = TRUE ), "persons" ) expect_identical( find_predictors( m, effects = "fixed", component = "zi", flatten = TRUE ), c("child", "livebait") ) expect_identical( find_predictors( m, effects = "all", component = "zi", flatten = TRUE ), c("child", "livebait", "persons") ) expect_identical( find_predictors( m, effects = "random", component = "zi", flatten = TRUE ), "persons" ) expect_null(find_predictors( m, effects = "fixed", component = "dispersion", flatten = TRUE )) expect_null(find_predictors( m, effects = "all", component = "dispersion", flatten = TRUE )) expect_null(find_predictors( m, effects = "random", component = "dispersion", flatten = TRUE )) }) test_that("find_response", { expect_identical(find_response(m), "count") }) test_that("link_inverse", { expect_identical(link_inverse(m)(.2), exp(.2)) }) test_that("clean_names", { expect_identical( clean_names(m), c("count", "child", "camper", "persons", "livebait") ) }) test_that("find_formula", { expect_length(find_formula(m), 4) expect_identical( names(find_formula(m)), c( "conditional", "random", "zero_inflated", "zero_inflated_random" ) ) }) test_that("find_random", { expect_identical( find_random(m), list(random = "persons", zero_inflated_random = "persons") ) expect_identical(find_random(m, flatten = TRUE), "persons") }) test_that("find_respone", { expect_identical(find_response(m), "count") }) test_that("find_terms", { expect_identical( find_terms(m), list( response = "count", conditional = c("child", "camper"), random = "persons", zero_inflated = c("child", "livebait"), zero_inflated_random = "persons" ) ) expect_identical( find_terms(m, flatten = TRUE), c("count", "child", "camper", "persons", "livebait") ) }) test_that("get_response", { expect_identical(get_response(m3), cbpp[, c("incidence", "size")]) }) test_that("get_predictors", { expect_identical( colnames(get_predictors(m)), c("child", "camper", "livebait") ) }) test_that("get_random", { expect_identical(colnames(get_random(m)), "persons") }) test_that("get_data", { expect_identical( colnames(get_data(m)), c("count", "child", "camper", "livebait", "persons") ) expect_identical( colnames(get_data(m, effects = "fixed")), c("count", "child", "camper", "livebait") ) expect_identical(colnames(get_data(m, effects = "random")), "persons") expect_identical( colnames(get_data(m, component = "zi")), c("count", "child", "livebait", "persons") ) expect_identical(colnames(get_data( m, component = "zi", effects = "fixed" )), c("count", "child", "livebait")) expect_identical(colnames(get_data( m, component = "zi", effects = "random" )), "persons") expect_identical( colnames(get_data(m, component = "cond")), c("count", "child", "camper", "persons") ) expect_identical(colnames(get_data( m, component = "cond", effects = "fixed" )), c("count", "child", "camper")) expect_identical(colnames(get_data( m, component = "cond", effects = "random" )), "persons") expect_identical(colnames(get_data(m, component = "dispersion")), "count") expect_null(get_data(m, component = "dispersion", effects = "random")) expect_identical( colnames(get_data(m3)), c("incidence", "size", "period", "herd") ) }) test_that("find_parameter", { expect_equal( find_parameters(m), list( conditional = c("(Intercept)", "child", "camper1"), random = "(Intercept)", zero_inflated = c("(Intercept)", "child", "livebait1"), zero_inflated_random = "zi_(Intercept)" ) ) expect_equal( find_parameters(m2), list( conditional = c("(Intercept)", "child", "camper1"), random = "(Intercept)", zero_inflated = c("(Intercept)", "child", "livebait1") ) ) expect_equal( find_parameters(m3), list( conditional = c("(Intercept)", "period2", "period3", "period4"), random = "(Intercept)" ) ) expect_equal(nrow(get_parameters(m)), 6) expect_equal( get_parameters(m, effects = "random"), list( random = c(-1.0715496, 1.4083630, 1.9129880, 0.2007521), zero_inflated_random = c(-0.1676294, 0.5502481, 1.2592406, 0.9336591) ), tolerance = 1e-5 ) expect_equal(nrow(get_parameters(m2)), 6) expect_equal(get_parameters(m2, effects = "random"), list(random = c( -1.3262364, -0.2048055, 1.3852572, 0.5282277 )), tolerance = 1e-5 ) expect_equal( get_parameters(m3)$Component, c( "conditional", "conditional", "conditional", "conditional" ) ) expect_error(get_parameters(m3, "zi")) }) test_that("linkfun", { expect_false(is.null(link_function(m))) expect_false(is.null(link_function(m2))) }) test_that("is_multivariate", { expect_false(is_multivariate(m)) expect_false(is_multivariate(m2)) }) test_that("find_algorithm", { expect_equal( find_algorithm(m), list(algorithm = "quasi-Newton", optimizer = "optim") ) }) } # these run successfully for devtools::test_file() locally but fail on Travis # not sure what's going on # test_that("find_statistic", { # expect_identical(find_statistic(m1), "z-statistic") # expect_identical(find_statistic(m2), "z-statistic") # expect_identical(find_statistic(m3), "z-statistic") # }) } insight/tests/testthat/test-glm.R0000644000176200001440000000626513572501701016612 0ustar liggesusersif (require("testthat") && require("insight") && require("glmmTMB")) { context("insight, model_info") data(Salamanders) Salamanders$cover <- abs(Salamanders$cover) m1 <- glm(count ~ mined + log(cover) + sample, family = poisson, data = Salamanders ) test_that("model_info", { expect_true(model_info(m1)$is_poisson) expect_true(model_info(m1)$is_count) expect_false(model_info(m1)$is_negbin) expect_false(model_info(m1)$is_binomial) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("mined", "cover", "sample"))) expect_identical( find_predictors(m1, flatten = TRUE), c("mined", "cover", "sample") ) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "count") }) test_that("get_response", { expect_equal(get_response(m1), Salamanders$count) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("mined", "cover", "sample")) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), exp(.2), tolerance = 1e-5) }) test_that("linkfun", { expect_equal(link_function(m1)(.2), -1.609438, tolerance = 1e-4) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 644) expect_equal( colnames(get_data(m1)), c("count", "mined", "cover", "sample") ) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("count ~ mined + log(cover) + sample")) ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "count", conditional = c("mined", "cover", "sample") ) ) expect_equal( find_variables(m1, flatten = TRUE), c("count", "mined", "cover", "sample") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 644) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "minedno", "log(cover)", "sample") ) ) expect_equal(nrow(get_parameters(m1)), 4) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "minedno", "log(cover)", "sample") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "count", conditional = c("mined", "log(cover)", "sample") ) ) }) test_that("find_algorithm", { expect_equal(find_algorithm(m1), list(algorithm = "ML")) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") }) test_that("get_statistic", { expect_equal(get_statistic(m1)$Statistic, c(-10.7066515607315, 18.1533878215937, -1.68918157150882, 2.23541768590273), tolernce = 1e-4) }) } insight/tests/testthat/test-cgam.R0000644000176200001440000000215613603137664016745 0ustar liggesusersif (require("testthat") && require("insight") && require("cgam")) { context("insight, model_info") data(cubic, package = "cgam") m <- cgam(y ~ incr.conv(x), data = cubic) test_that("n_obs", { expect_equal(n_obs(m), 50) }) test_that("find_formula", { expect_length(find_formula(m), 1) expect_equal( find_formula(m), list(conditional = as.formula("y ~ incr.conv(x)")) ) }) test_that("find_terms", { expect_equal(find_terms(m), list( response = "y", conditional = "incr.conv(x)" )) expect_equal( find_terms(m, flatten = TRUE), c("y", "incr.conv(x)") ) }) test_that("get_data", { expect_equal(nrow(get_data(m)), 50) expect_equal(colnames(get_data(m)), c("y", "x")) }) test_that("get_response", { expect_equal(get_response(m), cubic$y) }) test_that("is_multivariate", { expect_false(is_multivariate(m)) }) test_that("is_model", { expect_true(is_model(m)) }) test_that("find_statistic", { expect_identical(find_statistic(m), "t-statistic") }) } insight/tests/testthat/test-gam.R0000644000176200001440000001330413554405404016572 0ustar liggesusersif (require("testthat") && require("insight") && require("mgcv")) { context("insight, model_info") set.seed(123) dat <- gamSim(1, n = 400, dist = "normal", scale = 2) m1 <- mgcv::gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat) m2 <- download_model("gam_zi_1") m3 <- download_model("gam_mv_1") test_that("model_info", { expect_true(model_info(m1)$is_linear) expect_true(model_info(m2)$is_count) expect_true(model_info(m3)$is_multivariate) }) test_that("clean_names", { expect_equal(clean_names(m1), c("y", "x0", "x1", "x2", "x3")) expect_equal(clean_names(m2), c("y", "x2", "x3", "x0", "x1")) expect_equal(clean_names(m3), c("y0", "y1", "x0", "x1", "x2", "x3")) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("x0", "x1", "x2", "x3"))) expect_identical( find_predictors(m1, flatten = TRUE), c("x0", "x1", "x2", "x3") ) expect_null(find_predictors(m1, effects = "random")) expect_identical(find_predictors(m2), list(conditional = c("x2", "x3"), zero_inflated = c("x0", "x1"))) expect_identical(find_predictors(m2, flatten = TRUE), c("x2", "x3", "x0", "x1")) expect_null(find_predictors(m2, effects = "random")) expect_identical(find_predictors(m3), list(y0 = list(conditional = c("x0", "x1")), y1 = list(conditional = c("x2", "x3")))) expect_identical(find_predictors(m3, flatten = TRUE), c("x0", "x1", "x2", "x3")) expect_null(find_predictors(m3, effects = "random")) }) test_that("find_response", { expect_identical(find_response(m1), "y") expect_identical(find_response(m2), "y") expect_identical(find_response(m3), c(y0 = "y0", y1 = "y1")) }) test_that("get_response", { expect_equal(get_response(m1), dat$y) expect_equal(length(get_response(m2)), 500) expect_equal(ncol(get_response(m3)), 2) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) expect_equal(link_inverse(m2)(.2), .2, tolerance = 1e-5) expect_equal(link_inverse(m3)(.2), .2, tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 400) expect_equal(colnames(get_data(m1)), c("y", "x0", "x1", "x2", "x3")) expect_equal(nrow(get_data(m2)), 500) expect_equal(colnames(get_data(m2)), c("y", "x2", "x3", "x0", "x1")) expect_equal(nrow(get_data(m3)), 300) expect_equal(colnames(get_data(m3)), c("y0", "x0", "x1", "x2", "x3", "y1")) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("y ~ s(x0) + s(x1) + s(x2) + s(x3)")) ) expect_length(find_formula(m2), 2) expect_equal( find_formula(m2), list( conditional = as.formula("y ~ s(x2) + s(x3)"), zero_inflated = as.formula("~s(x0) + s(x1)") ) ) expect_length(find_formula(m3), 2) expect_equal( find_formula(m3), structure(list( y0 = list(conditional = as.formula("y0 ~ s(x0) + s(x1)")), y1 = list(conditional = as.formula("y1 ~ s(x2) + s(x3)")) ), is_mv = "1" ) ) }) test_that("find_variables", { expect_equal(find_variables(m1), list(response = "y", conditional = c("x0", "x1", "x2", "x3"))) expect_equal(find_variables(m1, flatten = TRUE), c("y", "x0", "x1", "x2", "x3")) expect_equal(find_variables(m2), list(response = "y", conditional = c("x2", "x3"), zero_inflated = c("x0", "x1"))) expect_equal(find_variables(m2, flatten = TRUE), c("y", "x2", "x3", "x0", "x1")) expect_equal(find_variables(m3), list(response = c(y0 = "y0", y1 = "y1"), y0 = list(conditional = c("x0", "x1")), y1 = list(conditional = c("x2", "x3")))) expect_equal(find_variables(m3, flatten = TRUE), c("y0", "y1", "x0", "x1", "x2", "x3")) }) test_that("n_obs", { expect_equal(n_obs(m1), 400) expect_equal(n_obs(m2), 500) expect_equal(n_obs(m3), 300) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = "(Intercept)", smooth_terms = c("s(x0)", "s(x1)", "s(x2)", "s(x3)") ) ) expect_equal(nrow(get_parameters(m1)), 5) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "s(x0)", "s(x1)", "s(x2)", "s(x3)") ) expect_equal(nrow(get_parameters(m1, "smooth_terms")), 4) expect_equal( find_parameters(m2), list( conditional = c("(Intercept)", "(Intercept).1"), smooth_terms = c("s(x2)", "s(x3)", "s.1(x0)", "s.1(x1)") ) ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) expect_false(is_multivariate(m2)) expect_true(is_multivariate(m3)) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "y", conditional = c("s(x0)", "s(x1)", "s(x2)", "s(x3)") ) ) expect_equal( find_terms(m2), list( response = "y", conditional = c("s(x2)", "s(x3)"), zero_inflated = c("s(x0)", "s(x1)") ) ) expect_equal( find_terms(m3), list( y0 = list(response = "y0", conditional = c("s(x0)", "s(x1)")), y1 = list(response = "y1", conditional = c("s(x2)", "s(x3)")) ) ) }) test_that("find_algorithm", { expect_equal( find_algorithm(m1), list(algorithm = "GCV", optimizer = "magic") ) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") }) } insight/tests/testthat/test-BBmm.R0000644000176200001440000000610613531007236016641 0ustar liggesusers.runThisTest <- Sys.getenv("RunAllinsightTests") == "yes" if (.runThisTest && Sys.getenv("USER") != "travis") { if (require("testthat") && require("insight") && require("HRQoL")) { context("insight, BBmm") set.seed(18) k <- 100 m <- 10 x <- rnorm(k, 5, 3) j <- runif(k, 0, 5) fac <- sample(letters[1:4], k, TRUE) beta <- c(-10, 2) p <- 1 / (1 + exp(-(beta[1] + beta[2] * x))) phi <- 1.2 y <- HRQoL::rBB(k, m, p, phi) z <- as.factor(HRQoL::rBI(k, 4, 0.5, 2)) dat <- data.frame(y, x, j, fac, z) m1 <- BBmm( fixed.formula = y ~ x, random.formula = ~z, m = m, data = dat ) test_that("model_info", { expect_true(model_info(m1)$is_binomial) expect_true(model_info(m1)$is_betabinomial) expect_true(model_info(m1)$is_mixed) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = "x")) expect_identical(find_predictors(m1, flatten = TRUE), "x") expect_identical( find_predictors(m1, effects = "random"), list(random = "z") ) expect_identical( find_predictors(m1, effects = "all"), list( conditional = "x", random = "z" ) ) }) test_that("find_random", { expect_identical(find_random(m1), list(random = "z")) }) test_that("find_response", { expect_identical(find_response(m1), "y") }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), plogis(.2), tolerance = 1e-5) }) test_that("link_function", { expect_equal(link_function(m1)(.2), qlogis(.2), tolerance = 1e-5) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_equal( find_formula(m1), list( conditional = as.formula("y ~ x"), random = as.formula("~z") ) ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "y", conditional = "x", random = "z" ) ) expect_equal(find_variables(m1, flatten = TRUE), c("y", "x", "z")) }) test_that("n_obs", { expect_equal(n_obs(m1), 100) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "x"), random = "z" ) ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "y", conditional = "x", random = "z" ) ) }) test_that("find_algorithm", { expect_equal( find_algorithm(m1), list(algorithm = "extended likelihood", optimizer = "BB-NR") ) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") }) } } insight/tests/testthat/test-mlogit.R0000644000176200001440000000540013531007236017313 0ustar liggesusersif (require("testthat") && require("insight") && require("mlogit")) { context("insight, polr") data("Fishing") Fish <- mlogit.data(Fishing, varying = c(2:9), shape = "wide", choice = "mode" ) m1 <- mlogit(mode ~ price + catch, data = Fish) m2 <- mlogit(mode ~ price + catch | income, data = Fish) test_that("model_info", { expect_true(model_info(m1)$is_ordinal) expect_true(model_info(m2)$is_ordinal) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("price", "catch"))) expect_identical(find_predictors(m1, flatten = TRUE), c("price", "catch")) expect_null(find_predictors(m1, effects = "random")) expect_identical(find_predictors(m2), list(conditional = c("price", "catch", "income"))) expect_identical( find_predictors(m2, flatten = TRUE), c("price", "catch", "income") ) expect_null(find_predictors(m2, effects = "random")) }) test_that("find_response", { expect_identical(find_response(m1), "mode") expect_identical(find_response(m2), "mode") }) test_that("get_response", { expect_equal(get_response(m1), Fish$mode) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), plogis(.2), tolerance = 1e-5) expect_equal(link_inverse(m2)(.2), plogis(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 4728) expect_equal(nrow(get_data(m2)), 4728) expect_equal( colnames(get_data(m1)), c("mode", "price", "catch", "probabilities", "linpred") ) expect_equal( colnames(get_data(m2)), c( "mode", "price", "catch", "income", "probabilities", "linpred" ) ) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_length(find_formula(m2), 1) }) test_that("find_terms", { expect_equal(find_terms(m1), list( response = "mode", conditional = c("price", "catch") )) expect_equal(find_terms(m1, flatten = TRUE), c("mode", "price", "catch")) expect_equal(find_terms(m2), list( response = "mode", conditional = c("price", "catch", "income") )) expect_equal( find_terms(m2, flatten = TRUE), c("mode", "price", "catch", "income") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 4728) expect_equal(n_obs(m2), 4728) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) expect_false(is.null(link_function(m2))) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") expect_identical(find_statistic(m2), "z-statistic") }) } insight/tests/testthat/test-plm.R0000644000176200001440000000677313534510641016630 0ustar liggesusers.runThisTest <- Sys.getenv("RunAllinsightTests") == "yes" if (.runThisTest || Sys.getenv("USER") == "travis") { if (require("testthat") && require("insight") && require("plm")) { context("insight, model_info") data(Crime) m1 <- plm(lcrmrte ~ lprbarr + factor(year) | . - lprbarr + lmix, data = Crime, model = "random") # data set.seed(123) data("Produc", package = "plm") # model m2 <- plm::plm( formula = log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, data = Produc, index = c("state", "year") ) test_that("model_info", { expect_true(model_info(m1)$is_linear) }) test_that("find_predictors", { expect_identical( find_predictors(m1), list( conditional = c("lprbarr", "year"), instruments = c("lprbarr", "lmix") ) ) expect_identical( find_predictors(m1, flatten = TRUE), c("lprbarr", "year", "lmix") ) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "lcrmrte") }) test_that("get_response", { expect_equal(get_response(m1), Crime$lcrmrte) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("lprbarr", "year", "lmix")) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 630) expect_equal( colnames(get_data(m1)), c("lcrmrte", "lprbarr", "year", "lmix") ) expect_equal(nrow(get_data(m2)), 816) expect_equal( colnames(get_data(m2)), c("gsp", "pcap", "pc", "emp", "unemp", "state", "year") ) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_equal( find_formula(m1), list( conditional = as.formula("lcrmrte ~ lprbarr + factor(year)"), instruments = as.formula("~-lprbarr + lmix") ) ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "lcrmrte", conditional = c("lprbarr", "year"), instruments = c("lprbarr", "lmix") ) ) expect_equal( find_variables(m1, flatten = TRUE), c("lcrmrte", "lprbarr", "year", "lmix") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 630) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c( "(Intercept)", "lprbarr", "factor(year)82", "factor(year)83", "factor(year)84", "factor(year)85", "factor(year)86", "factor(year)87" ) ) ) expect_equal(nrow(get_parameters(m1)), 8) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") expect_identical(find_statistic(m2), "t-statistic") }) } } insight/tests/testthat/test-ols.R0000644000176200001440000000471313552364343016633 0ustar liggesusersif (require("testthat") && require("insight") && require("rms")) { context("insight, model_info") data(mtcars) m1 <- ols(mpg ~ rcs(hp, 3) * cyl + wt, data = mtcars) test_that("model_info", { expect_true(model_info(m1)$is_linear) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("hp", "cyl", "wt"))) expect_identical(find_predictors(m1, flatten = TRUE), c("hp", "cyl", "wt")) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "mpg") }) test_that("get_response", { expect_equal(get_response(m1), mtcars$mpg) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("hp", "cyl", "wt")) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 32) expect_equal(colnames(get_data(m1)), c("mpg", "cyl", "wt", "hp")) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("mpg ~ rcs(hp, 3) * cyl + wt")) ) }) test_that("find_variables", { expect_equal(find_variables(m1), list( response = "mpg", conditional = c("hp", "cyl", "wt") )) expect_equal( find_variables(m1, flatten = TRUE), c("mpg", "hp", "cyl", "wt") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 32) }) test_that("linkfun", { expect_equal(link_function(m1)(.2), .2, tolerance = 1e-5) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("Intercept", "hp", "hp'", "cyl", "wt", "hp * cyl", "hp' * cyl") ) ) expect_equal(nrow(get_parameters(m1)), 7) expect_equal( get_parameters(m1)$Parameter, c("Intercept", "hp", "hp'", "cyl", "wt", "hp * cyl", "hp' * cyl") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_algorithm", { expect_equal(find_algorithm(m1), list(algorithm = "OLS")) }) # TO DO # test_that("find_statistic", { # expect_null(find_statistic(m1)) # }) } insight/tests/testthat/test-multinom.R0000644000176200001440000000402513552364343017676 0ustar liggesusersif (require("testthat") && require("insight") && require("nnet") && require("MASS")) { context("insight, model_info") data("birthwt") m1 <- multinom(low ~ age + lwt + race + smoke, data = birthwt) test_that("model_info", { expect_true(model_info(m1)$is_binomial) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("age", "lwt", "race", "smoke"))) expect_identical( find_predictors(m1, flatten = TRUE), c("age", "lwt", "race", "smoke") ) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_response", { expect_identical(find_response(m1), "low") }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), plogis(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 189) expect_equal( colnames(get_data(m1)), c("low", "age", "lwt", "race", "smoke") ) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("low ~ age + lwt + race + smoke")) ) }) test_that("find_terms", { expect_equal(find_terms(m1), list( response = "low", conditional = c("age", "lwt", "race", "smoke") )) expect_equal( find_terms(m1, flatten = TRUE), c("low", "age", "lwt", "race", "smoke") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 189) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list(conditional = c( "(Intercept)", "age", "lwt", "race", "smoke" )) ) expect_equal(nrow(get_parameters(m1)), 5) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "age", "lwt", "race", "smoke") ) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") }) } insight/tests/testthat/test-model_data.R0000644000176200001440000000261013531007236020111 0ustar liggesusersif (require("testthat") && require("insight") && require("splines") && require("glmmTMB")) { context("insight, get_data") data(iris) m1 <- lm(Sepal.Length ~ Species + ns(Petal.Width), data = iris) m2 <- lm(Sepal.Length ~ Species + ns(Petal.Width, knots = 2), data = iris) m3 <- lm(Sepal.Length ~ Species + bs(Petal.Width, degree = 3), data = iris) m4 <- lm(Sepal.Length ~ Species + bs(Petal.Width, degree = 1), data = iris) m5 <- lm(Sepal.Length ~ Species + Petal.Width, data = iris) test_that("get_data", { mf1 <- get_data(m1) mf2 <- get_data(m2) mf3 <- get_data(m3) mf4 <- get_data(m4) mf5 <- model.frame(m5) expect_equal(as.vector(mf1$Petal.Width), as.vector(mf5$Petal.Width)) expect_equal(as.vector(mf2$Petal.Width), as.vector(mf5$Petal.Width)) expect_equal(as.vector(mf3$Petal.Width), as.vector(mf5$Petal.Width)) expect_equal(as.vector(mf4$Petal.Width), as.vector(mf5$Petal.Width)) }) data("Salamanders") m <- glmmTMB( count ~ spp + cover + mined + poly(DOP, 3) + (1 | site), ziformula = ~ spp + mined, dispformula = ~DOY, data = Salamanders, family = nbinom2 ) test_that("get_data", { mf <- get_data(m) expect_equal(ncol(mf), 7) expect_equal( colnames(mf), c("count", "spp", "cover", "mined", "DOP", "DOY", "site") ) }) } insight/tests/testthat/test-fixest.R0000644000176200001440000001416313615521170017331 0ustar liggesusersif (require("testthat") && require("insight") && require("fixest")) { data(trade) m1 <- femlm(Euros ~ log(dist_km) | Origin + Destination + Product, data = trade) m2 <- femlm(log1p(Euros) ~ log(dist_km) | Origin + Destination + Product, data = trade, family = "gaussian") m3 <- feglm(Euros ~ log(dist_km) | Origin + Destination + Product, data = trade) test_that("model_info", { expect_true(model_info(m1)$is_count) expect_true(model_info(m2)$is_linear) expect_true(model_info(m3)$is_count) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = "dist_km", cluster = c("Origin", "Destination", "Product"))) expect_identical(find_predictors(m2), list(conditional = "dist_km", cluster = c("Origin", "Destination", "Product"))) expect_identical(find_predictors(m3), list(conditional = "dist_km", cluster = c("Origin", "Destination", "Product"))) expect_identical( find_predictors(m1, component = "all"), list(conditional = "dist_km", cluster = c("Origin", "Destination", "Product")) ) expect_identical( find_predictors(m2, component = "all"), list(conditional = "dist_km", cluster = c("Origin", "Destination", "Product")) ) expect_identical( find_predictors(m3, component = "all"), list(conditional = "dist_km", cluster = c("Origin", "Destination", "Product")) ) }) test_that("find_random", { expect_null(find_random(m1)) expect_null(find_random(m2)) expect_null(find_random(m3)) }) test_that("get_random", { expect_null(expect_warning(get_random(m1))) }) test_that("find_response", { expect_identical(find_response(m1), "Euros") expect_identical(find_response(m2), "Euros") expect_identical(find_response(m3), "Euros") }) test_that("get_response", { expect_equal(get_response(m1), trade$Euros) expect_equal(get_response(m2), trade$Euros) expect_equal(get_response(m3), trade$Euros) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("dist_km", "Origin", "Destination", "Product")) expect_equal(colnames(get_predictors(m2)), c("dist_km", "Origin", "Destination", "Product")) expect_equal(colnames(get_predictors(m3)), c("dist_km", "Origin", "Destination", "Product")) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), exp(.2), tolerance = 1e-4) expect_equal(link_inverse(m2)(.2), .2, tolerance = 1e-4) expect_equal(link_inverse(m3)(.2), exp(.2), tolerance = 1e-4) }) test_that("link_function", { expect_equal(link_function(m1)(.2), log(.2), tolerance = 1e-4) expect_equal(link_function(m2)(.2), .2, tolerance = 1e-4) expect_equal(link_function(m3)(.2), log(.2), tolerance = 1e-4) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 38325) expect_equal(colnames(get_data(m1)), c("Euros", "dist_km", "Origin", "Destination", "Product")) expect_equal(nrow(get_data(m2)), 38325) expect_equal(colnames(get_data(m2)), c("Euros", "dist_km", "Origin", "Destination", "Product")) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_equal( find_formula(m1), list( conditional = as.formula("Euros ~ log(dist_km)"), cluster = as.formula("~Origin + Destination + Product") ) ) expect_length(find_formula(m2), 2) expect_equal( find_formula(m2), list( conditional = as.formula("log1p(Euros) ~ log(dist_km)"), cluster = as.formula("~Origin + Destination + Product") ) ) }) test_that("find_terms", { expect_equal( find_terms(m1), list(response = "Euros", conditional = "log(dist_km)", cluster = c("Origin", "Destination", "Product")) ) expect_equal( find_terms(m1, flatten = TRUE), c("Euros", "log(dist_km)", "Origin", "Destination", "Product") ) expect_equal( find_terms(m2), list(response = "log1p(Euros)", conditional = "log(dist_km)", cluster = c("Origin", "Destination", "Product")) ) expect_equal( find_terms(m2, flatten = TRUE), c("log1p(Euros)", "log(dist_km)", "Origin", "Destination", "Product") ) }) test_that("find_variables", { expect_equal( find_variables(m1), list(response = "Euros", conditional = "dist_km", cluster = c("Origin", "Destination", "Product")) ) expect_equal( find_variables(m1, flatten = TRUE), c("Euros", "dist_km", "Origin", "Destination", "Product") ) expect_equal( find_variables(m2), list(response = "Euros", conditional = "dist_km", cluster = c("Origin", "Destination", "Product")) ) expect_equal( find_variables(m1, flatten = TRUE), c("Euros", "dist_km", "Origin", "Destination", "Product") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 38325) expect_equal(n_obs(m2), 38325) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list(conditional = "log(dist_km)") ) expect_equal( get_parameters(m1), data.frame( Parameter = "log(dist_km)", Estimate = -1.52774702640008, row.names = NULL, stringsAsFactors = FALSE ), tolerance = 1e-4 ) expect_equal( find_parameters(m2), list(conditional = "log(dist_km)") ) expect_equal( get_parameters(m2), data.frame( Parameter = "log(dist_km)", Estimate = -2.16843021944503, row.names = NULL, stringsAsFactors = FALSE ), tolerance = 1e-4 ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") expect_identical(find_statistic(m2), "z-statistic") }) test_that("get_statistic", { stat <- get_statistic(m1) expect_equal(stat$Statistic, -13.212695, tolerance = 1e-3) stat <- get_statistic(m2) expect_equal(stat$Statistic, -14.065336, tolerance = 1e-3) }) } insight/tests/testthat/test-brms.R0000644000176200001440000005514013602425632016774 0ustar liggesusers.runThisTest <- Sys.getenv("RunAllinsightTests") == "yes" if (.runThisTest || Sys.getenv("USER") == "travis") { if (suppressWarnings(require("testthat") && require("insight") && require("brms"))) { context("insight, brms-find_response") # Model fitting ----------------------------------------------------------- m1 <- insight::download_model("brms_mixed_6") m2 <- insight::download_model("brms_mv_4") m3 <- insight::download_model("brms_2") m4 <- insight::download_model("brms_zi_3") m5 <- insight::download_model("brms_mv_5") m6 <- insight::download_model("brms_corr_re1") # Tests ------------------------------------------------------------------- test_that("find_statistic", { expect_null(find_statistic(m1)) expect_null(find_statistic(m2)) expect_null(find_statistic(m3)) expect_null(find_statistic(m4)) expect_null(find_statistic(m5)) }) test_that("model_info", { expect_true(model_info(m3)$is_trial) expect_true(model_info(m5)[[1]]$is_zero_inflated) expect_true(model_info(m5)[[1]]$is_bayesian) }) test_that("clean_names", { expect_identical( clean_names(m1), c("count", "Age", "Base", "Trt", "patient") ) expect_identical( clean_names(m2), c( "Sepal.Length", "Sepal.Width", "Petal.Length", "Species" ) ) expect_identical(clean_names(m3), c("r", "n", "treat", "c2")) expect_identical( clean_names(m4), c("count", "child", "camper", "persons") ) expect_identical( clean_names(m5), c( "count", "count2", "child", "camper", "persons", "livebait" ) ) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("Age", "Base", "Trt"))) expect_identical( find_predictors(m1, flatten = TRUE), c("Age", "Base", "Trt") ) expect_identical( find_predictors(m1, effects = "all", component = "all"), list( conditional = c("Age", "Base", "Trt"), random = "patient" ) ) expect_identical( find_predictors( m1, effects = "all", component = "all", flatten = TRUE ), c("Age", "Base", "Trt", "patient") ) expect_identical( find_predictors(m2), list( SepalLength = list(conditional = c( "Petal.Length", "Sepal.Width", "Species" )), SepalWidth = list(conditional = "Species") ) ) expect_identical( find_predictors(m2, flatten = TRUE), c("Petal.Length", "Sepal.Width", "Species") ) expect_identical(find_predictors(m3), list(conditional = c("treat", "c2"))) expect_identical( find_predictors(m4), list( conditional = c("child", "camper"), zero_inflated = c("child", "camper") ) ) expect_identical( find_predictors(m4, effects = "random"), list(random = "persons", zero_inflated_random = "persons") ) expect_identical(find_predictors(m4, flatten = TRUE), c("child", "camper")) expect_identical( find_predictors(m5), list( count = list( conditional = c("child", "camper"), zero_inflated = "camper" ), count2 = list( conditional = c("child", "livebait"), zero_inflated = "child" ) ) ) }) test_that("find_response", { expect_equal(find_response(m1, combine = TRUE), "count") expect_equal( find_response(m2, combine = TRUE), c(SepalLength = "Sepal.Length", SepalWidth = "Sepal.Width") ) expect_equal(find_response(m3, combine = TRUE), c("r", "n")) expect_equal(find_response(m1, combine = FALSE), "count") expect_equal( find_response(m2, combine = FALSE), c(SepalLength = "Sepal.Length", SepalWidth = "Sepal.Width") ) expect_equal(find_response(m3, combine = FALSE), c("r", "n")) expect_equal(find_response(m4, combine = FALSE), "count") expect_equal( find_response(m5, combine = TRUE), c(count = "count", count2 = "count2") ) }) test_that("get_response", { expect_length(get_response(m1), 236) expect_equal(ncol(get_response(m2)), 2) expect_equal( colnames(get_response(m2)), c("Sepal.Length", "Sepal.Width") ) expect_equal(ncol(get_response(m3)), 2) expect_equal(colnames(get_response(m3)), c("r", "n")) expect_length(get_response(m4), 250) expect_equal(colnames(get_response(m5)), c("count", "count2")) }) test_that("find_variables", { expect_identical( find_variables(m1), list( response = "count", conditional = c("Age", "Base", "Trt"), random = "patient" ) ) expect_identical( find_variables(m6), list( response = "y", conditional = "x", random = "id" ) ) expect_identical( find_variables(m1, effects = "fixed"), list( response = "count", conditional = c("Age", "Base", "Trt") ) ) expect_null(find_variables(m1, component = "zi")) expect_identical( find_variables(m2), list( response = c(SepalLength = "Sepal.Length", SepalWidth = "Sepal.Width"), SepalLength = list(conditional = c( "Petal.Length", "Sepal.Width", "Species" )), SepalWidth = list(conditional = "Species") ) ) expect_identical( find_variables(m2, flatten = TRUE), c( "Sepal.Length", "Sepal.Width", "Petal.Length", "Species" ) ) expect_identical(find_variables(m3), list( response = c("r", "n"), conditional = c("treat", "c2") )) expect_identical( find_variables(m4), list( response = "count", conditional = c("child", "camper"), random = "persons", zero_inflated = c("child", "camper"), zero_inflated_random = "persons" ) ) expect_identical( find_variables(m4, flatten = TRUE), c("count", "child", "camper", "persons") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 236) expect_equal(n_obs(m2), 150) expect_equal(n_obs(m3), 10) expect_equal(n_obs(m4), 250) expect_equal(n_obs(m5), 250) }) test_that("find_random", { expect_equal(find_random(m5), list( count = list( random = "persons", zero_inflated_random = "persons" ), count2 = list( random = "persons", zero_inflated_random = "persons" ) )) expect_equal(find_random(m5, flatten = TRUE), "persons") expect_equal(find_random(m6, flatten = TRUE), "id") }) test_that("get_random", { zinb <- get_data(m4) expect_equal(get_random(m4), zinb[, "persons", drop = FALSE]) }) test_that("get_data", { d <- get_data(m6) expect_equal(nrow(d), 200) expect_equal(ncol(d), 3) }) test_that("find_paramaters", { expect_equal( find_parameters(m1), list( conditional = c( "b_Intercept", "b_Age", "b_Base", "b_Trt1", "b_Base.Trt1" ), random = sprintf("r_patient.%i.Intercept.", 1:59) ) ) expect_equal( find_parameters(m2), structure(list( SepalLength = list( conditional = c( "b_SepalLength_Intercept", "b_SepalLength_Petal.Length", "b_SepalLength_Sepal.Width", "b_SepalLength_Speciesversicolor", "b_SepalLength_Speciesvirginica" ), sigma = "sigma_SepalLength" ), SepalWidth = list( conditional = c( "b_SepalWidth_Intercept", "b_SepalWidth_Speciesversicolor", "b_SepalWidth_Speciesvirginica" ), sigma = "sigma_SepalWidth" ) ), "is_mv" = "1" ) ) expect_equal( find_parameters(m4), list( conditional = c("b_Intercept", "b_child", "b_camper"), random = sprintf("r_persons.%i.Intercept.", 1:4), zero_inflated = c("b_zi_Intercept", "b_zi_child", "b_zi_camper"), zero_inflated_random = sprintf("r_persons__zi.%i.Intercept.", 1:4) ) ) expect_equal( find_parameters(m5), structure(list( count = list( conditional = c("b_count_Intercept", "b_count_child", "b_count_camper"), random = sprintf("r_persons__count.%i.Intercept.", 1:4), zero_inflated = c("b_zi_count_Intercept", "b_zi_count_camper"), zero_inflated_random = sprintf("r_persons__zi_count.%i.Intercept.", 1:4) ), count2 = list( conditional = c( "b_count2_Intercept", "b_count2_child", "b_count2_livebait" ), random = sprintf("r_persons__count2.%i.Intercept.", 1:4), zero_inflated = c("b_zi_count2_Intercept", "b_zi_count2_child"), zero_inflated_random = sprintf("r_persons__zi_count2.%i.Intercept.", 1:4) ) ), "is_mv" = "1" ) ) }) test_that("find_paramaters", { expect_equal( colnames(get_parameters(m4)), c( "b_Intercept", "b_child", "b_camper", "b_zi_Intercept", "b_zi_child", "b_zi_camper" ) ) expect_equal( colnames(get_parameters(m4, component = "zi")), c("b_zi_Intercept", "b_zi_child", "b_zi_camper") ) expect_equal( colnames(get_parameters(m4, effects = "all")), c( "b_Intercept", "b_child", "b_camper", "r_persons.1.Intercept.", "r_persons.2.Intercept.", "r_persons.3.Intercept.", "r_persons.4.Intercept.", "b_zi_Intercept", "b_zi_child", "b_zi_camper", "r_persons__zi.1.Intercept.", "r_persons__zi.2.Intercept.", "r_persons__zi.3.Intercept.", "r_persons__zi.4.Intercept." ) ) expect_equal( colnames(get_parameters( m4, effects = "random", component = "cond" )), c( "r_persons.1.Intercept.", "r_persons.2.Intercept.", "r_persons.3.Intercept.", "r_persons.4.Intercept." ) ) expect_equal( colnames(get_parameters( m5, effects = "random", component = "cond" )), c( "r_persons__count.1.Intercept.", "r_persons__count.2.Intercept.", "r_persons__count.3.Intercept.", "r_persons__count.4.Intercept.", "r_persons__count2.1.Intercept.", "r_persons__count2.2.Intercept.", "r_persons__count2.3.Intercept.", "r_persons__count2.4.Intercept." ) ) expect_equal( colnames(get_parameters( m5, effects = "all", component = "all" )), c( "b_count_Intercept", "b_count_child", "b_count_camper", "r_persons__count.1.Intercept.", "r_persons__count.2.Intercept.", "r_persons__count.3.Intercept.", "r_persons__count.4.Intercept.", "b_zi_count_Intercept", "b_zi_count_camper", "r_persons__zi_count.1.Intercept.", "r_persons__zi_count.2.Intercept.", "r_persons__zi_count.3.Intercept.", "r_persons__zi_count.4.Intercept.", "b_count2_Intercept", "b_count2_child", "b_count2_livebait", "r_persons__count2.1.Intercept.", "r_persons__count2.2.Intercept.", "r_persons__count2.3.Intercept.", "r_persons__count2.4.Intercept.", "b_zi_count2_Intercept", "b_zi_count2_child", "r_persons__zi_count2.1.Intercept.", "r_persons__zi_count2.2.Intercept.", "r_persons__zi_count2.3.Intercept.", "r_persons__zi_count2.4.Intercept." ) ) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) expect_length(link_function(m2), 2) expect_false(is.null(link_function(m3))) expect_false(is.null(link_function(m4))) expect_length(link_function(m5), 2) }) test_that("linkinv", { expect_false(is.null(link_inverse(m1))) expect_length(link_inverse(m2), 2) expect_false(is.null(link_inverse(m3))) expect_false(is.null(link_inverse(m4))) expect_length(link_inverse(m2), 2) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) expect_true(is_multivariate(m2)) expect_false(is_multivariate(m3)) expect_false(is_multivariate(m4)) expect_true(is_multivariate(m5)) }) test_that("find_terms", { expect_equal( find_terms(m2), list( SepalLength = list( response = "Sepal.Length", conditional = c("Petal.Length", "Sepal.Width", "Species") ), SepalWidth = list( response = "Sepal.Width", conditional = "Species" ) ) ) }) test_that("find_algorithm", { expect_equal( find_algorithm(m1), list( algorithm = "sampling", chains = 1, iterations = 500, warmup = 250 ) ) }) test_that("get_priors", { expect_equal( get_priors(m1), data.frame( Parameter = c("Age", "Base", "Base:Trt1", "Trt1"), Distribution = c("student_t", "student_t", "student_t", "student_t"), Location = c("5, 0", "5, 0", "5, 0", "5, 0"), Scale = c(10, 10, 10, 10), stringsAsFactors = FALSE ) ) expect_equal( get_priors(m3), data.frame( Parameter = c("c2", "treat1", "treat1:c2"), Distribution = c("uniform", "uniform", "uniform"), Location = c(0, 0, 0), Scale = c(NA, NA, NA), stringsAsFactors = FALSE ) ) }) test_that("clean_parameters", { expect_equal( clean_parameters(m4), structure( list( Parameter = c( "b_Intercept", "b_child", "b_camper", "r_persons.1.Intercept.", "r_persons.2.Intercept.", "r_persons.3.Intercept.", "r_persons.4.Intercept.", "b_zi_Intercept", "b_zi_child", "b_zi_camper", "r_persons__zi.1.Intercept.", "r_persons__zi.2.Intercept.", "r_persons__zi.3.Intercept.", "r_persons__zi.4.Intercept." ), Effects = c( "fixed", "fixed", "fixed", "random", "random", "random", "random", "fixed", "fixed", "fixed", "random", "random", "random", "random" ), Component = c( "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "zero_inflated", "zero_inflated", "zero_inflated", "zero_inflated", "zero_inflated", "zero_inflated", "zero_inflated" ), Group = c( "", "", "", "Intercept: persons", "Intercept: persons", "Intercept: persons", "Intercept: persons", "", "", "", "Intercept: persons", "Intercept: persons", "Intercept: persons", "Intercept: persons" ), Cleaned_Parameter = c( "(Intercept)", "child", "camper", "persons.1", "persons.2", "persons.3", "persons.4", "(Intercept)", "child", "camper", "persons.1", "persons.2", "persons.3", "persons.4" ) ), class = c("clean_parameters", "data.frame"), row.names = c(NA, -14L) ) ) expect_equal( clean_parameters(m5), structure( list( Parameter = c( "b_count_Intercept", "b_count_child", "b_count_camper", "b_count2_Intercept", "b_count2_child", "b_count2_livebait", "r_persons__count.1.Intercept.", "r_persons__count.2.Intercept.", "r_persons__count.3.Intercept.", "r_persons__count.4.Intercept.", "r_persons__count2.1.Intercept.", "r_persons__count2.2.Intercept.", "r_persons__count2.3.Intercept.", "r_persons__count2.4.Intercept.", "b_zi_count_Intercept", "b_zi_count_camper", "b_zi_count2_Intercept", "b_zi_count2_child", "r_persons__zi_count.1.Intercept.", "r_persons__zi_count.2.Intercept.", "r_persons__zi_count.3.Intercept.", "r_persons__zi_count.4.Intercept.", "r_persons__zi_count2.1.Intercept.", "r_persons__zi_count2.2.Intercept.", "r_persons__zi_count2.3.Intercept.", "r_persons__zi_count2.4.Intercept." ), Effects = c( "fixed", "fixed", "fixed", "fixed", "fixed", "fixed", "random", "random", "random", "random", "random", "random", "random", "random", "fixed", "fixed", "fixed", "fixed", "random", "random", "random", "random", "random", "random", "random", "random" ), Component = c( "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "zero_inflated", "zero_inflated", "zero_inflated", "zero_inflated", "zero_inflated", "zero_inflated", "zero_inflated", "zero_inflated", "zero_inflated", "zero_inflated", "zero_inflated", "zero_inflated" ), Group = c( "", "", "", "", "", "", "Intercept: persons", "Intercept: persons", "Intercept: persons", "Intercept: persons", "Intercept: persons2", "Intercept: persons2", "Intercept: persons2", "Intercept: persons2", "", "", "", "", "Intercept: persons", "Intercept: persons", "Intercept: persons", "Intercept: persons", "Intercept: persons2", "Intercept: persons2", "Intercept: persons2", "Intercept: persons2" ), Response = c( "count", "count", "count", "count2", "count2", "count2", "count", "count", "count", "count", "count2", "count2", "count2", "count2", "count", "count", "count2", "count2", "count", "count", "count", "count", "count2", "count2", "count2", "count2" ), Cleaned_Parameter = c( "(Intercept)", "child", "camper", "(Intercept)", "child", "livebait", "persons.1", "persons.2", "persons.3", "persons.4", "persons2.1", "persons2.2", "persons2.3", "persons2.4", "(Intercept)", "camper", "(Intercept)", "child", "persons.1", "persons.2", "persons.3", "persons.4", "persons2.1", "persons2.2", "persons2.3", "persons2.4" ) ), class = c("clean_parameters", "data.frame"), row.names = c(NA, -26L) ) ) }) } } insight/tests/testthat/test-format.R0000644000176200001440000000047013534510641017314 0ustar liggesusersif (require("testthat") && require("insight")) { context("insight, format") test_that("format_value", { expect_equal(nchar(format_value(1.2012313)), 4) expect_equal(format_value(4.2, protect_integers = TRUE), "4.20") expect_equal(format_value(4.0, protect_integers = TRUE), "4") }) } insight/tests/testthat/test-blmer.R0000644000176200001440000002205413552364343017135 0ustar liggesusersif (require("testthat") && require("insight") && require("blme")) { context("insight, blme") data(sleepstudy) set.seed(123) sleepstudy$mygrp <- sample(1:5, size = 180, replace = TRUE) sleepstudy$mysubgrp <- NA for (i in 1:5) { filter_group <- sleepstudy$mygrp == i sleepstudy$mysubgrp[filter_group] <- sample(1:30, size = sum(filter_group), replace = TRUE) } m1 <- blmer(Reaction ~ Days + (1 + Days | Subject), data = sleepstudy, cov.prior = NULL ) m2 <- blmer( Reaction ~ Days + (1 | mygrp / mysubgrp) + (1 | Subject), data = sleepstudy, cov.prior = wishart ) test_that("model_info", { expect_true(model_info(m1)$is_linear) expect_true(model_info(m2)$is_linear) expect_true(model_info(m1)$is_bayesian) }) test_that("find_predictors", { expect_equal( find_predictors(m1, effects = "all"), list(conditional = "Days", random = "Subject") ) expect_equal( find_predictors(m1, effects = "all", flatten = TRUE), c("Days", "Subject") ) expect_equal( find_predictors(m1, effects = "fixed"), list(conditional = "Days") ) expect_equal( find_predictors(m1, effects = "fixed", flatten = TRUE), "Days" ) expect_equal( find_predictors(m1, effects = "random"), list(random = "Subject") ) expect_equal( find_predictors(m1, effects = "random", flatten = TRUE), "Subject" ) expect_equal( find_predictors(m2, effects = "all"), list( conditional = "Days", random = c("mysubgrp", "mygrp", "Subject") ) ) expect_equal( find_predictors(m2, effects = "all", flatten = TRUE), c("Days", "mysubgrp", "mygrp", "Subject") ) expect_equal( find_predictors(m2, effects = "fixed"), list(conditional = "Days") ) expect_equal(find_predictors(m2, effects = "random"), list(random = c("mysubgrp", "mygrp", "Subject"))) expect_null(find_predictors(m2, effects = "all", component = "zi")) expect_null(find_predictors(m2, effects = "fixed", component = "zi")) expect_null(find_predictors(m2, effects = "random", component = "zi")) }) test_that("find_random", { expect_equal(find_random(m1), list(random = "Subject")) expect_equal(find_random(m1, flatten = TRUE), "Subject") expect_equal(find_random(m2), list(random = c("mysubgrp:mygrp", "mygrp", "Subject"))) expect_equal(find_random(m2, split_nested = TRUE), list(random = c("mysubgrp", "mygrp", "Subject"))) expect_equal( find_random(m2, flatten = TRUE), c("mysubgrp:mygrp", "mygrp", "Subject") ) expect_equal( find_random(m2, split_nested = TRUE, flatten = TRUE), c("mysubgrp", "mygrp", "Subject") ) }) test_that("find_response", { expect_identical(find_response(m1), "Reaction") expect_identical(find_response(m2), "Reaction") }) test_that("get_response", { expect_equal(get_response(m1), sleepstudy$Reaction) }) test_that("link_inverse", { expect_identical(link_inverse(m1)(.2), .2) expect_identical(link_inverse(m2)(.2), .2) }) test_that("get_data", { expect_equal(colnames(get_data(m1)), c("Reaction", "Days", "Subject")) expect_equal(colnames(get_data(m1, effects = "all")), c("Reaction", "Days", "Subject")) expect_equal(colnames(get_data(m1, effects = "random")), "Subject") expect_equal( colnames(get_data(m2)), c("Reaction", "Days", "mygrp", "mysubgrp", "Subject") ) expect_equal( colnames(get_data(m2, effects = "all")), c("Reaction", "Days", "mygrp", "mysubgrp", "Subject") ) expect_equal(colnames(get_data(m2, effects = "random")), c("mysubgrp", "mygrp", "Subject")) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_length(find_formula(m2), 2) expect_equal( find_formula(m1, component = "conditional"), list( conditional = as.formula("Reaction ~ Days"), random = as.formula("~1 + Days | Subject") ) ) expect_equal( find_formula(m2, component = "conditional"), list( conditional = as.formula("Reaction ~ Days"), random = list( as.formula("~1 | mysubgrp:mygrp"), as.formula("~1 | mygrp"), as.formula("~1 | Subject") ) ) ) }) test_that("find_terms", { expect_identical( find_terms(m1), list( response = "Reaction", conditional = "Days", random = c("Days", "Subject") ) ) expect_identical( find_terms(m1, flatten = TRUE), c("Reaction", "Days", "Subject") ) expect_identical( find_terms(m2), list( response = "Reaction", conditional = "Days", random = c("mysubgrp", "mygrp", "Subject") ) ) expect_identical( find_terms(m2, flatten = TRUE), c("Reaction", "Days", "mysubgrp", "mygrp", "Subject") ) }) test_that("find_variables", { expect_identical( find_variables(m1), list( response = "Reaction", conditional = "Days", random = "Subject" ) ) }) test_that("get_response", { expect_identical(get_response(m1), sleepstudy$Reaction) }) test_that("get_predictors", { expect_identical(colnames(get_predictors(m1)), "Days") expect_identical(colnames(get_predictors(m2)), "Days") }) test_that("get_random", { expect_identical(colnames(get_random(m1)), "Subject") expect_identical(colnames(get_random(m2)), c("mysubgrp", "mygrp", "Subject")) }) test_that("clean_names", { expect_identical(clean_names(m1), c("Reaction", "Days", "Subject")) expect_identical( clean_names(m2), c("Reaction", "Days", "mysubgrp", "mygrp", "Subject") ) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) expect_false(is.null(link_function(m2))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "Days"), random = list(Subject = c("(Intercept)", "Days")) ) ) expect_equal(nrow(get_parameters(m1)), 2) expect_equal(get_parameters(m1)$Parameter, c("(Intercept)", "Days")) expect_equal( find_parameters(m2), list( conditional = c("(Intercept)", "Days"), random = list( `mysubgrp:mygrp` = "(Intercept)", Subject = "(Intercept)", mygrp = "(Intercept)" ) ) ) expect_equal(nrow(get_parameters(m2)), 2) expect_equal(get_parameters(m2)$Parameter, c("(Intercept)", "Days")) expect_equal( names(get_parameters(m2, effects = "random")), c("mysubgrp:mygrp", "Subject", "mygrp") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) expect_false(is_multivariate(m2)) }) test_that("get_variance", { skip_on_cran() expect_equal( get_variance(m1), list( var.fixed = 908.95336262316459396970, var.random = 1698.23306388298283309268, var.residual = 654.94079585243218843971, var.distribution = 654.94079585243218843971, var.dispersion = 0, var.intercept = c(Subject = 611.89760710463770010392), var.slope = c(Subject.Days = 35.08106944030500073950), cor.slope_intercept = c(Subject = 0.06561803142425107205) ), tolerance = 1e-4 ) expect_equal(get_variance_fixed(m1), c(var.fixed = 908.95336262316459396970), tolerance = 1e-4 ) expect_equal(get_variance_random(m1), c(var.random = 1698.23306388298283309268), tolerance = 1e-4 ) expect_equal( get_variance_residual(m1), c(var.residual = 654.94079585243218843971), tolerance = 1e-4 ) expect_equal( get_variance_distribution(m1), c(var.distribution = 654.94079585243218843971), tolerance = 1e-4 ) expect_equal(get_variance_dispersion(m1), c(var.dispersion = 0), tolerance = 1e-4 ) expect_equal( get_variance_intercept(m1), c(var.intercept.Subject = 611.89760710463770010392), toleance = 1e-4 ) expect_equal( get_variance_slope(m1), c(var.slope.Subject.Days = 35.08106944030500073950), toleance = 1e-4 ) expect_equal( get_correlation_slope_intercept(m1), c(cor.slope_intercept.Subject = 0.06561803), toleance = 1e-4 ) }) test_that("find_algorithm", { expect_equal( find_algorithm(m1), list(algorithm = "REML", optimizer = "nloptwrap") ) }) test_that("find_random_slopes", { expect_equal(find_random_slopes(m1), list(random = "Days")) expect_null(find_random_slopes(m2)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") expect_identical(find_statistic(m2), "t-statistic") }) } insight/tests/testthat/test-iv_robust.R0000644000176200001440000000542513552364343020053 0ustar liggesusersif (require("testthat") && require("insight") && require("estimatr")) { context("insight, model_info") data(mtcars) m1 <- iv_robust(mpg ~ gear + cyl | carb + wt, data = mtcars) test_that("model_info", { expect_true(model_info(m1)$is_linear) }) test_that("find_predictors", { expect_identical( find_predictors(m1), list( conditional = c("gear", "cyl"), instruments = c("carb", "wt") ) ) expect_identical( find_predictors(m1, component = "instruments"), list(instruments = c("carb", "wt")) ) expect_identical( find_predictors(m1, flatten = TRUE), c("gear", "cyl", "carb", "wt") ) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "mpg") }) test_that("get_response", { expect_equal(get_response(m1), mtcars$mpg) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("gear", "cyl", "carb", "wt")) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 32) expect_equal( colnames(get_data(m1)), c("mpg", "carb + wt", "gear", "cyl", "carb", "wt") ) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_equal( find_formula(m1), list( conditional = as.formula("mpg ~ gear + cyl"), instruments = as.formula("~carb + wt") ) ) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "mpg", conditional = c("gear", "cyl"), instruments = c("carb", "wt") ) ) expect_equal( find_terms(m1, flatten = TRUE), c("mpg", "gear", "cyl", "carb", "wt") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 32) }) test_that("link_function", { expect_equal(link_function(m1)(.2), .2, tolerance = 1e-5) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list(conditional = c("(Intercept)", "gear", "cyl")) ) expect_equal(nrow(get_parameters(m1)), 3) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "gear", "cyl") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_algorithm", { expect_warning(expect_null(find_algorithm(m1))) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") }) } insight/tests/testthat/test-psm.R0000644000176200001440000000703513552364343016635 0ustar liggesusersif (require("testthat") && require("insight") && require("rms")) { context("insight, rms") n <- 400 set.seed(1) age <- rnorm(n, 50, 12) sex <- factor(sample(c("Female", "Male"), n, TRUE)) # Population hazard function: h <- .02 * exp(.06 * (age - 50) + .8 * (sex == "Female")) d.time <- -log(runif(n)) / h cens <- 15 * runif(n) death <- ifelse(d.time <= cens, 1, 0) d.time <- pmin(d.time, cens) dat <- data.frame(d.time, death, sex, age, stringsAsFactors = FALSE) m1 <- psm(Surv(d.time, death) ~ sex * pol(age, 2), dist = "lognormal", data = dat ) test_that("model_info", { expect_false(model_info(m1)$is_binomial) expect_false(model_info(m1)$is_logit) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("sex", "age"))) expect_identical(find_predictors(m1, flatten = TRUE), c("sex", "age")) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "Surv(d.time, death)") expect_identical(find_response(m1, combine = FALSE), c("d.time", "death")) }) test_that("get_response", { expect_equal(get_response(m1), dat[, c("d.time", "death")]) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("sex", "age")) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), exp(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 400) expect_equal(colnames(get_data(m1)), c("d.time", "death", "sex", "age")) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula( "Surv(d.time, death) ~ sex * pol(age, 2)" )) ) }) test_that("find_terms", { expect_length(find_terms(m1), 2) expect_equal( find_terms(m1), list( response = "Surv(d.time, death)", conditional = c("sex", "pol(age, 2)") ) ) }) test_that("find_variables", { expect_equal(find_variables(m1), list( response = c("d.time", "death"), conditional = c("sex", "age") )) expect_equal( find_variables(m1, flatten = TRUE), c("d.time", "death", "sex", "age") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 400) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("linkinverse", { expect_false(is.null(link_inverse(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c( "(Intercept)", "sex=Male", "age", "age^2", "sex=Male * age", "sex=Male * age^2" ) ) ) expect_equal(nrow(get_parameters(m1)), 6) expect_equal( get_parameters(m1)$Parameter, c( "(Intercept)", "sex=Male", "age", "age^2", "sex=Male * age", "sex=Male * age^2" ) ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_algorithm", { expect_warning(find_algorithm(m1)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") }) } insight/tests/testthat/test-speedlm.R0000644000176200001440000001007213552364343017462 0ustar liggesusersif (require("testthat") && require("insight") && require("speedglm")) { context("insight, model_info") data(iris) data(mtcars) m1 <- speedlm(Sepal.Length ~ Petal.Width + Species, data = iris) m2 <- speedlm(log(mpg) ~ log(hp) + cyl + I(cyl^2) + poly(wt, degree = 2, raw = TRUE), data = mtcars ) test_that("model_info", { expect_true(model_info(m1)$is_linear) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("Petal.Width", "Species"))) expect_identical( find_predictors(m1, flatten = TRUE), c("Petal.Width", "Species") ) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "Sepal.Length") }) test_that("get_response", { expect_equal(get_response(m1), iris$Sepal.Length) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("Petal.Width", "Species")) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("linkfun", { expect_equal(link_function(m1)(.2), .2, tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 150) expect_equal( colnames(get_data(m1)), c("Sepal.Length", "Petal.Width", "Species") ) expect_equal(colnames(get_data(m2)), c("mpg", "hp", "cyl", "wt")) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("Sepal.Length ~ Petal.Width + Species")) ) expect_equal( find_formula(m2), list( conditional = as.formula( "log(mpg) ~ log(hp) + cyl + I(cyl^2) + poly(wt, degree = 2, raw = TRUE)" ) ) ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "Sepal.Length", conditional = c("Petal.Width", "Species") ) ) expect_equal( find_variables(m1, flatten = TRUE), c("Sepal.Length", "Petal.Width", "Species") ) expect_equal( find_variables(m2, flatten = TRUE), c("mpg", "hp", "cyl", "wt") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 150) expect_equal(n_obs(m2), 32) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c( "(Intercept)", "Petal.Width", "Speciesversicolor", "Speciesvirginica" ) ) ) expect_equal( find_parameters(m2), list( conditional = c( "(Intercept)", "log(hp)", "cyl", "I(cyl^2)", "poly(wt, degree = 2, raw = TRUE)1", "poly(wt, degree = 2, raw = TRUE)2" ) ) ) expect_equal(nrow(get_parameters(m1)), 4) expect_equal( get_parameters(m1)$Parameter, c( "(Intercept)", "Petal.Width", "Speciesversicolor", "Speciesvirginica" ) ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "Sepal.Length", conditional = c("Petal.Width", "Species") ) ) expect_equal( find_terms(m2), list( response = "log(mpg)", conditional = c( "log(hp)", "cyl", "I(cyl^2)", "poly(wt, degree = 2, raw = TRUE)" ) ) ) }) test_that("find_algorithm", { expect_equal(find_algorithm(m1), list(algorithm = "eigen")) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") expect_identical(find_statistic(m2), "t-statistic") }) } insight/tests/testthat/test-mvrstanarm.R0000644000176200001440000006467313602362701020233 0ustar liggesusers.runThisTest <- Sys.getenv("RunAllinsightTests") == "yes" if (.runThisTest && Sys.getenv("USER") != "travis") { if (suppressWarnings(require("testthat") && require("insight") && require("rstanarm"))) { context("insight, mv-rstanarm") data("pbcLong") m1 <- download_model("stanmvreg_1") test_that("clean_names", { expect_identical( clean_names(m1), c("logBili", "albumin", "year", "id", "sex") ) }) test_that("find_predictors", { expect_identical( find_predictors(m1), list( y1 = list(conditional = "year"), y2 = list(conditional = c("sex", "year")) ) ) expect_identical(find_predictors(m1, flatten = TRUE), c("year", "sex")) expect_identical( find_predictors(m1, effects = "all", component = "all"), list( y1 = list(conditional = "year", random = "id"), y2 = list( conditional = c("sex", "year"), random = "id" ) ) ) expect_identical( find_predictors( m1, effects = "all", component = "all", flatten = TRUE ), c("year", "id", "sex") ) }) test_that("find_response", { expect_equal( find_response(m1, combine = TRUE), c(y1 = "logBili", y2 = "albumin") ) expect_equal( find_response(m1, combine = FALSE), c(y1 = "logBili", y2 = "albumin") ) }) test_that("get_response", { expect_equal(nrow(get_response(m1)), 304) expect_equal(colnames(get_response(m1)), c("logBili", "albumin")) }) test_that("find_statistic", { expect_null(find_statistic(m1)) }) test_that("find_variables", { expect_identical( find_variables(m1), list( response = c(y1 = "logBili", y2 = "albumin"), y1 = list(conditional = "year", random = "id"), y2 = list( conditional = c("sex", "year"), random = "id" ) ) ) expect_identical( find_variables(m1, flatten = TRUE), c("logBili", "albumin", "year", "id", "sex") ) expect_identical( find_variables(m1, effects = "random"), list( response = c(y1 = "logBili", y2 = "albumin"), y1 = list(random = "id"), y2 = list(random = "id") ) ) }) test_that("find_terms", { expect_identical( find_terms(m1), list( y1 = list( response = "logBili", conditional = "year", random = "id" ), y2 = list( response = "albumin", conditional = c("sex", "year"), random = c("year", "id") ) ) ) expect_identical( find_terms(m1, flatten = TRUE), c("logBili", "year", "id", "albumin", "sex") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 304) }) test_that("find_paramaters", { expect_equal( find_parameters(m1), structure(list( y1 = list( conditional = c("(Intercept)", "year"), random = sprintf("b[(Intercept) id:%i]", 1:40), sigma = "sigma" ), y2 = list( conditional = c("(Intercept)", "sexf", "year"), random = sprintf( c("b[(Intercept) id:%i]", "b[year id:%i]"), rep(1:40, each = 2) ), sigma = "sigma" ) ), is_mv = "1" ) ) expect_equal( find_parameters(m1, effects = "fixed"), structure(list( y1 = list( conditional = c("(Intercept)", "year"), sigma = "sigma" ), y2 = list( conditional = c("(Intercept)", "sexf", "year"), sigma = "sigma" ) ), is_mv = "1" ) ) expect_equal( find_parameters(m1, effects = "random"), structure(list( y1 = list(random = sprintf("b[(Intercept) id:%i]", 1:40)), y2 = list(random = sprintf( c("b[(Intercept) id:%i]", "b[year id:%i]"), rep(1:40, each = 2) )) ), is_mv = "1" ) ) }) test_that("get_paramaters", { expect_equal( colnames(get_parameters(m1)), c( "y1|(Intercept)", "y1|year", "y2|(Intercept)", "y2|sexf", "y2|year" ) ) expect_equal( colnames(get_parameters(m1, effects = "all")), c( "y1|(Intercept)", "y1|year", sprintf("b[y1|(Intercept) id:%i]", 1:40), "y2|(Intercept)", "y2|sexf", "y2|year", sprintf( c("b[y2|(Intercept) id:%i]", "b[y2|year id:%i]"), rep(1:40, each = 2) ) ) ) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) expect_length(link_function(m1), 2) }) test_that("linkinv", { expect_false(is.null(link_inverse(m1))) expect_length(link_inverse(m1), 2) }) test_that("is_multivariate", { expect_true(is_multivariate(m1)) }) test_that("clean_parameters", { expect_identical( clean_parameters(m1), structure( list( Parameter = c( "(Intercept)", "year", "(Intercept)", "sexf", "year", "b[(Intercept) id:1]", "b[(Intercept) id:2]", "b[(Intercept) id:3]", "b[(Intercept) id:4]", "b[(Intercept) id:5]", "b[(Intercept) id:6]", "b[(Intercept) id:7]", "b[(Intercept) id:8]", "b[(Intercept) id:9]", "b[(Intercept) id:10]", "b[(Intercept) id:11]", "b[(Intercept) id:12]", "b[(Intercept) id:13]", "b[(Intercept) id:14]", "b[(Intercept) id:15]", "b[(Intercept) id:16]", "b[(Intercept) id:17]", "b[(Intercept) id:18]", "b[(Intercept) id:19]", "b[(Intercept) id:20]", "b[(Intercept) id:21]", "b[(Intercept) id:22]", "b[(Intercept) id:23]", "b[(Intercept) id:24]", "b[(Intercept) id:25]", "b[(Intercept) id:26]", "b[(Intercept) id:27]", "b[(Intercept) id:28]", "b[(Intercept) id:29]", "b[(Intercept) id:30]", "b[(Intercept) id:31]", "b[(Intercept) id:32]", "b[(Intercept) id:33]", "b[(Intercept) id:34]", "b[(Intercept) id:35]", "b[(Intercept) id:36]", "b[(Intercept) id:37]", "b[(Intercept) id:38]", "b[(Intercept) id:39]", "b[(Intercept) id:40]", "b[(Intercept) id:1]", "b[year id:1]", "b[(Intercept) id:2]", "b[year id:2]", "b[(Intercept) id:3]", "b[year id:3]", "b[(Intercept) id:4]", "b[year id:4]", "b[(Intercept) id:5]", "b[year id:5]", "b[(Intercept) id:6]", "b[year id:6]", "b[(Intercept) id:7]", "b[year id:7]", "b[(Intercept) id:8]", "b[year id:8]", "b[(Intercept) id:9]", "b[year id:9]", "b[(Intercept) id:10]", "b[year id:10]", "b[(Intercept) id:11]", "b[year id:11]", "b[(Intercept) id:12]", "b[year id:12]", "b[(Intercept) id:13]", "b[year id:13]", "b[(Intercept) id:14]", "b[year id:14]", "b[(Intercept) id:15]", "b[year id:15]", "b[(Intercept) id:16]", "b[year id:16]", "b[(Intercept) id:17]", "b[year id:17]", "b[(Intercept) id:18]", "b[year id:18]", "b[(Intercept) id:19]", "b[year id:19]", "b[(Intercept) id:20]", "b[year id:20]", "b[(Intercept) id:21]", "b[year id:21]", "b[(Intercept) id:22]", "b[year id:22]", "b[(Intercept) id:23]", "b[year id:23]", "b[(Intercept) id:24]", "b[year id:24]", "b[(Intercept) id:25]", "b[year id:25]", "b[(Intercept) id:26]", "b[year id:26]", "b[(Intercept) id:27]", "b[year id:27]", "b[(Intercept) id:28]", "b[year id:28]", "b[(Intercept) id:29]", "b[year id:29]", "b[(Intercept) id:30]", "b[year id:30]", "b[(Intercept) id:31]", "b[year id:31]", "b[(Intercept) id:32]", "b[year id:32]", "b[(Intercept) id:33]", "b[year id:33]", "b[(Intercept) id:34]", "b[year id:34]", "b[(Intercept) id:35]", "b[year id:35]", "b[(Intercept) id:36]", "b[year id:36]", "b[(Intercept) id:37]", "b[year id:37]", "b[(Intercept) id:38]", "b[year id:38]", "b[(Intercept) id:39]", "b[year id:39]", "b[(Intercept) id:40]", "b[year id:40]", "sigma", "sigma" ), Effects = c( "fixed", "fixed", "fixed", "fixed", "fixed", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "random", "fixed", "fixed" ), Component = c( "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "conditional", "sigma", "sigma" ), Group = c( "", "", "", "", "", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "Intercept: id", "year: id", "", "" ), Response = c( "y1", "y1", "y2", "y2", "y2", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y1", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y2", "y1", "y2" ), Cleaned_Parameter = c( "(Intercept)", "year", "(Intercept)", "sexf", "year", "id:1", "id:2", "id:3", "id:4", "id:5", "id:6", "id:7", "id:8", "id:9", "id:10", "id:11", "id:12", "id:13", "id:14", "id:15", "id:16", "id:17", "id:18", "id:19", "id:20", "id:21", "id:22", "id:23", "id:24", "id:25", "id:26", "id:27", "id:28", "id:29", "id:30", "id:31", "id:32", "id:33", "id:34", "id:35", "id:36", "id:37", "id:38", "id:39", "id:40", "id:1", "id:1", "id:2", "id:2", "id:3", "id:3", "id:4", "id:4", "id:5", "id:5", "id:6", "id:6", "id:7", "id:7", "id:8", "id:8", "id:9", "id:9", "id:10", "id:10", "id:11", "id:11", "id:12", "id:12", "id:13", "id:13", "id:14", "id:14", "id:15", "id:15", "id:16", "id:16", "id:17", "id:17", "id:18", "id:18", "id:19", "id:19", "id:20", "id:20", "id:21", "id:21", "id:22", "id:22", "id:23", "id:23", "id:24", "id:24", "id:25", "id:25", "id:26", "id:26", "id:27", "id:27", "id:28", "id:28", "id:29", "id:29", "id:30", "id:30", "id:31", "id:31", "id:32", "id:32", "id:33", "id:33", "id:34", "id:34", "id:35", "id:35", "id:36", "id:36", "id:37", "id:37", "id:38", "id:38", "id:39", "id:39", "id:40", "id:40", "sigma", "sigma" ) ), class = c("clean_parameters", "data.frame"), row.names = c(NA, -127L) ) ) }) } } insight/tests/testthat/test-rlmer.R0000644000176200001440000002253013552364343017154 0ustar liggesusers.runThisTest <- Sys.getenv("RunAllinsightTests") == "yes" if (.runThisTest) { if (require("testthat") && require("insight") && require("lme4") && require("robustlmm")) { context("insight, find_predictors") data(sleepstudy) set.seed(123) sleepstudy$mygrp <- sample(1:5, size = 180, replace = TRUE) sleepstudy$mysubgrp <- NA for (i in 1:5) { filter_group <- sleepstudy$mygrp == i sleepstudy$mysubgrp[filter_group] <- sample(1:30, size = sum(filter_group), replace = TRUE ) } m1 <- rlmer( Reaction ~ Days + (Days | Subject), data = sleepstudy, rho.sigma.e = psi2propII(smoothPsi, k = 2.28), rho.sigma.b = chgDefaults(smoothPsi, k = 5.11, s = 10) ) m2 <- rlmer( Reaction ~ Days + (1 | mygrp / mysubgrp) + (1 | Subject), data = sleepstudy, rho.sigma.e = psi2propII(smoothPsi, k = 2.28), rho.sigma.b = chgDefaults(smoothPsi, k = 5.11, s = 10) ) test_that("model_info", { expect_true(model_info(m1)$is_linear) expect_true(model_info(m2)$is_linear) }) test_that("find_predictors", { expect_equal( find_predictors(m1, effects = "all"), list(conditional = "Days", random = "Subject") ) expect_equal( find_predictors(m1, effects = "all", flatten = TRUE), c("Days", "Subject") ) expect_equal( find_predictors(m1, effects = "fixed"), list(conditional = "Days") ) expect_equal( find_predictors(m1, effects = "fixed", flatten = TRUE), "Days" ) expect_equal( find_predictors(m1, effects = "random"), list(random = "Subject") ) expect_equal( find_predictors(m1, effects = "random", flatten = TRUE), "Subject" ) expect_equal( find_predictors(m2, effects = "all"), list( conditional = "Days", random = c("mysubgrp", "mygrp", "Subject") ) ) expect_equal( find_predictors(m2, effects = "all", flatten = TRUE), c("Days", "mysubgrp", "mygrp", "Subject") ) expect_equal( find_predictors(m2, effects = "fixed"), list(conditional = "Days") ) expect_equal(find_predictors(m2, effects = "random"), list(random = c("mysubgrp", "mygrp", "Subject"))) expect_null(find_predictors(m2, effects = "all", component = "zi")) expect_null(find_predictors(m2, effects = "fixed", component = "zi")) expect_null(find_predictors(m2, effects = "random", component = "zi")) }) test_that("find_random", { expect_equal(find_random(m1), list(random = "Subject")) expect_equal(find_random(m1, flatten = TRUE), "Subject") expect_equal(find_random(m2), list(random = c( "mysubgrp:mygrp", "mygrp", "Subject" ))) expect_equal(find_random(m2, split_nested = TRUE), list(random = c("mysubgrp", "mygrp", "Subject"))) expect_equal( find_random(m2, flatten = TRUE), c("mysubgrp:mygrp", "mygrp", "Subject") ) expect_equal( find_random(m2, split_nested = TRUE, flatten = TRUE), c("mysubgrp", "mygrp", "Subject") ) }) test_that("find_response", { expect_identical(find_response(m1), "Reaction") expect_identical(find_response(m2), "Reaction") }) test_that("get_response", { expect_equal(get_response(m1), sleepstudy$Reaction) }) test_that("link_inverse", { expect_identical(link_inverse(m1)(.2), .2) expect_identical(link_inverse(m2)(.2), .2) }) test_that("get_data", { expect_equal(colnames(get_data(m1)), c("Reaction", "Days", "Subject")) expect_equal(colnames(get_data(m1, effects = "all")), c("Reaction", "Days", "Subject")) expect_equal(colnames(get_data(m1, effects = "random")), "Subject") expect_equal( colnames(get_data(m2)), c("Reaction", "Days", "mysubgrp", "mygrp", "Subject") ) expect_equal( colnames(get_data(m2, effects = "all")), c("Reaction", "Days", "mysubgrp", "mygrp", "Subject") ) expect_equal(colnames(get_data(m2, effects = "random")), c("mysubgrp", "mygrp", "Subject")) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_length(find_formula(m2), 2) expect_equal( find_formula(m1, component = "conditional"), list( conditional = as.formula("Reaction ~ Days"), random = as.formula("~Days | Subject") ) ) expect_equal( find_formula(m2, component = "conditional"), list( conditional = as.formula("Reaction ~ Days"), random = list( as.formula("~1 | mysubgrp:mygrp"), as.formula("~1 | mygrp"), as.formula("~1 | Subject") ) ) ) }) test_that("find_terms", { expect_identical( find_terms(m1), list( response = "Reaction", conditional = "Days", random = c("Days", "Subject") ) ) expect_identical( find_terms(m1, flatten = TRUE), c("Reaction", "Days", "Subject") ) expect_identical( find_terms(m2), list( response = "Reaction", conditional = "Days", random = c("mysubgrp", "mygrp", "Subject") ) ) expect_identical( find_terms(m2, flatten = TRUE), c("Reaction", "Days", "mysubgrp", "mygrp", "Subject") ) }) test_that("find_variables", { expect_identical( find_variables(m1), list( response = "Reaction", conditional = "Days", random = "Subject" ) ) }) test_that("get_response", { expect_identical(get_response(m1), sleepstudy$Reaction) }) test_that("get_predictors", { expect_identical(colnames(get_predictors(m1)), "Days") expect_identical(colnames(get_predictors(m2)), "Days") }) test_that("get_random", { expect_identical(colnames(get_random(m1)), "Subject") expect_identical( colnames(get_random(m2)), c("mysubgrp", "mygrp", "Subject") ) }) test_that("clean_names", { expect_identical(clean_names(m1), c("Reaction", "Days", "Subject")) expect_identical( clean_names(m2), c("Reaction", "Days", "mysubgrp", "mygrp", "Subject") ) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) expect_false(is.null(link_function(m2))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "Days"), random = list(Subject = c("(Intercept)", "Days")) ) ) expect_equal(nrow(get_parameters(m1)), 2) expect_equal(get_parameters(m1)$Parameter, c("(Intercept)", "Days")) expect_equal( find_parameters(m2), list( conditional = c("(Intercept)", "Days"), random = list( `mysubgrp:mygrp` = "(Intercept)", Subject = "(Intercept)", mygrp = "(Intercept)" ) ) ) expect_equal(nrow(get_parameters(m2)), 2) expect_equal(get_parameters(m2)$Parameter, c("(Intercept)", "Days")) expect_equal( names(get_parameters(m2, effects = "random")), c("mysubgrp:mygrp", "Subject", "mygrp") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) expect_false(is_multivariate(m2)) }) test_that("get_variance", { skip_on_cran() skip_on_travis() expect_equal( get_variance(m1), list( var.fixed = 972.98333873885542288917, var.random = 1909.82627106414997797401, var.residual = 401.79840084390571064432, var.distribution = 401.79840084390571064432, var.dispersion = 0, var.intercept = c(Subject = 750.51639089692923789698), var.slope = c(Subject.Days = 41.06728604073937560770), cor.slope_intercept = c(Subject = -0.00703001666895963079) ), tolerance = 1e-4 ) expect_equal( get_variance(m2), list( var.fixed = 914.841369525452, var.random = 1406.78220090082, var.residual = 809.318117324236, var.distribution = 809.318117324236, var.dispersion = 0, var.intercept = c( `mysubgrp:mygrp` = 0, Subject = 1390.66848951126, mygrp = 16.113711389561 ) ), tolerance = 1e-4 ) }) test_that("find_algorithm", { expect_equal( find_algorithm(m1), list(algorithm = "REML", optimizer = "rlmer.fit.DAS.nondiag") ) }) test_that("find_random_slopes", { expect_equal(find_random_slopes(m1), list(random = "Days")) expect_null(find_random_slopes(m2)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") expect_identical(find_statistic(m2), "t-statistic") }) } } insight/tests/testthat/test-mixed.R0000644000176200001440000002233113552364343017140 0ustar liggesusersif (require("testthat") && require("insight") && require("lme4") && require("afex")) { context("insight, find_predictors") data(sleepstudy) set.seed(123) sleepstudy$mygrp <- sample(1:5, size = 180, replace = TRUE) sleepstudy$mysubgrp <- NA for (i in 1:5) { filter_group <- sleepstudy$mygrp == i sleepstudy$mysubgrp[filter_group] <- sample(1:30, size = sum(filter_group), replace = TRUE) } m1 <- mixed(Reaction ~ Days + (1 + Days | Subject), data = sleepstudy ) m2 <- mixed(Reaction ~ Days + (1 | mygrp / mysubgrp) + (1 | Subject), data = sleepstudy ) test_that("model_info", { expect_true(model_info(m1)$is_linear) expect_true(model_info(m2)$is_linear) }) test_that("find_predictors", { expect_equal( find_predictors(m1, effects = "all"), list(conditional = "Days", random = "Subject") ) expect_equal( find_predictors(m1, effects = "all", flatten = TRUE), c("Days", "Subject") ) expect_equal( find_predictors(m1, effects = "fixed"), list(conditional = "Days") ) expect_equal( find_predictors(m1, effects = "fixed", flatten = TRUE), "Days" ) expect_equal( find_predictors(m1, effects = "random"), list(random = "Subject") ) expect_equal( find_predictors(m1, effects = "random", flatten = TRUE), "Subject" ) expect_equal( find_predictors(m2, effects = "all"), list( conditional = "Days", random = c("mysubgrp", "mygrp", "Subject") ) ) expect_equal( find_predictors(m2, effects = "all", flatten = TRUE), c("Days", "mysubgrp", "mygrp", "Subject") ) expect_equal( find_predictors(m2, effects = "fixed"), list(conditional = "Days") ) expect_equal(find_predictors(m2, effects = "random"), list(random = c("mysubgrp", "mygrp", "Subject"))) expect_null(find_predictors(m2, effects = "all", component = "zi")) expect_null(find_predictors(m2, effects = "fixed", component = "zi")) expect_null(find_predictors(m2, effects = "random", component = "zi")) }) test_that("find_random", { expect_equal(find_random(m1), list(random = "Subject")) expect_equal(find_random(m1, flatten = TRUE), "Subject") expect_equal(find_random(m2), list(random = c("mysubgrp:mygrp", "mygrp", "Subject"))) expect_equal(find_random(m2, split_nested = TRUE), list(random = c("mysubgrp", "mygrp", "Subject"))) expect_equal( find_random(m2, flatten = TRUE), c("mysubgrp:mygrp", "mygrp", "Subject") ) expect_equal( find_random(m2, split_nested = TRUE, flatten = TRUE), c("mysubgrp", "mygrp", "Subject") ) }) test_that("find_response", { expect_identical(find_response(m1), "Reaction") expect_identical(find_response(m2), "Reaction") }) test_that("get_response", { expect_equal(get_response(m1), sleepstudy$Reaction) }) test_that("link_inverse", { expect_identical(link_inverse(m1)(.2), .2) expect_identical(link_inverse(m2)(.2), .2) }) test_that("get_data", { expect_equal(colnames(get_data(m1)), c("Reaction", "Days", "Subject")) expect_equal(colnames(get_data(m1, effects = "all")), c("Reaction", "Days", "Subject")) expect_equal(colnames(get_data(m1, effects = "random")), "Subject") expect_equal( colnames(get_data(m2)), c("Reaction", "Days", "mysubgrp", "mygrp", "Subject") ) expect_equal( colnames(get_data(m2, effects = "all")), c("Reaction", "Days", "mysubgrp", "mygrp", "Subject") ) expect_equal(colnames(get_data(m2, effects = "random")), c("mysubgrp", "mygrp", "Subject")) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_length(find_formula(m2), 2) expect_equal( find_formula(m1, component = "conditional"), list( conditional = as.formula("Reaction ~ Days"), random = as.formula("~1 + Days | Subject") ) ) expect_equal( find_formula(m2, component = "conditional"), list( conditional = as.formula("Reaction ~ Days"), random = list( as.formula("~1 | mysubgrp:mygrp"), as.formula("~1 | mygrp"), as.formula("~1 | Subject") ) ) ) }) test_that("find_variables", { expect_identical( find_variables(m1), list( response = "Reaction", conditional = "Days", random = "Subject" ) ) expect_identical( find_variables(m1, flatten = TRUE), c("Reaction", "Days", "Subject") ) expect_identical( find_variables(m2), list( response = "Reaction", conditional = "Days", random = c("mysubgrp", "mygrp", "Subject") ) ) expect_identical( find_variables(m2, flatten = TRUE), c("Reaction", "Days", "mysubgrp", "mygrp", "Subject") ) }) test_that("get_response", { expect_identical(get_response(m1), sleepstudy$Reaction) }) test_that("get_predictors", { expect_identical(colnames(get_predictors(m1)), "Days") expect_identical(colnames(get_predictors(m2)), "Days") }) test_that("get_random", { expect_identical(colnames(get_random(m1)), "Subject") expect_identical(colnames(get_random(m2)), c("mysubgrp", "mygrp", "Subject")) }) test_that("clean_names", { expect_identical(clean_names(m1), c("Reaction", "Days", "Subject")) expect_identical( clean_names(m2), c("Reaction", "Days", "mysubgrp", "mygrp", "Subject") ) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) expect_false(is.null(link_function(m2))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "Days"), random = list(Subject = c("(Intercept)", "Days")) ) ) expect_equal(nrow(get_parameters(m1)), 2) expect_equal(get_parameters(m1)$Parameter, c("(Intercept)", "Days")) expect_equal( find_parameters(m2), list( conditional = c("(Intercept)", "Days"), random = list( `mysubgrp:mygrp` = "(Intercept)", Subject = "(Intercept)", mygrp = "(Intercept)" ) ) ) expect_equal(nrow(get_parameters(m2)), 2) expect_equal(get_parameters(m2)$Parameter, c("(Intercept)", "Days")) expect_equal( names(get_parameters(m2, effects = "random")), c("mysubgrp:mygrp", "Subject", "mygrp") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) expect_false(is_multivariate(m2)) }) test_that("get_variance", { skip_on_cran() skip_on_travis() expect_equal( get_variance(m1), list( var.fixed = 908.95336262316459396970, var.random = 1698.23306388298283309268, var.residual = 654.94079585243218843971, var.distribution = 654.94079585243218843971, var.dispersion = 0, var.intercept = c(Subject = 611.89760710463770010392), var.slope = c(Subject.Days = 35.08106944030500073950), cor.slope_intercept = c(Subject = 0.06561803142425107205) ), tolerance = 1e-4 ) expect_equal(get_variance_fixed(m1), c(var.fixed = 908.95336262316459396970), tolerance = 1e-4 ) expect_equal(get_variance_random(m1), c(var.random = 1698.23306388298283309268), tolerance = 1e-4 ) expect_equal( get_variance_residual(m1), c(var.residual = 654.94079585243218843971), tolerance = 1e-4 ) expect_equal( get_variance_distribution(m1), c(var.distribution = 654.94079585243218843971), tolerance = 1e-4 ) expect_equal(get_variance_dispersion(m1), c(var.dispersion = 0), tolerance = 1e-4 ) expect_equal( get_variance_intercept(m1), c(var.intercept.Subject = 611.89760710463770010392), toleance = 1e-4 ) expect_equal( get_variance_slope(m1), c(var.slope.Subject.Days = 35.08106944030500073950), toleance = 1e-4 ) expect_equal( get_correlation_slope_intercept(m1), c(cor.slope_intercept.Subject = 0.06561803), toleance = 1e-4 ) expect_warning(expect_equal( get_variance(m2), list( var.fixed = 889.329700216337, var.residual = 941.817768377025, var.distribution = 941.817768377025, var.dispersion = 0, var.intercept = c( `mysubgrp:mygrp` = 0, Subject = 1357.35782386825, mygrp = 24.4073139080596 ) ), tolerance = 1e-4, )) }) test_that("find_algorithm", { expect_equal( find_algorithm(m1), list(algorithm = "REML", optimizer = "nloptwrap") ) }) test_that("find_random_slopes", { expect_equal(find_random_slopes(m1), list(random = "Days")) expect_null(find_random_slopes(m2)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") expect_identical(find_statistic(m2), "t-statistic") }) } insight/tests/testthat/test-vglm.R0000644000176200001440000000554013552364343017002 0ustar liggesusersunloadNamespace("gam") if (require("testthat") && require("insight") && require("VGAM")) { context("insight, model_info") d.AD <- data.frame( treatment = gl(3, 3), outcome = gl(3, 1, 9), counts = c(18, 17, 15, 20, 10, 20, 25, 13, 12) ) m1 <- vglm( counts ~ outcome + treatment, family = poissonff, data = d.AD, trace = TRUE ) test_that("model_info", { expect_true(model_info(m1)$is_poisson) expect_false(model_info(m1)$is_bayesian) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("outcome", "treatment"))) expect_identical( find_predictors(m1, flatten = TRUE), c("outcome", "treatment") ) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "counts") }) test_that("get_response", { expect_equal(get_response(m1), d.AD$counts) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("outcome", "treatment")) }) li <- suppressWarnings(link_inverse(m1)(.2)[1, 1]) test_that("link_inverse", { expect_equal(li, exp(.2), tolerance = 1e-5) expect_warning(link_inverse(m1)(.2)) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 9) expect_equal(colnames(get_data(m1)), c("counts", "outcome", "treatment")) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("counts ~ outcome + treatment")) ) }) test_that("find_terms", { expect_equal(find_terms(m1), list( response = "counts", conditional = c("outcome", "treatment") )) expect_equal( find_terms(m1, flatten = TRUE), c("counts", "outcome", "treatment") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 9) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c( "(Intercept)", "outcome2", "outcome3", "treatment2", "treatment3" ) ) ) expect_equal(nrow(get_parameters(m1)), 5) expect_equal( get_parameters(m1)$Parameter, c( "(Intercept)", "outcome2", "outcome3", "treatment2", "treatment3" ) ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") }) } insight/tests/testthat/test-rms.R0000644000176200001440000000462313552364343016637 0ustar liggesusersif (require("testthat") && require("insight") && require("rms")) { context("insight, model_info") data(mtcars) m1 <- lrm(am ~ mpg + gear, data = mtcars) test_that("model_info", { expect_true(model_info(m1)$is_binomial) expect_true(model_info(m1)$is_logit) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("mpg", "gear"))) expect_identical(find_predictors(m1, flatten = TRUE), c("mpg", "gear")) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "am") }) test_that("get_response", { expect_equal(get_response(m1), mtcars$am) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("mpg", "gear")) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), plogis(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 32) expect_equal(colnames(get_data(m1)), c("am", "mpg", "gear")) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("am ~ mpg + gear")) ) }) test_that("find_terms", { expect_equal(find_terms(m1), list( response = "am", conditional = c("mpg", "gear") )) expect_equal(find_terms(m1, flatten = TRUE), c("am", "mpg", "gear")) }) test_that("n_obs", { expect_equal(n_obs(m1), 32) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("linkinverse", { expect_false(is.null(link_inverse(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list(conditional = c("Intercept", "mpg", "gear")) ) expect_equal(nrow(get_parameters(m1)), 3) expect_equal( get_parameters(m1)$Parameter, c("Intercept", "mpg", "gear") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_algorithm", { expect_equal(find_algorithm(m1), list(algorithm = "ML")) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") }) } insight/tests/testthat/test-LORgee.R0000644000176200001440000000752413615534722017156 0ustar liggesusersif (require("testthat") && require("insight") && require("multgee")) { context("insight, multgee") data(arthritis) m1 <- ordLORgee( y ~ factor(time) + factor(trt) + factor(baseline), data = arthritis, id = id, LORstr = "uniform", repeated = time ) test_that("model_info", { expect_true(model_info(m1)$is_ordinal) expect_false(model_info(m1)$is_multinomial) expect_true(model_info(m1)$is_logit) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("time", "trt", "baseline"))) expect_identical( find_predictors(m1, flatten = TRUE), c("time", "trt", "baseline") ) expect_identical(find_predictors(m1, effects = "random"), list(random = "id")) expect_identical( find_predictors(m1, effects = "all", flatten = TRUE), c("time", "trt", "baseline", "id") ) }) test_that("find_response", { expect_identical(find_response(m1), "y") }) test_that("get_response", { expect_equal(get_response(m1), na.omit(arthritis)$y) }) test_that("find_random", { expect_equal(find_random(m1), list(random = "id")) }) test_that("get_random", { expect_equal(get_random(m1), arthritis[, "id", drop = FALSE]) }) test_that("get_predictors", { expect_equal(get_predictors(m1), na.omit(arthritis)[, c("time", "trt", "baseline"), drop = FALSE]) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), plogis(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 888) expect_equal( colnames(get_data(m1)), c("y", "time", "trt", "baseline", "id") ) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_equal( find_formula(m1), list( conditional = as.formula("y ~ factor(time) + factor(trt) + factor(baseline)"), random = as.formula("~id") ) ) }) test_that("find_terms", { expect_length(find_terms(m1), 3) expect_equal( find_terms(m1), list( response = "y", conditional = c("factor(time)", "factor(trt)", "factor(baseline)"), random = "id" ) ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "y", conditional = c("time", "trt", "baseline"), random = "id" ) ) expect_equal( find_variables(m1, flatten = TRUE), c("y", "time", "trt", "baseline", "id") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 888) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c( "beta10", "beta20", "beta30", "beta40", "factor(time)3", "factor(time)5", "factor(trt)2", "factor(baseline)2", "factor(baseline)3", "factor(baseline)4", "factor(baseline)5" ) ) ) expect_equal(nrow(get_parameters(m1)), 11) expect_equal( get_parameters(m1)$Parameter, c( "beta10", "beta20", "beta30", "beta40", "factor(time)3", "factor(time)5", "factor(trt)2", "factor(baseline)2", "factor(baseline)3", "factor(baseline)4", "factor(baseline)5" ) ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_algorithm", { expect_equal(find_algorithm(m1), list(algorithm = "Fisher's scoring ML")) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") }) } insight/tests/testthat/test-hurdle.R0000644000176200001440000000615413552364343017322 0ustar liggesusersif (require("testthat") && require("insight") && require("pscl")) { context("insight, model_info") data("bioChemists") m1 <- hurdle(art ~ fem + mar + kid5 + ment | kid5 + phd, data = bioChemists) test_that("model_info", { expect_true(model_info(m1)$is_poisson) expect_true(model_info(m1)$is_zero_inflated) }) test_that("find_predictors", { expect_identical( find_predictors(m1), list( conditional = c("fem", "mar", "kid5", "ment"), zero_inflated = c("kid5", "phd") ) ) expect_identical( find_predictors(m1, flatten = TRUE), c("fem", "mar", "kid5", "ment", "phd") ) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_response", { expect_identical(find_response(m1), "art") }) test_that("get_response", { expect_equal(get_response(m1), bioChemists$art) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), exp(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 915) expect_equal( colnames(get_data(m1)), c("art", "fem", "mar", "kid5", "ment", "phd") ) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_equal( find_formula(m1), list( conditional = as.formula("art ~ fem + mar + kid5 + ment"), zero_inflated = as.formula("~kid5 + phd") ) ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "art", conditional = c("fem", "mar", "kid5", "ment"), zero_inflated = c("kid5", "phd") ) ) expect_equal( find_variables(m1, flatten = TRUE), c("art", "fem", "mar", "kid5", "ment", "phd") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 915) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c( "count_(Intercept)", "count_femWomen", "count_marMarried", "count_kid5", "count_ment" ), zero_inflated = c("zero_(Intercept)", "zero_kid5", "zero_phd") ) ) expect_equal(nrow(get_parameters(m1)), 8) expect_equal(nrow(get_parameters(m1, component = "zi")), 3) expect_equal( get_parameters(m1)$Parameter, c( "count_(Intercept)", "count_femWomen", "count_marMarried", "count_kid5", "count_ment", "zero_(Intercept)", "zero_kid5", "zero_phd" ) ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "art", conditional = c("fem", "mar", "kid5", "ment"), zero_inflated = c("kid5", "phd") ) ) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") }) } insight/tests/testthat/test-rq.R0000644000176200001440000000517713552364343016465 0ustar liggesusersif (require("testthat") && require("insight") && require("quantreg")) { context("insight, model_info") data(stackloss) m1 <- rq(stack.loss ~ Air.Flow + Water.Temp, data = stackloss, tau = .25 ) test_that("model_info", { expect_true(model_info(m1)$is_linear) }) test_that("find_predictors", { expect_identical( find_predictors(m1), list(conditional = c("Air.Flow", "Water.Temp")) ) expect_identical( find_predictors(m1, flatten = TRUE), c("Air.Flow", "Water.Temp") ) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "stack.loss") }) test_that("get_response", { expect_equal(get_response(m1), stackloss$stack.loss) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("Air.Flow", "Water.Temp")) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 21) expect_equal( colnames(get_data(m1)), c("stack.loss", "Air.Flow", "Water.Temp") ) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("stack.loss ~ Air.Flow + Water.Temp")) ) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "stack.loss", conditional = c("Air.Flow", "Water.Temp") ) ) expect_equal( find_terms(m1, flatten = TRUE), c("stack.loss", "Air.Flow", "Water.Temp") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 21) }) test_that("link_function", { expect_equal(link_function(m1)(.2), .2, tolerance = 1e-5) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list(conditional = c( "(Intercept)", "Air.Flow", "Water.Temp" )) ) expect_equal(nrow(get_parameters(m1)), 3) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "Air.Flow", "Water.Temp") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_algorithm", { expect_equal(find_algorithm(m1), list(algorithm = "br")) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") }) } insight/tests/testthat/test-zeroinfl.R0000644000176200001440000000531413552364343017664 0ustar liggesusersif (require("testthat") && require("insight") && require("pscl")) { context("insight, model_info") data("bioChemists") m1 <- zeroinfl(art ~ fem + mar + kid5 + ment | kid5 + phd, data = bioChemists) test_that("model_info", { expect_true(model_info(m1)$is_poisson) expect_true(model_info(m1)$is_zero_inflated) }) test_that("find_predictors", { expect_identical( find_predictors(m1), list( conditional = c("fem", "mar", "kid5", "ment"), zero_inflated = c("kid5", "phd") ) ) expect_identical( find_predictors(m1, flatten = TRUE), c("fem", "mar", "kid5", "ment", "phd") ) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_response", { expect_identical(find_response(m1), "art") }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), exp(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 915) expect_equal( colnames(get_data(m1)), c("art", "fem", "mar", "kid5", "ment", "phd") ) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_equal( find_formula(m1), list( conditional = as.formula("art ~ fem + mar + kid5 + ment"), zero_inflated = as.formula("~kid5 + phd") ) ) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "art", conditional = c("fem", "mar", "kid5", "ment"), zero_inflated = c("kid5", "phd") ) ) expect_equal( find_terms(m1, flatten = TRUE), c("art", "fem", "mar", "kid5", "ment", "phd") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 915) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c( "count_(Intercept)", "count_femWomen", "count_marMarried", "count_kid5", "count_ment" ), zero_inflated = c("zero_(Intercept)", "zero_kid5", "zero_phd") ) ) expect_equal(nrow(get_parameters(m1)), 8) expect_equal(nrow(get_parameters(m1, component = "zi")), 3) expect_equal( get_parameters(m1)$Parameter, c( "count_(Intercept)", "count_femWomen", "count_marMarried", "count_kid5", "count_ment", "zero_(Intercept)", "zero_kid5", "zero_phd" ) ) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "z-statistic") }) } insight/tests/testthat/test-data.frame.R0000644000176200001440000000053013531007236020021 0ustar liggesusersif (require("testthat") && require("insight")) { context("insight, data.frame") data(iris) test_that("find_parameters", { expect_error(find_parameters(iris)) }) test_that("find_formula", { expect_error(find_formula(iris)) }) test_that("find_statistic", { expect_error(find_statistic(iris)) }) } insight/tests/testthat/test-lm_robust.R0000644000176200001440000000471713552364343020050 0ustar liggesusersif (require("testthat") && require("insight") && require("estimatr")) { context("insight, model_info") data(mtcars) m1 <- lm_robust(mpg ~ gear + wt + cyl, data = mtcars) test_that("model_info", { expect_true(model_info(m1)$is_linear) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("gear", "wt", "cyl"))) expect_identical(find_predictors(m1, flatten = TRUE), c("gear", "wt", "cyl")) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "mpg") }) test_that("get_response", { expect_equal(get_response(m1), mtcars$mpg) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), c("gear", "wt", "cyl")) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 32) expect_equal(colnames(get_data(m1)), c("mpg", "gear", "wt", "cyl")) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("mpg ~ gear + wt + cyl")) ) }) test_that("find_terms", { expect_equal(find_terms(m1), list( response = "mpg", conditional = c("gear", "wt", "cyl") )) expect_equal(find_terms(m1, flatten = TRUE), c("mpg", "gear", "wt", "cyl")) }) test_that("n_obs", { expect_equal(n_obs(m1), 32) }) test_that("link_function", { expect_equal(link_function(m1)(.2), .2, tolerance = 1e-5) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list(conditional = c("(Intercept)", "gear", "wt", "cyl")) ) expect_equal(nrow(get_parameters(m1)), 4) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "gear", "wt", "cyl") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_algorithm", { expect_warning(expect_null(find_algorithm(m1))) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") }) } insight/tests/testthat/test-cpglmm.R0000644000176200001440000001012113602213235017270 0ustar liggesusersif (require("testthat") && require("insight") && require("cplm")) { data("FineRoot") m1 <- cpglmm(RLD ~ Stock + Spacing + (1 | Plant), data = FineRoot) test_that("model_info", { expect_true(model_info(m1)$is_count) }) test_that("find_predictors", { expect_equal( find_predictors(m1, effects = "all"), list(conditional = c("Stock", "Spacing"), random = "Plant") ) expect_equal( find_predictors(m1, effects = "all", flatten = TRUE), c("Stock", "Spacing", "Plant") ) expect_equal( find_predictors(m1, effects = "fixed"), list(conditional = c("Stock", "Spacing")) ) expect_equal( find_predictors(m1, effects = "fixed", flatten = TRUE), c("Stock", "Spacing") ) expect_equal( find_predictors(m1, effects = "random"), list(random = "Plant") ) expect_equal( find_predictors(m1, effects = "random", flatten = TRUE), "Plant" ) }) test_that("find_random", { expect_equal(find_random(m1), list(random = "Plant")) expect_equal(find_random(m1, flatten = TRUE), "Plant") }) test_that("find_response", { expect_identical(find_response(m1), "RLD") }) test_that("get_response", { expect_equal(get_response(m1), FineRoot$RLD) }) test_that("get_data", { expect_equal(colnames(get_data(m1)), c("RLD", "Stock", "Spacing", "Plant")) expect_equal(colnames(get_data(m1, effects = "all")), c("RLD", "Stock", "Spacing", "Plant")) expect_equal(colnames(get_data(m1, effects = "random")), "Plant") }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_equal( find_formula(m1, component = "conditional"), list( conditional = as.formula("RLD ~ Stock + Spacing"), random = as.formula("~1 | Plant") ) ) }) test_that("find_terms", { expect_identical( find_terms(m1), list( response = "RLD", conditional = c("Stock", "Spacing"), random = "Plant" ) ) expect_identical( find_terms(m1, flatten = TRUE), c("RLD", "Stock", "Spacing", "Plant") ) }) test_that("link_function", { expect_equal(link_function(m1)(.2), log(.2), tolerance = 1e-3) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), exp(.2), tolerance = 1e-3) }) test_that("find_variables", { expect_identical( find_variables(m1), list( response = "RLD", conditional = c("Stock", "Spacing"), random = "Plant" ) ) expect_identical( find_variables(m1, flatten = TRUE), c("RLD", "Stock", "Spacing", "Plant") ) }) test_that("get_predictors", { expect_identical(colnames(get_predictors(m1)), c("Stock", "Spacing")) }) test_that("get_random", { expect_identical(colnames(get_random(m1)), "Plant") }) test_that("clean_names", { expect_identical(clean_names(m1), c("RLD", "Stock", "Spacing", "Plant")) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "StockMM106", "StockMark", "Spacing5x3"), random = list(Plant = c("(Intercept)")) ) ) expect_equal(nrow(get_parameters(m1)), 4) expect_equal(get_parameters(m1)$Parameter, c("(Intercept)", "StockMM106", "StockMark", "Spacing5x3")) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("get_variance", { skip_on_cran() skip_on_travis() expect_equal( get_variance(m1), list( var.fixed = 0.1687617, var.random = 0.0002706301, var.residual = 2.763129, var.distribution = 2.763129, var.dispersion = 0, var.intercept = c(Plant = 0.0002706301) ), tolerance = 1e-3 ) }) test_that("find_random_slopes", { expect_null(find_random_slopes(m1)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") }) } insight/tests/testthat/test-ivreg.R0000644000176200001440000000703313552364343017150 0ustar liggesusersif (require("testthat") && require("insight") && require("AER")) { context("insight, model_info") data(CigarettesSW) CigarettesSW$rprice <- with(CigarettesSW, price / cpi) CigarettesSW$rincome <- with(CigarettesSW, income / population / cpi) CigarettesSW$tdiff <- with(CigarettesSW, (taxs - tax) / cpi) m1 <- ivreg( log(packs) ~ log(rprice) + log(rincome) | log(rincome) + tdiff + I(tax / cpi), data = CigarettesSW, subset = year == "1995" ) test_that("model_info", { expect_true(model_info(m1)$is_linear) }) test_that("find_predictors", { expect_identical( find_predictors(m1), list( conditional = c("rprice", "rincome"), instruments = c("rincome", "tdiff", "tax", "cpi") ) ) expect_identical( find_predictors(m1, flatten = TRUE), c("rprice", "rincome", "tdiff", "tax", "cpi") ) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_random", { expect_null(find_random(m1)) }) test_that("get_random", { expect_warning(get_random(m1)) }) test_that("find_response", { expect_identical(find_response(m1), "packs") }) test_that("get_response", { expect_equal(get_response(m1), log(CigarettesSW$packs[CigarettesSW$year == "1995"])) }) test_that("get_predictors", { expect_equal( colnames(get_predictors(m1)), c("rprice", "rincome", "tdiff", "tax", "cpi") ) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 48) expect_equal( colnames(get_data(m1)), c("packs", "rprice", "rincome", "tdiff", "tax", "cpi") ) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_equal( find_formula(m1), list( conditional = as.formula("log(packs) ~ log(rprice) + log(rincome)"), instruments = as.formula("~log(rincome) + tdiff + I(tax/cpi)") ) ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "packs", conditional = c("rprice", "rincome"), instruments = c("rincome", "tdiff", "tax", "cpi") ) ) expect_equal( find_variables(m1, flatten = TRUE), c("packs", "rprice", "rincome", "tdiff", "tax", "cpi") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 48) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "log(rprice)", "log(rincome)") ) ) expect_equal(nrow(get_parameters(m1)), 3) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "log(rprice)", "log(rincome)") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "log(packs)", conditional = c("log(rprice)", "log(rincome)"), instruments = c("log(rincome)", "tdiff", "I(tax/cpi)") ) ) expect_equal(nrow(get_parameters(m1)), 3) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "log(rprice)", "log(rincome)") ) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") }) } insight/tests/testthat/test-MCMCglmm.R0000644000176200001440000000505613552364343017433 0ustar liggesusersif (require("testthat") && require("insight") && require("MCMCglmm")) { context("insight, model_info") data(PlodiaPO) m1 <- MCMCglmm( PO ~ plate, random = ~FSfamily, data = PlodiaPO, verbose = FALSE, nitt = 1300, burnin = 300, thin = 1 ) test_that("model_info", { expect_true(model_info(m1)$is_mixed) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = "plate")) expect_identical(find_predictors(m1, flatten = TRUE), "plate") expect_identical( find_predictors(m1, effects = "random"), list(random = "FSfamily") ) }) test_that("find_random", { expect_equal(find_random(m1), list(random = "FSfamily")) }) test_that("get_random", { expect_equal(get_random(m1), data.frame(FSfamily = PlodiaPO$FSfamily)) }) test_that("find_response", { expect_identical(find_response(m1), "PO") }) test_that("get_response", { expect_equal(get_response(m1), PlodiaPO$PO) }) test_that("get_predictors", { expect_equal(colnames(get_predictors(m1)), "plate") }) test_that("link_inverse", { expect_null(link_inverse(m1)) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 511) expect_equal(colnames(get_data(m1)), c("FSfamily", "PO", "plate")) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_equal( find_formula(m1), list( conditional = as.formula("PO ~ plate"), random = as.formula("~FSfamily") ) ) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "PO", conditional = "plate", random = "FSfamily" ) ) expect_equal(find_terms(m1, flatten = TRUE), c("PO", "plate", "FSfamily")) }) test_that("n_obs", { expect_null(n_obs(m1)) }) test_that("linkfun", { expect_null(link_function(m1)) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "plate"), random = "FSfamily" ) ) expect_equal(nrow(get_parameters(m1)), 2) expect_equal(get_parameters(m1)$Parameter, c("(Intercept)", "plate")) expect_equal( get_parameters(m1, effects = "random")$Parameter, "FSfamily" ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_statistic", { expect_null(find_statistic(m1)) }) } insight/tests/testthat/test-gls.R0000644000176200001440000000521213572501701016607 0ustar liggesusersif (require("testthat") && require("insight") && require("nlme")) { data(Ovary) m1 <- gls(follicles ~ sin(2 * pi * Time) + cos(2 * pi * Time), Ovary, correlation = corAR1(form = ~ 1 | Mare) ) test_that("model_info", { expect_true(model_info(m1)$is_linear) }) test_that("find_predictors", { expect_identical( find_predictors(m1), list(conditional = "Time", correlation = "Mare") ) expect_identical(find_predictors(m1, flatten = TRUE), c("Time", "Mare")) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_response", { expect_identical(find_response(m1), "follicles") }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), .2, tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 308) expect_equal(colnames(get_data(m1)), c("Mare", "Time", "follicles")) }) test_that("find_formula", { expect_length(find_formula(m1), 2) expect_equal( find_formula(m1), list( conditional = as.formula("follicles ~ sin(2 * pi * Time) + cos(2 * pi * Time)"), correlation = as.formula("~1 | Mare") ) ) }) test_that("find_terms", { expect_equal( find_terms(m1), list( response = "follicles", conditional = c("sin(2 * pi * Time)", "cos(2 * pi * Time)"), correlation = c("1", "Mare") ) ) expect_equal( find_terms(m1, flatten = TRUE), c( "follicles", "sin(2 * pi * Time)", "cos(2 * pi * Time)", "1", "Mare" ) ) }) test_that("find_variables", { expect_equal( find_variables(m1), list( response = "follicles", conditional = "Time", correlation = "Mare" ) ) expect_equal( find_variables(m1, flatten = TRUE), c("follicles", "Time", "Mare") ) }) test_that("n_obs", { expect_equal(n_obs(m1), 308) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = c("(Intercept)", "sin(2 * pi * Time)", "cos(2 * pi * Time)") ) ) expect_equal(nrow(get_parameters(m1)), 3) expect_equal( get_parameters(m1)$Parameter, c("(Intercept)", "sin(2 * pi * Time)", "cos(2 * pi * Time)") ) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) test_that("find_statistic", { expect_identical(find_statistic(m1), "t-statistic") }) } insight/tests/testthat/test-clean_names.R0000644000176200001440000000724013603567561020305 0ustar liggesusersif (require("testthat") && require("insight")) { context("insight, clean_names") test_that("clean_names", { expect_equal(clean_names(""), "") expect_equal(clean_names("as.factor(test)"), "test") expect_equal(clean_names("log(test)"), "test") expect_equal(clean_names("log(test, base = exp(3))"), "test") expect_equal(clean_names("log(test,base=exp(3))"), "test") expect_equal(clean_names("log(test/10)"), "test") expect_equal(clean_names("log(test^2)"), "test") expect_equal(clean_names("log(log(test))"), "test") expect_equal(clean_names("log(log(test/10))"), "test") expect_equal(clean_names("log(log(test*2))"), "test") expect_equal(clean_names("scale(log(Days1))"), "Days1") expect_equal(clean_names("I(test^2)"), "test") expect_equal(clean_names("I(test/10)"), "test") expect_equal(clean_names("I(test ^ 2)"), "test") expect_equal(clean_names("I(test / 10)"), "test") expect_equal(clean_names("poly(test, 2)"), "test") expect_equal(clean_names("poly(test, degrees = 2)"), "test") expect_equal(clean_names("poly(test, degrees = 2, raw = TRUE)"), "test") expect_equal(clean_names("ns(test)"), "test") expect_equal(clean_names("ns(test, df = 2)"), "test") expect_equal(clean_names("bs(test)"), "test") expect_equal(clean_names("bs(test, df = 2)"), "test") expect_equal(clean_names("offset(test)"), "test") expect_equal(clean_names("offset(log(test))"), "test") expect_equal(clean_names("factor(test)"), "test") expect_equal(clean_names("as.factor(test)"), "test") expect_equal(clean_names("~ 1 | test"), "test") expect_equal(clean_names("~1|test"), "test") expect_equal(clean_names("1 | test"), "test") expect_equal(clean_names("as.factor(Sepal.Length)"), "Sepal.Length") expect_equal(clean_names("log(Sepal.Length)"), "Sepal.Length") expect_equal(clean_names("log(Sepal.Length, base = exp(3))"), "Sepal.Length") expect_equal(clean_names("log(Sepal.Length,base=exp(3))"), "Sepal.Length") expect_equal(clean_names("log(Sepal.Length/10)"), "Sepal.Length") expect_equal(clean_names("log(Sepal.Length^2)"), "Sepal.Length") expect_equal(clean_names("log(log(Sepal.Length))"), "Sepal.Length") expect_equal(clean_names("log(log(Sepal.Length/10))"), "Sepal.Length") expect_equal(clean_names("log(log(Sepal.Length*2))"), "Sepal.Length") expect_equal(clean_names("I(Sepal.Length^2)"), "Sepal.Length") expect_equal(clean_names("I(Sepal.Length/10)"), "Sepal.Length") expect_equal(clean_names("I(Sepal.Length ^ 2)"), "Sepal.Length") expect_equal(clean_names("I(Sepal.Length / 10)"), "Sepal.Length") expect_equal(clean_names("poly(Sepal.Length, 2)"), "Sepal.Length") expect_equal(clean_names("poly(Sepal.Length, degrees = 2)"), "Sepal.Length") expect_equal(clean_names("poly(Sepal.Length, degrees = 2, raw = TRUE)"), "Sepal.Length") expect_equal(clean_names("ns(Sepal.Length)"), "Sepal.Length") expect_equal(clean_names("ns(Sepal.Length, df = 2)"), "Sepal.Length") expect_equal(clean_names("bs(Sepal.Length)"), "Sepal.Length") expect_equal(clean_names("bs(Sepal.Length, df = 2)"), "Sepal.Length") expect_equal(clean_names("offset(Sepal.Length)"), "Sepal.Length") expect_equal(clean_names("offset(log(Sepal.Length))"), "Sepal.Length") expect_equal(clean_names("factor(Sepal.Length)"), "Sepal.Length") expect_equal(clean_names("as.factor(Sepal.Length)"), "Sepal.Length") expect_equal(clean_names("~ 1 | Sepal.Length"), "Sepal.Length") expect_equal(clean_names("~1|Sepal.Length"), "Sepal.Length") expect_equal(clean_names("1 | Sepal.Length"), "Sepal.Length") }) } insight/tests/testthat/test-backticks.R0000644000176200001440000000453513556565021017776 0ustar liggesusersif (require("testthat") && require("insight")) { context("insight, all_models_equal") data(iris) iris$`a m` <- iris$Species iris$`Sepal Width` <- iris$Sepal.Width m <- lm(`Sepal Width` ~ Petal.Length + `a m` * log(Sepal.Length), data = iris) test_that("backticks", { expect_equal( find_parameters(m), list(conditional = c( "(Intercept)", "Petal.Length", "a mversicolor", "a mvirginica", "log(Sepal.Length)", "a mversicolor:log(Sepal.Length)", "a mvirginica:log(Sepal.Length)" )) ) expect_equal( get_parameters(m)$Parameter, c( "(Intercept)", "Petal.Length", "a mversicolor", "a mvirginica", "log(Sepal.Length)", "a mversicolor:log(Sepal.Length)", "a mvirginica:log(Sepal.Length)" ) ) expect_equal( get_statistic(m)$Parameter, c( "(Intercept)", "Petal.Length", "a mversicolor", "a mvirginica", "log(Sepal.Length)", "a mversicolor:log(Sepal.Length)", "a mvirginica:log(Sepal.Length)" ) ) expect_equal( clean_parameters(m)$Parameter, c( "(Intercept)", "Petal.Length", "a mversicolor", "a mvirginica", "log(Sepal.Length)", "a mversicolor:log(Sepal.Length)", "a mvirginica:log(Sepal.Length)" ) ) expect_equal( find_predictors(m), list(conditional = c("Petal.Length", "a m", "Sepal.Length")) ) expect_equal( colnames(get_predictors(m)), c("Petal.Length", "a m", "Sepal.Length") ) expect_equal( find_variables(m), list( response = "Sepal Width", conditional = c("Petal.Length", "a m", "Sepal.Length") ) ) expect_equal( find_terms(m), list( response = "Sepal Width", conditional = c("Petal.Length", "a m", "log(Sepal.Length)") ) ) expect_equal( rownames(get_varcov(m)), c( "(Intercept)", "Petal.Length", "a mversicolor", "a mvirginica", "log(Sepal.Length)", "a mversicolor:log(Sepal.Length)", "a mvirginica:log(Sepal.Length)" ) ) expect_equal( clean_names(m), c("Sepal Width", "Petal.Length", "a m", "Sepal.Length") ) expect_equal(find_response(m), "Sepal Width") expect_equal(get_response(m), iris[["Sepal Width"]]) }) } insight/tests/testthat/test-has_intercept.R0000644000176200001440000000132013531007236020645 0ustar liggesusersif (require("testthat") && require("insight")) { context("insight, has_intercept") library(lme4) data(mtcars) data(sleepstudy) m1 <- lm(mpg ~ 0 + gear, data = mtcars) m2 <- lm(mpg ~ gear, data = mtcars) m3 <- suppressWarnings(lmer(Reaction ~ 0 + Days + (Days | Subject), data = sleepstudy)) m4 <- lmer(Reaction ~ Days + (Days | Subject), data = sleepstudy) m5 <- suppressWarnings(lmer(Reaction ~ 0 + (Days | Subject), data = sleepstudy)) test_that("has_intercept", { expect_true(has_intercept(m2)) expect_false(has_intercept(m1)) expect_true(has_intercept(m4)) expect_false(has_intercept(m3)) expect_false(has_intercept(m5)) }) } insight/tests/testthat/test-gamm.R0000644000176200001440000000571413563552732016764 0ustar liggesusers.runThisTest <- Sys.getenv("RunAllinsightTests") == "yes" if (.runThisTest || Sys.getenv("USER") == "travis") { unloadNamespace("gam") if (require("testthat") && require("insight") && require("mgcv")) { context("insight, model_info") set.seed(0) dat <- gamSim(6, n = 200, scale = .2, dist = "poisson") m1 <- gamm( y ~ s(x0) + s(x1) + s(x2), family = poisson, data = dat, random = list(fac = ~1) ) test_that("model_info", { expect_true(model_info(m1)$is_poisson) }) test_that("clean_names", { expect_equal(clean_names(m1), c("y", "x0", "x1", "x2")) }) test_that("find_predictors", { expect_identical(find_predictors(m1), list(conditional = c("x0", "x1", "x2"))) expect_identical(find_predictors(m1, flatten = TRUE), c("x0", "x1", "x2")) expect_null(find_predictors(m1, effects = "random")) }) test_that("find_response", { expect_identical(find_response(m1), "y") }) test_that("get_response", { expect_equal(get_response(m1), dat$y) }) test_that("link_inverse", { expect_equal(link_inverse(m1)(.2), exp(.2), tolerance = 1e-5) }) test_that("get_data", { expect_equal(nrow(get_data(m1)), 200) expect_equal(colnames(get_data(m1)), c("y", "x0", "x1", "x2", "fac", "g", "g.0", "g.1", "y.0", "Xr.V1", "Xr.V2", "Xr.V3", "Xr.V4", "Xr.V5", "Xr.V6", "Xr.V7", "Xr.V8", "Xr.0.V1", "Xr.0.V2", "Xr.0.V3", "Xr.0.V4", "Xr.0.V5", "Xr.0.V6", "Xr.0.V7", "Xr.0.V8", "Xr.1.V1", "Xr.1.V2", "Xr.1.V3", "Xr.1.V4", "Xr.1.V5", "Xr.1.V6", "Xr.1.V7", "Xr.1.V8", "X.(Intercept)", "X.s(x0)Fx1", "X.s(x1)Fx1", "X.s(x2)Fx1")) }) test_that("find_formula", { expect_length(find_formula(m1), 1) expect_equal( find_formula(m1), list(conditional = as.formula("y ~ s(x0) + s(x1) + s(x2)")) ) }) test_that("find_terms", { expect_equal(find_terms(m1), list(response = "y", conditional = c("s(x0)", "s(x1)", "s(x2)"))) expect_equal(find_terms(m1, flatten = TRUE), c("y", "s(x0)", "s(x1)", "s(x2)")) }) test_that("find_variables", { expect_equal(find_variables(m1), list(response = "y", conditional = c("x0", "x1", "x2"))) expect_equal(find_variables(m1, flatten = TRUE), c("y", "x0", "x1", "x2")) }) test_that("n_obs", { expect_equal(n_obs(m1), 200) }) test_that("linkfun", { expect_false(is.null(link_function(m1))) }) test_that("find_parameters", { expect_equal( find_parameters(m1), list( conditional = "(Intercept)", smooth_terms = c("s(x0)", "s(x1)", "s(x2)") ) ) expect_equal(nrow(get_parameters(m1)), 4) expect_equal(get_parameters(m1)$Parameter, c("(Intercept)", "s(x0)", "s(x1)", "s(x2)")) }) test_that("is_multivariate", { expect_false(is_multivariate(m1)) }) } } insight/tests/testthat.R0000644000176200001440000000036413446526427015064 0ustar liggesuserslibrary(testthat) library(insight) if (length(strsplit(packageDescription("insight")$Version, "\\.")[[1]]) > 3) { Sys.setenv("RunAllinsightTests" = "yes") } else { Sys.setenv("RunAllinsightTests" = "no") } test_check("insight") insight/vignettes/0000755000176200001440000000000013615562370013737 5ustar liggesusersinsight/vignettes/figure3c.png0000644000176200001440000010017713502774207016161 0ustar liggesusersPNG  IHDR !hgsRGBgAMA a pHYs+IDATx^ \UIP`+ = \Aid("} 9 BҗڋH#`Z8 ؈OkpЈ=b*8!}8 vC$;yoYszZU{\ZozF GH $ BTB AHR! @*!H $ dbݺu7l3`+]wޫ.3hE`f zWþ tIa'~0,bg. &~%, ,{gXF4h4șmxSX١Ss2K86ңm _I?D펻+XhQ !AH۹sgp?yfc=~f `ygSl3Ob&ɟ?,?xi0򅛂_c^A=h96f qѶ/țW=K/G ]ӛt<qfi͛7>$ @"۶m ;hCՂ]. _yf|>9ٹ G>3 .+7S T0tƙf qж/(?pf6l;<^r4@Kg>7>8CM؀* {_e`y~ΔЎk[ijTG{tmZ _t7m ̢_Pe>!MTC6W9C#t2ׇ!~nIRn4p0zpjocjrg g愃53ۚ⡽f+hkL qж-zS{^nW $:T=t4 Yh 8 0 Ҵo:X# 4Ӵ|k`J&~WBmm7%`7o6K^! @/(k}7݈hʕat;:YlYp衇TRi,^8rm;VRl+b5*<,;o>є&֌@wР)7+sΊ`)W Z`b9 Z[m^ө~!@o[n],4gyYBO 㨂Շ!!իW7|Y_|,u>SJ**.iwGӮ۔[HS'i Ό\}=i7x4mYS`;99,7*!ڶ6W҆ ;,)q ҥK3@| BҜ^G>d:6D抜A ˅&TX缳3]q-zҶ 1B9BRoRp-I 4uL@5/$cC;j=bv2(H58ʦL!AHʴ7*$< U眏8^]`퇙%dE5#7F{,}7j-_{ @?xi0x)fi22p)uѫޮm;W:_ tK/dJB=G.G TIYCcCdKӱ:?mtluWknq ?~ROUt_y,XNS:uo Re>{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xD%I>@T@nE}}8ŒH;wozKCޒ vd@<=oGbMz<X SQq?p|x3qakU0ϛK7y 0/1 u~O>W{235u=k/7K 0.:P $PT ҩ~*# .2׍kO{6:]uCEߖ L٫ƮƴlT&,on vO2:`3o"w{Y*΢KgT٠ R! @=>{ QH_wbpeFPǃꅠ"MOT AET AET AETAȤ3ZIENDB`insight/vignettes/insight.Rmd0000644000176200001440000003224213614067316016052 0ustar liggesusers--- title: "Getting Started with Accessing Model Information" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{insight} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) if (!requireNamespace("lme4", quietly = TRUE)) { knitr::opts_chunk$set(eval = FALSE) } ``` When fitting any statistical model, there are many useful pieces of information that are simultaneously calculated and stored beyond coefficient estimates and general model fit statistics. Although there exist some generic functions to obtain model information and data, many package-specific modeling functions do not provide such methods to allow users to access such valuable information. **insight** is an R-package that fills this important gap by providing a suite of functions to support almost any model. The goal of **insight**, then, is to provide tools to provide *easy*, *intuitive*, and *consistent* access to information contained in model objects. These tools aid applied research in virtually any field who fit, diagnose, and present statistical models by streamlining access to every aspect of many model objects via consistent syntax and output. Built with non-programmers in mind, **insight** offers a broad toolbox for making model and data information easily accessible. While **insight** offers many useful functions for working with and understanding model objects (discussed below), we suggest users start with `model_info()`, as this function provides a clean and consistent overview of model objects (*e.g.*, functional form of the model, the model family, link function, number of observations, variables included in the specification, etc.). With a clear understanding of the model introduced, users are able to adapt other functions for more nuanced exploration of and interaction with virtually any model object. ## Overview of Core Functions A statistical model is an object describing the relationship between variables. Although there are a lot of *different types* of models, each with their specificities, most of them also share some *common components*. The goal of **insight** is to help you retrieve these components. The `get_*` prefix extracts *values* (or *data*) associated with model-specific objects (e.g., parameters or variables), while the `find_*` prefix *lists* model-specific objects (e.g., priors or predictors). These are powerful families of functions allowing for great flexibility in use, whether at a high, descriptive level (`find_*`) or narrower level of statistical inspection and reporting (`get_*`). We point users to the package documentation or the complementary package website, https://easystats.github.io/insight/, for a detailed list of the arguments associated with each function as well as the returned values from each function. ```{r out.width="100%", echo=FALSE} knitr::include_graphics("insight_design_1.png", dpi = 72) ``` ## Definition of Model Components The functions from **insight** address different components of a model. In an effort to avoid confusion about specific "targets" of each function, in this section we provide a short explanation of **insight**'s definitions of regression model components. ### Data The dataset used to fit the model. ### Parameters Values estimated or learned from data that capture the relationship between variables. In regression models, these are usually referred to as *coefficients*. ### Response and Predictors * **response**: the outcome or response variable (dependent variable) of a regression model. * **predictor**: independent variables of (the _fixed_ part of) a regression model. For mixed models, variables that are only in the _random effects_ part (i.e. grouping factors) of the model are not returned as predictors by default. However, these can be included using additional arguments in the function call, treating predictors are "unique". As such, if a variable appears as a fixed effect and a random slope, it is treated as one (the same) predictor. ```{r out.width="65%", echo=FALSE} knitr::include_graphics("figure3a.png", dpi = 72) ``` ### Variables Any unique variable names that appear in a regression model, e.g., response variable, predictors or random effects. A "variable" only relates to the unique occurrence of a term, or the term name. For instance, the expression `x + poly(x, 2)` has only the variable `x`. ```{r out.width="80%", echo=FALSE} knitr::include_graphics("figure3b.png", dpi = 72) ``` ### Terms Terms themselves consist of variable and factor names separated by operators, or involve arithmetic expressions. For instance, the expression `x + poly(x, 2)` has _one_ variable `x`, but _two_ terms `x` and `poly(x, 2)`. ```{r out.width="80%", echo=FALSE} knitr::include_graphics("figure3c.png", dpi = 72) ``` ### Random Effects * **random slopes**: variables that are specified as random slopes in a mixed effects model. * **random or grouping factors**: variables that are specified as grouping variables in a mixed effects model. ```{r out.width="65%", echo=FALSE} knitr::include_graphics("figure3d.png", dpi = 72) ``` ## Examples *Aren't the predictors, terms, and parameters the same thing?* In some cases, yes. But not in all cases, and sometimes it is useful to have the "bare" variable names (terms), but sometimes it is also useful to have the information about a possible transformation of variables. That is the main reason for having functions that cover similar aspects of a model object (like `find_terms()` and `find_predictors()` or `find_variables()`). Here are some examples that demonstrate the differences of each function: ```{r echo=TRUE,message=FALSE,warning=FALSE} library(insight) library(lme4) data(sleepstudy) sleepstudy$mygrp <- sample(1:5, size = 180, replace = TRUE) sleepstudy$mysubgrp <- NA sleepstudy$Weeks <- sleepstudy$Days / 7 sleepstudy$cat <- as.factor(sample(letters[1:4], nrow(sleepstudy), replace = TRUE)) for (i in 1:5) { filter_group <- sleepstudy$mygrp == i sleepstudy$mysubgrp[filter_group] <- sample(1:30, size = sum(filter_group), replace = TRUE) } model <- lmer( Reaction ~ Days + I(Days^2) + log1p(Weeks) + cat + (1 | mygrp / mysubgrp) + (1 + Days | Subject), data = sleepstudy ) ``` ```{r echo=TRUE,message=FALSE,warning=FALSE} # find the response variable find_response(model) # find all predictors, fixed part by default find_predictors(model) # find random effects, grouping factors only find_random(model) # find random slopes find_random_slopes(model) # find all predictors, including random effects find_predictors(model, effects = "all", component = "all") # find all terms, including response and random effects # this is essentially the same as the previous example plus response find_terms(model) # find all variables, i.e. also quadratic or log-transformed predictors find_variables(model) ``` Finally, there is `find_parameters()`. Parameters are also known as *coefficients*, and `find_parameters()` does exactly that: returns the model coefficients. ```{r echo=TRUE,message=FALSE,warning=FALSE} # find model parameters, i.e. coefficients find_parameters(model) ``` ## Examples of Use Cases in R We now would like to provide examples of use cases of the **insight** package. These examples probably do not cover typical real-world problems, but serve as illustration of the core idea of this package: The unified interface to access model information. **insight** should help both users and package developers in order to reduce the hassle with the many exceptions from various modelling packages when accessing model information. ### Making Predictions at Specific Values of a Term of Interest Say, the goal is to make predictions for a certain term, holding remaining co-variates constant. This is achieved by calling `predict()` and feeding the `newdata`-argument with the values of the term of interest as well as the "constant" values for remaining co-variates. The functions `get_data()` and `find_predictors()` are used to get this information, which then can be used in the call to `predict()`. In this example, we fit a simple linear model, but it could be replaced by (m)any other models, so this approach is "universal" and applies to many different model objects. ``` r library(insight) m <- lm( Sepal.Length ~ Species + Petal.Width + Sepal.Width, data = iris ) dat <- get_data(m) pred <- find_predictors(m, flatten = TRUE) l <- lapply(pred, function(x) { if (is.numeric(dat[[x]])) mean(dat[[x]]) else unique(dat[[x]]) }) names(l) <- pred l <- as.data.frame(l) cbind(l, predictions = predict(m, newdata = l)) #> Species Petal.Width Sepal.Width predictions #> 1 setosa 1.199333 3.057333 5.101427 #> 2 versicolor 1.199333 3.057333 6.089557 #> 3 virginica 1.199333 3.057333 6.339015 ``` ### Printing Model Coefficients The next example should emphasize the possibilities to generalize functions to many different model objects using **insight**. The aim is simply to print coefficients in a complete, human readable sentence. The first approach uses the functions that are available for some, but obviously not for all models, to access the information about model coefficients. ``` r print_params <- function(model){ paste0( "My parameters are ", paste0(row.names(summary(model)$coefficients), collapse = ", "), ", thank you for your attention!" ) } m1 <- lm(Sepal.Length ~ Petal.Width, data = iris) print_params(m1) #> [1] "My parameters are (Intercept), Petal.Width, thank you for your attention!" # obviously, something is missing in the output m2 <- mgcv::gam(Sepal.Length ~ Petal.Width + s(Petal.Length), data = iris) print_params(m2) #> [1] "My parameters are , thank you for your attention!" ``` As we can see, the function fails for *gam*-models. As the access to models depends on the type of the model in the R ecosystem, we would need to create specific functions for all models types. With **insight**, users can write a function without having to worry about the model type. ``` r print_params <- function(model){ paste0( "My parameters are ", paste0(insight::find_parameters(model, flatten = TRUE), collapse = ", "), ", thank you for your attention!" ) } m1 <- lm(Sepal.Length ~ Petal.Width, data = iris) print_params(m1) #> [1] "My parameters are (Intercept), Petal.Width, thank you for your attention!" m2 <- mgcv::gam(Sepal.Length ~ Petal.Width + s(Petal.Length), data = iris) print_params(m2) #> [1] "My parameters are (Intercept), Petal.Width, s(Petal.Length), thank you for your attention!" ``` ## Examples of Use Cases in R packages **insight** is already used by different packages to solve problems that typically occur when the users' inputs are different model objects of varying complexity. For example, [**ggeffects**](https://strengejacke.github.io/ggeffects), a package that computes and visualizes marginal effects of regression models, requires extraction of the data (`get_data()`) that was used to fit the models, and also the retrieval all model predictors (`find_predictors()`) to decide which covariates are held constant when computing marginal effects. All of this information is required in order to create a data frame for `predict(newdata=)`. Furthermore, the models' link-functions (`link_function()`) resp. link-inverse-functions (`link_inverse()`) are required to obtain predictors at the model's response scale. The [**sjPlot**-package](https://strengejacke.github.io/sjPlot/) creates plots or summary tables from regression models, and uses **insight**-functions to get model-information (`model_info()` or `find_response()`), which is used to build the components of the final plot or table. This information helps, for example, in labeling table columns by providing information on the effect type (odds ratio, incidence rate ratio, etc.) or the different model components, which split plots and tables into the "conditional" and "zero-inflated" parts of a model, in the cases of models with zero-inflation. [**bayestestR**](https://easystats.github.io/bayestestR/) mainly relies on `get_priors()` and `get_parameters()` to retrieve the necessary information to compute various indices or statistics of Bayesian models (like HDI, Credible Interval, MCSE, effective sample size, Bayes factors, etc.). The advantage of `get_parameters()` in this context is that regardless of the number of parameters the posterior distribution has, the necessary data can be easily accessed from the model objects. There is no need to write original, complicated code or regular expressions. A last example is the [**performance**-package](https://easystats.github.io/performance/), which provides functions for computing measures to assess model quality. Many of these indices (e.g. check for overdispersion or zero-inflation, predictive accuracy, logloss, RMSE, etc.) require the number of observations (`n_obs()`) or the data from the response-variable (`get_response()`). Again, in this context, functions from **insight** are helpful, because they offer a unified access to this information. insight/vignettes/figure3d.png0000644000176200001440000010314213502774207016155 0ustar liggesusersPNG  IHDRAxsRGBgAMA a pHYs+IDATx^ UW p$"W$FP_)PBE (55L,Y_h6/f͚K:\wu2Rw ֘e( UE ={|rn<_)cܸqۇ;m4o…淀&Ng57oxb("A(eH֮]{f \(@<]]]fi8:kZ3gzW6k)Z=pJE=ǎlPo(EXK/x=Pħ,be P媷C,h8APn:z*Y >S:Tҁ"A*ư Qaw =d" -_ApVSz9A]f7~xSNo'Ol3ą9zD E斛0aqF($ǁqH *{l5|oÆ ޸q۷'**g=N SI;Z9a"llp,Ѓ @/dA5D eD80$z9A_~,!7VxV4Ph*(NP5  9s5hU @&\  .dPy\B@0/씽S6K b g _yAC9,! és E-Zd~5ၔ!;v7}}'?M&@E4߬kf ?{*@1EǓlbNPFA? EoHs"ٲeY+Upj ¤NYfUagCHr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AaB\3LHAaB„8 q%D& (LCPYrHAaB„8 q%D& (LCP1LHAaB„8 q%D& (LCP a.9 P'0!AaB\g! q &EpAP'0!AaB\$d),qa?{+ a"(!=ȐdHwjXۡq0C8r5n?fX]3~j I$c;tHa*n=tHa*n=J-?(○ L zV*s90愊W*PqXPx/5cTǩo 8)A 86#Xܿ ܁mDZ&p0Ck3`i&L~?~<WXIENDB`insight/vignettes/figure3a.png0000644000176200001440000010352413502774207016156 0ustar liggesusersPNG  IHDRYͨ sRGBgAMA a pHYs+IDATx^ Uՙ/UUTQ FШ81h0pĨ $>1iNn4>\qj1-(H4p,G0TEU}jm9k=>.s:{wku""""""""""""""^$""""""""""""""d%""""""""""""" AV"""""""""""""d%""""""""""""" AV"""""""""""""d%""""""""""""" AV"""""""""""""d%""""""""""""" AV"""""""""""""d%""""""""""""" AV"2K.U%"""""hxAD-[5k֨%""qY3fS' "c~ԨQbܸq|(lod%"*Aǂ dyʕ!""""xADdI&۷2|;w,Q>ގu2QA`6lؠ~mʔ)bɒ%jȌD!;eРA1cƈYf" nذa2*8DT9]CXz;vZ""""""} Nz 2fϞM0AXB-mҎs`"Ix|< """"" 8yÀT(8dA# rG AIDDvK; +՜5k'M𴬩'""""" pii?QvЎ3JD5 W°DDDDDDD& J3Y)s̑/7jlj(;㜓WZ% "./G?ΑDDDDDD~(5СC'+vAVN@:2C]f̘!֭[' $ZZZbF75x4F;u 1 / +ë́ Ċ+=?NvAV &N('|:mۦ ^cbO_-Ȋy1QhM4gcפIT7LLȁ0BqČ3_ld%Bj09  Ve&۳OQ][N| R-UIDa&+iT [(K19V+W7 WV8d=~$(a›4"*W^lj`\g7|_46_W5MH%f̶E%ڀ tQMi¨&LPK0ܤ;(I[V8d=~$ϴtSpBU15Q бkڅfQdk[jIeԦN#F/?K/Y`F]۪83_e1Pږ,YJz"'&xK8DdKX/^JDDwyh]rMxuMMDDyu+0=^Ɵ=2uяTxA=fRy XU,hMy$ю3J$3\<Λ7O :T>iNDWr>W=\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fq/*dʴ922h 45~J-Șkw]pn՜~lovMg]JmkPC>"ۮ57OLX.EVڏmmCX C"#2.4߽H-@Uo~][' m"̱r[{Xͷ<6E9MpJضۖY foJ{CV:5"mpֱ%""""YFĵc0J۞|wryk` 4}1kY3`jCVv DuQgP 7/J" HV('WGX 1Vՙ YK&X/]xݪ-t0^rU X='ku5@eNV>=vAt덗^.̫ž|Exy204/D䯪jMݵ͕A*5bp^>=4^xZ Ʃ7a>AD&{}Q:qlman=ܻW6ܤJݐr m?QV8\0yA;u:' \b7ֶstOdsYwtzwCSbȑ/<(J,XYlxG' 8G/Z,_}! ֚VPcǼ}[y@+t- G~* ɋѬ3~P,ؼR-uA}kbZyY- ٷx1gsZـD}m7xfmЄn7/Fa,>ZC*l4|dnF]x g~{X>*]6OA2Q 밧׊'nQ`]ÉŎ/N;#kKYO'cUýN#'Ij?#!q |/ Ҵ?Pwc87O>S:S 亁'^&RGmXn4vhZ@qx%x`|gVWKDDDTd QrHVdVq[ƯU z 3YC7MH-uAV潝b'R<ǙJDDDU&"ru+?WpZJϋ_pD*n}L]fssjTurb ߑ9Y>wfEZϨޞ[{W?`X>qImqh<, b8bd:Ty/DDDD4f/ H8'+0̇E0|pRVX=z1}|((4`GLVGDDAP25+ 0@4`V"""t1JDZ[eQ`jIB&Q4Y,UmNV#"a^K/WKɨt +ykjvLTfR-Dbk9Y9YYerXW1ͺT|A<㜬DD3---⠷TKA d%"""""" DD/> rzefpMlzMmc᳆~ebС/(M Q0,0DDD`,AV"""""""""""""O""""""""""""""AV"""""""""""""d%""""""""""""" AV"""""""""""""d%""""""""""""" AV""""""""""""""߄E6^T,JIENDB`insight/R/0000755000176200001440000000000013615055655012133 5ustar liggesusersinsight/R/find_formula.R0000644000176200001440000006233613613250065014723 0ustar liggesusers#' @title Find model formula #' @name find_formula #' #' @description Returns the formula(s) for the different parts of a model #' (like fixed or random effects, zero-inflated component, ...). #' #' @param ... Currently not used. #' @inheritParams find_predictors #' #' @return A list of formulas that describe the model. For simple models, #' only one list-element, \code{conditional}, is returned. For more complex #' models, the returned list may have following elements: #' \itemize{ #' \item \code{conditional}, the "fixed effects" part from the model. One exception are \code{DirichletRegModel} models from \pkg{DirichletReg}, which has two or three components, depending on \code{model}. #' \item \code{random}, the "random effects" part from the model (or the \code{id} for gee-models and similar) #' \item \code{zero_inflated}, the "fixed effects" part from the zero-inflation component of the model #' \item \code{zero_inflated_random}, the "random effects" part from the zero-inflation component of the model #' \item \code{dispersion}, the dispersion formula #' \item \code{instruments}, for fixed-effects regressions like \code{ivreg}, \code{felm} or \code{plm}, the instrumental variables #' \item \code{cluster}, for fixed-effects regressions like \code{felm}, the cluster specification #' \item \code{correlation}, for models with correlation-component like \code{gls}, the formula that describes the correlation structure #' \item \code{slopes}, for fixed-effects individual-slope models like \code{feis}, the formula for the slope parameters #' \item \code{precision}, for \code{DirichletRegModel} models from \pkg{DirichletReg}, when parametrization (i.e. \code{model}) is \code{"alternative"}. #' } #' #' @note For models of class \code{lme} or \code{gls} the correlation-component #' is only returned, when it is explicitly defined as named argument #' (\code{form}), e.g. \code{corAR1(form = ~1 | Mare)} #' #' @examples #' data(mtcars) #' m <- lm(mpg ~ wt + cyl + vs, data = mtcars) #' find_formula(m) #' @importFrom stats formula terms as.formula #' @export find_formula <- function(x, ...) { UseMethod("find_formula") } # Default method ----------------------------------- #' @export find_formula.default <- function(x, ...) { if (inherits(x, "list") && .obj_has_name(x, "gam")) { x <- x$gam class(x) <- c(class(x), c("glm", "lm")) } tryCatch( { list(conditional = stats::formula(x)) }, error = function(x) { NULL } ) } #' @export find_formula.data.frame <- function(x, ...) { stop("A data frame is no valid object for this function") } #' @export find_formula.aovlist <- function(x, ...) { f <- attr(x, "terms", exact = TRUE) attributes(f) <- NULL list(conditional = f) } # GAM ----------------------------------------------------------- #' @export find_formula.gam <- function(x, ...) { f <- tryCatch( { stats::formula(x) }, error = function(x) { NULL } ) if (!is.null(f)) { if (is.list(f)) { mi <- .gam_family(x) if (!is.null(mi) && mi$family == "ziplss") { # handle formula for zero-inflated models f <- list(conditional = f[[1]], zero_inflated = f[[2]]) } else if (mi$family == "Multivariate normal") { # handle formula for multivariate models r <- lapply(f, function(.i) deparse(.i[[2]])) f <- lapply(f, function(.i) list(conditional = .i)) names(f) <- r attr(f, "is_mv") <- "1" } } else { f <- list(conditional = f) } } f } #' @export find_formula.gamlss <- function(x, ...) { tryCatch( { if (!requireNamespace("lme4", quietly = TRUE)) { stop("To use this function, please install package 'lme4'.") } f.random <- lapply(lme4::findbars(x$mu.formula), function(.x) { f <- .safe_deparse(.x) stats::as.formula(paste0("~", f)) }) if (length(f.random) == 1) { f.random <- f.random[[1]] } .compact_list(list( conditional = stats::as.formula(.get_fixed_effects(x$mu.formula)), random = f.random, sigma = x$sigma.formula, nu = x$nu.formula, tau = x$tau.formula )) }, error = function(x) { NULL } ) } #' @importFrom stats as.formula #' @export find_formula.bamlss <- function(x, ...) { f <- stats::formula(x) .compact_list(list( conditional = stats::as.formula(.safe_deparse(f$mu$formula)), sigma = stats::as.formula(paste0("~", as.character(f$sigma$formula)[3])) )) } #' @export find_formula.gamm <- function(x, ...) { x <- x$gam class(x) <- c(class(x), c("glm", "lm")) NextMethod() } # Other models ---------------------------------------------- #' @export find_formula.gee <- function(x, ...) { tryCatch( { id <- parse(text = .safe_deparse(x$call))[[1]]$id # alternative regex-patterns that also work: # sub(".*id ?= ?(.*?),.*", "\\1", .safe_deparse(x$call), perl = TRUE) # sub(".*\\bid\\s*=\\s*([^,]+).*", "\\1", .safe_deparse(x$call), perl = TRUE) list( conditional = stats::formula(x), random = stats::as.formula(paste0("~", id)) ) }, error = function(x) { NULL } ) } #' @export find_formula.MANOVA <- function(x, ...) { .compact_list(list( conditional = x$input$formula, random = stats::as.formula(paste0("~", x$input$subject)) )) } #' @export find_formula.RM <- find_formula.MANOVA #' @export find_formula.gls <- function(x, ...) { ## TODO this is an intermediate fix to return the correlation variables from gls-objects f_corr <- parse(text = .safe_deparse(x$call$correlation))[[1]]$form l <- tryCatch( { list( conditional = stats::formula(x), correlation = stats::as.formula(f_corr) ) }, error = function(x) { NULL } ) .compact_list(l) } #' @export find_formula.LORgee <- function(x, ...) { tryCatch( { id <- parse(text = .safe_deparse(x$call))[[1]]$id # alternative regex-patterns that also work: # sub(".*id ?= ?(.*?),.*", "\\1", .safe_deparse(x$call), perl = TRUE) # sub(".*\\bid\\s*=\\s*([^,]+).*", "\\1", .safe_deparse(x$call), perl = TRUE) list( conditional = stats::formula(x), random = stats::as.formula(paste0("~", id)) ) }, error = function(x) { NULL } ) } #' @export find_formula.cglm <- function(x, ...) { tryCatch( { id <- parse(text = .safe_deparse(x$call))[[1]]$id # alternative regex-patterns that also work: # sub(".*id ?= ?(.*?),.*", "\\1", .safe_deparse(x$call), perl = TRUE) # sub(".*\\bid\\s*=\\s*([^,]+).*", "\\1", .safe_deparse(x$call), perl = TRUE) list( conditional = stats::formula(x), random = stats::as.formula(paste0("~", id)) ) }, error = function(x) { NULL } ) } # Panel data models --------------------------------------- #' @export find_formula.ivreg <- function(x, ...) { tryCatch( { f <- .safe_deparse(stats::formula(x)) cond <- .trim(substr(f, start = 0, stop = regexpr(pattern = "\\|", f) - 1)) instr <- .trim(substr(f, regexpr(pattern = "\\|", f) + 1, stop = 10000L)) list( conditional = stats::as.formula(cond), instruments = stats::as.formula(paste0("~", instr)) ) }, error = function(x) { NULL } ) } #' @export find_formula.iv_robust <- function(x, ...) { tryCatch( { f <- .safe_deparse(stats::formula(x)) cond <- .trim(gsub("(.*)\\+(\\s)*\\((.*)\\)", "\\1", f)) instr <- .trim(gsub("(.*)\\((.*)\\)", "\\2", f)) list( conditional = stats::as.formula(cond), instruments = stats::as.formula(paste0("~", instr)) ) }, error = function(x) { NULL } ) } #' @export find_formula.plm <- function(x, ...) { tryCatch( { f <- .safe_deparse(stats::formula(x)) bar_pos <- regexpr(pattern = "\\|", f) if (bar_pos == -1) { stop_pos <- nchar(f) + 1 } else { stop_pos <- bar_pos } cond <- .trim(substr(f, start = 0, stop = stop_pos - 1)) instr <- .trim(substr(f, stop_pos + 1, stop = 10000L)) if (.is_empty_string(instr)) { list(conditional = stats::as.formula(cond)) } else { # check if formula starts with dot, and remove it instr <- gsub("(^\\.\\s*)(.*)", "\\2", instr) list( conditional = stats::as.formula(cond), instruments = stats::as.formula(paste0("~", instr)) ) } }, error = function(x) { NULL } ) } #' @export find_formula.felm <- function(x, ...) { f <- .safe_deparse(stats::formula(x)) f_parts <- unlist(strsplit(f, "(? 1) { f.rand <- paste0("~", .trim(f_parts[2])) } else { f.rand <- NULL } if (length(f_parts) > 2) { f.instr <- paste0("~", .trim(f_parts[3])) } else { f.instr <- NULL } if (length(f_parts) > 3) { f.clus <- paste0("~", .trim(f_parts[4])) } else { f.clus <- NULL } .compact_list(list( conditional = stats::as.formula(f.cond), random = stats::as.formula(f.rand), instruments = stats::as.formula(f.instr), cluster = stats::as.formula(f.clus) )) } #' @export find_formula.feglm <- function(x, ...) { f <- .safe_deparse(stats::formula(x)) f_parts <- unlist(strsplit(f, "(? 1) { f.instr <- paste0("~", .trim(f_parts[2])) } else { f.instr <- NULL } if (length(f_parts) > 2) { f.clus <- paste0("~", .trim(f_parts[3])) } else { f.clus <- NULL } .compact_list(list( conditional = stats::as.formula(f.cond), instruments = stats::as.formula(f.instr), cluster = stats::as.formula(f.clus) )) } #' @export find_formula.fixest <- function(x, ...) { f <- .safe_deparse(stats::formula(x)) f_parts <- unlist(strsplit(f, "(? 1) { f.clus <- paste0("~", .trim(f_parts[2])) } else { f.clus <- parse(text = deparse(x$call))[[1]]$fixef if (!is.null(f.clus)) { f.clus <- paste("~", paste(eval(f.clus), collapse = " + ")) } } .compact_list(list( conditional = stats::as.formula(f.cond), cluster = stats::as.formula(f.clus) )) } #' @export find_formula.feis <- function(x, ...) { f <- .safe_deparse(stats::formula(x)) f_parts <- unlist(strsplit(f, "(? 1) { f.slopes <- paste0("~", .trim(f_parts[2])) } else { f.slopes <- NULL } .compact_list(list( conditional = stats::as.formula(f.cond), slopes = stats::as.formula(f.slopes), random = stats::as.formula(paste0("~", id)) )) } #' @export find_formula.wbm <- function(x, ...) { f <- .safe_deparse(stats::formula(x)) f_parts <- unlist(strsplit(f, "(? 1) { f.instr <- paste0("~", .trim(f_parts[2])) } else { f.instr <- NULL } if (length(f_parts) > 2) { f_parts[3] <- .trim(f_parts[3]) if (grepl("\\((.+)\\|(.+)\\)", f_parts[3])) { # we have multiple random effects, which we can better extract # via "lme4::findbars()" if (length(gregexpr("\\|", f_parts[3])[[1]]) > 1) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("To use this function, please install package 'lme4'.") } f.rand <- lme4::findbars(stats::as.formula(paste("~", f_parts[3]))) } else { f.rand <- gsub("(\\(|\\))", "", f_parts[3]) f.rand <- stats::as.formula(paste0("~", .trim(f.rand))) } f.clint <- NULL } else { ## TODO dangerous fix to convert cross-level interactions # into random effects... f.clint <- f_parts[3] f.clint <- paste0("~", .trim(f.clint)) f.rand <- NULL } } else { f.rand <- NULL f.clint <- NULL } .compact_list(list( conditional = stats::as.formula(f.cond), instruments = stats::as.formula(f.instr), interactions = stats::as.formula(f.clint), random = f.rand )) } #' @export find_formula.wbgee <- find_formula.wbm #' @export find_formula.glimML <- function(x, ...) { .compact_list(list( conditional = x@formula, random = x@random )) } #' @export find_formula.tobit <- function(x, ...) { tryCatch( { list(conditional = parse(text = .safe_deparse(x$call))[[1]]$formula) }, error = function(x) { NULL } ) } # Zero inflated models -------------------------------------- #' @export find_formula.hurdle <- function(x, ...) { .zeroinf_formula(x) } #' @export find_formula.zeroinfl <- find_formula.hurdle #' @export find_formula.zerotrunc <- find_formula.hurdle # Ordinal models -------------------------------------- #' @importFrom stats as.formula #' @export find_formula.clmm2 <- function(x, ...) { .compact_list(list( conditional = stats::as.formula(.safe_deparse(attr(x$location, "terms", exact = TRUE))), scale = stats::as.formula(.safe_deparse(attr(x$scale, "terms", exact = TRUE))), random = stats::as.formula(paste0("~", parse(text = .safe_deparse(x$call))[[1]]$random)) )) } #' @importFrom stats formula #' @export find_formula.clm2 <- function(x, ...) { .compact_list(list( conditional = stats::formula(attr(x$location, "terms", exact = TRUE)), scale = stats::formula(attr(x$scale, "terms", exact = TRUE)) )) } #' @export find_formula.DirichletRegModel <- function(x, ...) { f <- .safe_deparse(stats::formula(x)) f_parts <- unlist(strsplit(f, "(? 1) { f.cond2 <- paste0("~", .trim(f_parts[2])) } else { f.cond2 <- NULL } if (length(f_parts) > 2) { f.cond3 <- paste0("~", .trim(f_parts[3])) } else { f.cond3 <- NULL } out <- .compact_list(list( conditional = stats::as.formula(f.cond), conditional2 = stats::as.formula(f.cond2), conditional3 = stats::as.formula(f.cond3) )) if (x$parametrization == "alternative") { if (length(out) == 2) names(out)[2] <- "precision" } out } # Mixed models ----------------------- #' @export find_formula.glmmTMB <- function(x, ...) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("To use this function, please install package 'lme4'.") } f.cond <- stats::formula(x) f.zi <- stats::formula(x, component = "zi") f.disp <- stats::formula(x, component = "disp") if (identical(.safe_deparse(f.zi), "~0") || identical(.safe_deparse(f.zi), "~1")) { f.zi <- NULL } if (identical(.safe_deparse(f.disp), "~0") || identical(.safe_deparse(f.disp), "~1")) { f.disp <- NULL } f.random <- lapply(lme4::findbars(f.cond), function(.x) { f <- .safe_deparse(.x) stats::as.formula(paste0("~", f)) }) if (length(f.random) == 1) { f.random <- f.random[[1]] } f.zirandom <- lapply(lme4::findbars(f.zi), function(.x) { f <- .safe_deparse(.x) if (f == "NULL") { return(NULL) } stats::as.formula(paste0("~", f)) }) if (length(f.zirandom) == 1) { f.zirandom <- f.zirandom[[1]] } f.cond <- stats::as.formula(.get_fixed_effects(f.cond)) if (!is.null(f.zi)) f.zi <- stats::as.formula(.get_fixed_effects(f.zi)) .compact_list(list( conditional = f.cond, random = f.random, zero_inflated = f.zi, zero_inflated_random = f.zirandom, dispersion = f.disp )) } #' @export find_formula.nlmerMod <- function(x, ...) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("To use this function, please install package 'lme4'.") } f.random <- lapply(lme4::findbars(stats::formula(x)), function(.x) { f <- .safe_deparse(.x) stats::as.formula(paste0("~", f)) }) if (length(f.random) == 1) { f.random <- f.random[[1]] } f.cond <- lme4::nobars(stats::as.formula(gsub("(.*)(~)(.*)~(.*)", "\\1\\2\\4", .safe_deparse(stats::formula(x))))) f.nonlin <- stats::as.formula(paste0("~", .trim(gsub("(.*)~(.*)~(.*)", "\\2", .safe_deparse(stats::formula(x)))))) .compact_list(list( conditional = f.cond, nonlinear = f.nonlin, random = f.random )) } #' @export find_formula.merMod <- function(x, ...) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("To use this function, please install package 'lme4'.") } f.cond <- stats::formula(x) f.random <- lapply(lme4::findbars(f.cond), function(.x) { f <- .safe_deparse(.x) stats::as.formula(paste0("~", f)) }) if (length(f.random) == 1) { f.random <- f.random[[1]] } f.cond <- stats::as.formula(.get_fixed_effects(f.cond)) .compact_list(list(conditional = f.cond, random = f.random)) } #' @export find_formula.rlmerMod <- find_formula.merMod #' @export find_formula.cpglmm <- find_formula.merMod #' @export find_formula.glmmadmb <- find_formula.merMod #' @export find_formula.mixed <- find_formula.merMod #' @export find_formula.clmm <- find_formula.merMod #' @export find_formula.cgamm <- find_formula.merMod #' @export find_formula.coxme <- find_formula.merMod #' @export find_formula.lme <- function(x, ...) { fm <- eval(x$call$fixed) fmr <- eval(x$call$random) ## TODO this is an intermediate fix to return the correlation variables from lme-objects fc <- parse(text = .safe_deparse(x$call$correlation))[[1]]$form .compact_list(list( conditional = fm, random = fmr, correlation = stats::as.formula(fc) )) } #' @export find_formula.mixor <- function(x, ...) { fm <- x$call$formula f_id <- deparse(x$call$id) f_rs <- x$call$which.random.slope if (!is.null(f_rs)) { f_rs <- trimws(unlist(strsplit(.safe_deparse(x$call$formula[[3]]), "\\+")))[f_rs] fmr <- paste(f_rs, "|", f_id) } else { fmr <- f_id } fmr <- stats::as.formula(paste("~", fmr)) .compact_list(list( conditional = fm, random = fmr )) } #' @export find_formula.MixMod <- function(x, ...) { f.cond <- stats::formula(x) f.zi <- stats::formula(x, type = "zi_fixed") f.random <- stats::formula(x, type = "random") f.zirandom <- stats::formula(x, type = "zi_random") .compact_list(list( conditional = f.cond, random = f.random, zero_inflated = f.zi, zero_inflated_random = f.zirandom )) } #' @export find_formula.BBmm <- function(x, ...) { f.cond <- parse(text = .safe_deparse(x$call))[[1]]$fixed.formula f.rand <- parse(text = .safe_deparse(x$call))[[1]]$random.formula .compact_list(list( conditional = stats::as.formula(f.cond), random = stats::as.formula(f.rand) )) } #' @export find_formula.mmclogit <- function(x, ...) { tryCatch( { list( conditional = stats::formula(x), random = as.formula(parse(text = .safe_deparse(x$call))[[1]]$random) ) }, error = function(x) { NULL } ) } # Bayesian models -------------------------------- #' @export find_formula.stanreg <- function(x, ...) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("To use this function, please install package 'lme4'.") } f.cond <- stats::formula(x) f.random <- lapply(lme4::findbars(f.cond), function(.x) { f <- .safe_deparse(.x) stats::as.formula(paste0("~", f)) }) if (length(f.random) == 1) { f.random <- f.random[[1]] } f.cond <- stats::as.formula(.get_fixed_effects(f.cond)) .compact_list(list(conditional = f.cond, random = f.random)) } #' @export find_formula.brmsfit <- function(x, ...) { f <- stats::formula(x) if (.obj_has_name(f, "forms")) { mv_formula <- lapply(f$forms, .get_brms_formula) attr(mv_formula, "is_mv") <- "1" mv_formula } else { .get_brms_formula(f) } } #' @export find_formula.stanmvreg <- function(x, ...) { f <- stats::formula(x) mv_formula <- lapply(f, .get_stanmv_formula) attr(mv_formula, "is_mv") <- "1" mv_formula } #' @export find_formula.MCMCglmm <- function(x, ...) { fm <- x$Fixed$formula fmr <- x$Random$formula .compact_list(list(conditional = fm, random = fmr)) } #' @importFrom utils tail #' @export find_formula.BFBayesFactor <- function(x, ...) { if (.classify_BFBayesFactor(x) == "linear") { fcond <- utils::tail(x@numerator, 1)[[1]]@identifier$formula dt <- utils::tail(x@numerator, 1)[[1]]@dataTypes frand <- names(dt)[which(dt == "random")] if (!.is_empty_object(frand)) { f.random <- stats::as.formula(paste0("~", frand)) fcond <- sub(frand, "", fcond, fixed = TRUE) fcond <- gsub("(.*)\\+$", "\\1", .trim(fcond)) f.cond <- stats::as.formula(.trim(fcond)) } else { f.random <- NULL f.cond <- stats::as.formula(fcond) } } else { return(NULL) } .compact_list(list( conditional = f.cond, random = f.random )) } # helper --------------------------- .get_brms_formula <- function(f) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("To use this function, please install package 'lme4'.") } f.cond <- f$formula f.random <- lapply(lme4::findbars(f.cond), function(.x) { fm <- .safe_deparse(.x) stats::as.formula(paste0("~", fm)) }) if (length(f.random) == 1) { f.random <- f.random[[1]] } f.cond <- stats::as.formula(.get_fixed_effects(f.cond)) f.zi <- f$pforms$zi f.zirandom <- NULL if (!.is_empty_object(f.zi)) { f.zirandom <- lapply(lme4::findbars(f.zi), function(.x) { f <- .safe_deparse(.x) stats::as.formula(paste0("~", f)) }) if (length(f.zirandom) == 1) { f.zirandom <- f.zirandom[[1]] } f.zi <- stats::as.formula(paste0("~", .safe_deparse(f.zi[[3L]]))) f.zi <- stats::as.formula(.get_fixed_effects(f.zi)) } .compact_list(list( conditional = f.cond, random = f.random, zero_inflated = f.zi, zero_inflated_random = f.zirandom )) } .get_stanmv_formula <- function(f) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("To use this function, please install package 'lme4'.") } f.cond <- f f.random <- lapply(lme4::findbars(f.cond), function(.x) { fm <- .safe_deparse(.x) stats::as.formula(paste0("~", fm)) }) if (length(f.random) == 1) { f.random <- f.random[[1]] } f.cond <- stats::as.formula(.get_fixed_effects(f.cond)) .compact_list(list( conditional = f.cond, random = f.random )) } # Find formula for zero-inflated regressions, where # zero-inflated part is separated by | from count part .zeroinf_formula <- function(x) { f <- tryCatch( { stats::formula(x) }, error = function(x) { NULL } ) if (is.null(f)) { return(NULL) } f <- .trim(unlist(strsplit(.safe_deparse(f), "\\|"))) c.form <- stats::as.formula(f[1]) if (length(f) == 2) { zi.form <- stats::as.formula(paste0("~", f[2])) } else { zi.form <- NULL } ## TODO could be extended to all find_formula() # fix dot-formulas c.form <- .dot_formula(f = c.form, model = x) # fix dot-formulas zi.form <- tryCatch( { if (as.character(zi.form[2]) == ".") { resp <- .safe_deparse(c.form[2]) pred <- setdiff(colnames(.get_data_from_env(x)), resp) zi.form <- stats::as.formula(paste(resp, "~", paste0(pred, collapse = " + "))) } zi.form }, error = function(e) { zi.form } ) .compact_list(list(conditional = c.form, zero_inflated = zi.form)) } # try to guess "full" formula for dot-abbreviation, e.g. # lm(mpg ~., data = mtcars) .dot_formula <- function(f, model) { # fix dot-formulas tryCatch( { if (as.character(f[[3]])[1] == ".") { resp <- .safe_deparse(f[[2]]) pred <- setdiff(colnames(.get_data_from_env(model)), resp) f <- stats::as.formula(paste(resp, "~", paste0(pred, collapse = " + "))) } f }, error = function(e) { f } ) } insight/R/model_info.R0000644000176200001440000004436713615526334014404 0ustar liggesusers#' @title Access information from model objects #' @name model_info #' #' @description Retrieve information from model objects. #' #' @inheritParams find_predictors #' @inheritParams link_inverse #' @inheritParams find_formula #' #' @return A list with information about the model, like family, link-function #' etc. (see 'Details'). #' #' @details \code{model_info()} returns a list with information about the #' model for many different model objects. Following information #' is returned, where all values starting with \code{is_} are logicals. #' \itemize{ #' \item \code{is_binomial}: family is binomial (but not negative binomial) #' \item \code{is_poisson}: family is poisson #' \item \code{is_negbin}: family is negative binomial #' \item \code{is_count}: model is a count model (i.e. family is either poisson or negative binomial) #' \item \code{is_beta}: family is beta #' \item \code{is_betabinomial}: family is beta-binomial #' \item \code{is_dirichlet}: family is dirichlet #' \item \code{is_exponential}: family is exponential (e.g. Gamma or Weibull) #' \item \code{is_logit}: model has logit link #' \item \code{is_progit}: model has probit link #' \item \code{is_linear}: family is gaussian #' \item \code{is_tweedie}: family is tweedie #' \item \code{is_ordinal}: family is ordinal, multinomial, or cumulative link #' \item \code{is_cumulative}: family is ordinal, multinomial, or cumulative link #' \item \code{is_multinomial}: family is multinomial or categorical link #' \item \code{is_categorical}: family is categorical link #' \item \code{is_censored}: model is a censored model (has a censored response, including survival models) #' \item \code{is_truncated}: model is a truncated model (has a truncated response) #' \item \code{is_survival}: model is a survival model #' \item \code{is_zero_inflated}: model has zero-inflation component #' \item \code{is_hurdle}: model has zero-inflation component and is a hurdle-model (truncated family distribution) #' \item \code{is_mixed}: model is a mixed effects model (with random effects) #' \item \code{is_multivariate}: model is a multivariate response model (currently only works for \emph{brmsfit} objects) #' \item \code{is_trial}: model response contains additional information about the trials #' \item \code{is_bayesian}: model is a Bayesian model #' \item \code{is_anova}: model is an Anova object #' \item \code{link_function}: the link-function #' \item \code{family}: the family-object #' \item \code{n_obs}: number of observations #' \item \code{model_terms}: a list with all model terms, including terms such as random effects or from zero-inflated model parts. #' } #' #' @examples #' ldose <- rep(0:5, 2) #' numdead <- c(1, 4, 9, 13, 18, 20, 0, 2, 6, 10, 12, 16) #' sex <- factor(rep(c("M", "F"), c(6, 6))) #' SF <- cbind(numdead, numalive = 20 - numdead) #' dat <- data.frame(ldose, sex, SF, stringsAsFactors = FALSE) #' m <- glm(SF ~ sex * ldose, family = binomial) #' #' model_info(m) #' \dontrun{ #' library(glmmTMB) #' data("Salamanders") #' m <- glmmTMB( #' count ~ spp + cover + mined + (1 | site), #' ziformula = ~ spp + mined, #' dispformula = ~DOY, #' data = Salamanders, #' family = nbinom2 #' ) #' } #' #' model_info(m) #' @importFrom stats formula terms #' @export model_info <- function(x, ...) { UseMethod("model_info") } # Default methods -------------------------------------- #' @export model_info.data.frame <- function(x, ...) { stop("A data frame is no valid object for this function") } #' @importFrom stats family #' @export model_info.default <- function(x, ...) { if (inherits(x, "list") && .obj_has_name(x, "gam")) { x <- x$gam class(x) <- c(class(x), c("glm", "lm")) } faminfo <- tryCatch( { if (inherits(x, c("Zelig-relogit"))) { stats::binomial(link = "logit") } else { stats::family(x) } }, error = function(x) { NULL } ) if (!is.null(faminfo)) { .make_family( x = x, fitfam = faminfo$family, logit.link = faminfo$link == "logit", link.fun = faminfo$link, ... ) } else { warning("Could not access model information.", call. = FALSE) } } # Models with general handling, Gaussian ---------------------------------- #' @export model_info.mmclogit <- function(x, ...) { .make_family(x, ...) } #' @export model_info.maxLik <- model_info.mmclogit #' @export model_info.censReg <- model_info.mmclogit #' @export model_info.htest <- model_info.mmclogit #' @export model_info.BFBayesFactor <- model_info.mmclogit #' @export model_info.lme <- model_info.mmclogit #' @export model_info.bayesx <- model_info.mmclogit #' @export model_info.rq <- model_info.mmclogit #' @export model_info.crq <- model_info.mmclogit #' @export model_info.crqs <- model_info.mmclogit #' @export model_info.nlrq <- model_info.mmclogit #' @export model_info.rqss <- model_info.mmclogit #' @export model_info.mixed <- model_info.mmclogit #' @export model_info.plm <- model_info.mmclogit #' @export model_info.mcmc <- model_info.mmclogit #' @export model_info.gls <- model_info.mmclogit #' @export model_info.nls <- model_info.mmclogit #' @export model_info.MANOVA <- model_info.mmclogit #' @export model_info.RM <- model_info.mmclogit #' @export model_info.truncreg <- model_info.mmclogit #' @export model_info.lmRob <- model_info.mmclogit #' @export model_info.speedlm <- model_info.mmclogit #' @export model_info.lmrob <- model_info.mmclogit #' @export model_info.complmrob <- model_info.mmclogit #' @export model_info.lm_robust <- model_info.mmclogit #' @export model_info.iv_robust <- model_info.mmclogit #' @export model_info.felm <- model_info.mmclogit #' @export model_info.feis <- model_info.mmclogit #' @export model_info.ivreg <- model_info.mmclogit #' @export model_info.aovlist <- model_info.mmclogit #' @export model_info.rma <- model_info.mmclogit #' @export model_info.mlm <- function(x, ...) { .make_family(x, multi.var = TRUE, ...) } # Models with logit-link -------------------------------- #' @export model_info.logistf <- function(x, ...) { faminfo <- stats::binomial(link = "logit") .make_family( x = x, fitfam = faminfo$family, logit.link = faminfo$link == "logit", link.fun = faminfo$link, ... ) } #' @export model_info.lrm <- model_info.logistf #' @export model_info.multinom <- model_info.logistf #' @export model_info.mlogit <- model_info.logistf #' @export model_info.gmnl <- model_info.logistf # Models with ordinal family ------------------------------------ #' @export model_info.clm <- function(x, ...) { faminfo <- stats::binomial(link = .get_ordinal_link(x)) .make_family( x = x, fitfam = faminfo$family, logit.link = faminfo$link == "logit", link.fun = faminfo$link, ... ) } #' @export model_info.clm2 <- model_info.clm #' @export model_info.clmm <- model_info.clm #' @export model_info.mixor <- model_info.clm # Models with family-function ---------------------------------- #' @importFrom stats family #' @export model_info.bamlss <- function(x, ...) { faminfo <- stats::family(x) .make_family( x = x, fitfam = faminfo$family, logit.link = faminfo$links[1] == "logit", link.fun = faminfo$links[1], ... ) } #' @export model_info.speedglm <- function(x, ...) { faminfo <- stats::family(x) .make_family( x = x, fitfam = faminfo$family, logit.link = faminfo$link == "logit", link.fun = faminfo$link, ... ) } #' @export model_info.brmultinom <- model_info.speedglm # Models with tobit family ---------------------------------- #' @export model_info.flexsurvreg <- function(x, ...) { dist <- parse(text = .safe_deparse(x$call))[[1]]$dist faminfo <- .make_tobit_family(x, dist) .make_family( x = x, fitfam = faminfo$family, logit.link = faminfo$link == "logit", link.fun = faminfo$link, ... ) } #' @export model_info.tobit <- function(x, ...) { faminfo <- .make_tobit_family(x) .make_family( x = x, fitfam = faminfo$family, logit.link = faminfo$link == "logit", link.fun = faminfo$link, ... ) } #' @export model_info.crch <- model_info.tobit #' @export model_info.survreg <- model_info.tobit # Models with family in object ---------------------------------- #' @export model_info.MixMod <- function(x, ...) { faminfo <- x$family .make_family( x = x, fitfam = faminfo$family, logit.link = faminfo$link == "logit", link.fun = faminfo$link, ... ) } #' @export model_info.glmmPQL <- model_info.MixMod #' @export model_info.glmx <- function(x, ...) { faminfo <- x$family$glm .make_family( x = x, fitfam = faminfo$family, logit.link = faminfo$link == "logit", link.fun = faminfo$link, ... ) } #' @export model_info.fixest <- function(x, ...) { faminfo <- x$family if (is.null(faminfo)) { if (!is.null(x$method) && x$method == "feols") { .make_family(x, ...) } } else if (inherits(faminfo, "family")) { .make_family( x = x, fitfam = faminfo$family, logit.link = faminfo$link == "logit", link.fun = faminfo$link, ... ) } else { fitfam <- switch( faminfo, "negbin" = "negative binomial", "logit" = "binomial", faminfo ) link <- switch( faminfo, "poisson" = , "negbin" = "log", "logit" = "logit", "gaussian" = "identity" ) .make_family( x = x, fitfam = fitfam, logit.link = link == "logit", link.fun = link, ... ) } } #' @export model_info.feglm <- model_info.fixest # Survival-models ---------------------------------------- #' @export model_info.coxph <- function(x, ...) { .make_family( x = x, fitfam = "survival", logit.link = TRUE, link.fun = NULL, ... ) } #' @export model_info.aareg <- model_info.coxph #' @export model_info.survfit <- model_info.coxph #' @export model_info.coxme <- model_info.coxph # Zero-Inflated Models ------------------------------ #' @export model_info.zeroinfl <- function(x, ...) { if (is.list(x$dist)) { dist <- x$dist[[1]] } else { dist <- x$dist } fitfam <- switch( dist, poisson = "poisson", negbin = "negative binomial", "poisson" ) .make_family( x = x, fitfam = fitfam, zero.inf = TRUE, link.fun = "log", ... ) } #' @export model_info.zerotrunc <- model_info.zeroinfl #' @export model_info.hurdle <- function(x, ...) { if (is.list(x$dist)) { dist <- x$dist[[1]] } else { dist <- x$dist } fitfam <- switch( dist, poisson = "poisson", negbin = "negative binomial", "poisson" ) .make_family( x = x, fitfam = fitfam, zero.inf = TRUE, hurdle = TRUE, link.fun = "log", ... ) } # Bayesian Models --------------------------- #' @export model_info.brmsfit <- function(x, ...) { faminfo <- stats::family(x) if (is_multivariate(x)) { lapply(faminfo, function(.x) { .make_family( x = x, fitfam = .x$family, zero.inf = FALSE, logit.link = .x$link == "logit", multi.var = TRUE, link.fun = .x$link, ... ) }) } else { .make_family( x = x, fitfam = faminfo$family, logit.link = faminfo$link == "logit", multi.var = FALSE, link.fun = faminfo$link, ... ) } } #' @export model_info.stanmvreg <- function(x, ...) { faminfo <- stats::family(x) lapply(faminfo, function(.x) { .make_family( x = x, fitfam = .x$family, zero.inf = FALSE, logit.link = .x$link == "logit", multi.var = TRUE, link.fun = .x$link, ... ) }) } # Other models ---------------------------- #' @export model_info.cglm <- function(x, ...) { link <- parse(text = .safe_deparse(x$call))[[1]]$link method <- parse(text = .safe_deparse(x$call))[[1]]$method if (!is.null(method) && method == "clm") { .make_family(x, ...) } else if (!is.null(link)) { .make_family( x, logit.link = link == "logit", link.fun = link, ... ) } else { .make_family(x, ...) } } #' @export model_info.cgam <- function(x, ...) { faminfo <- x$family .make_family( x = x, fitfam = faminfo$family, logit.link = faminfo$link == "logit", link.fun = faminfo$link, ... ) } #' @export model_info.gamm <- function(x, ...) { x <- x$gam class(x) <- c(class(x), c("glm", "lm")) NextMethod() } #' @export model_info.LORgee <- function(x, ...) { if (grepl(pattern = "logit", x = x$link, fixed = TRUE)) { link <- "logit" } else if (grepl(pattern = "probit", x = x$link, fixed = TRUE)) { link <- "probit" } else if (grepl(pattern = "cauchit", x = x$link, fixed = TRUE)) { link <- "cauchit" } else if (grepl(pattern = "cloglog", x = x$link, fixed = TRUE)) { link <- "cloglog" } else { link <- "logit" } if (x$link == "Cumulative logit") family <- "ordinal" else family <- "multinomial" .make_family( x = x, fitfam = family, logit.link = link == "logit", link.fun = link, ... ) } #' @export model_info.BBreg <- function(x, ...) { .make_family( x = x, fitfam = "betabinomial", logit.link = TRUE, multi.var = FALSE, zero.inf = FALSE, link.fun = "logit", ... ) } #' @export model_info.BBmm <- model_info.BBreg #' @export model_info.glmmadmb <- function(x, ...) { .make_family( x = x, fitfam = x$family, logit.link = x$link == "logit", multi.var = FALSE, zero.inf = x$zeroInflation, link.fun = x$link, ... ) } #' @export model_info.cpglmm <- function(x, ...) { link <- parse(text = .safe_deparse(x@call))[[1]]$link if (is.numeric(link)) link <- "tweedie" .make_family( x = x, fitfam = "poisson", logit.link = FALSE, multi.var = FALSE, link.fun = link, ... ) } #' @export model_info.cpglm <- model_info.cpglmm #' @export model_info.glimML <- function(x, ...) { fitfam <- switch(x@method, BB = "betabinomial", NB = "negative binomial") .make_family( x = x, fitfam = fitfam, logit.link = x@link == "logit", multi.var = FALSE, zero.inf = FALSE, link.fun = x@link, ... ) } #' @export model_info.gam <- function(x, ...) { if (!inherits(x, c("glm", "lm"))) { class(x) <- c(class(x), "glm", "lm") } faminfo <- .gam_family(x) link <- faminfo$link[1] is.mv <- faminfo$family == "Multivariate normal" if (is.mv) link <- "identity" .make_family( x = x, fitfam = faminfo$family, logit.link = link == "logit", link.fun = link, multi.var = is.mv, ... ) } #' @export model_info.vgam <- function(x, ...) { faminfo <- x@family link.fun <- faminfo@blurb[3] if (grepl("^(l|L)ogit", link.fun)) link.fun <- "logit" .make_family( x = x, fitfam = faminfo@vfamily[1], logit.link = any(.string_contains("logit", faminfo@blurb)), link.fun = link.fun, ... ) } #' @export model_info.vglm <- model_info.vgam #' @export model_info.glmmTMB <- function(x, ...) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("To use this function, please install package 'lme4'.") } faminfo <- stats::family(x) .make_family( x = x, fitfam = faminfo$family, zero.inf = !.is_empty_object(lme4::fixef(x)$zi), hurdle = grepl("truncated", faminfo$family), logit.link = faminfo$link == "logit", link.fun = faminfo$link, ... ) } #' @export model_info.betareg <- function(x, ...) { .make_family( x = x, fitfam = "beta", logit.link = x$link$mean$name == "logit", link.fun = x$link$mean$name, ... ) } #' @export model_info.DirichletRegModel <- function(x, ...) { .make_family( x = x, fitfam = "dirichlet", logit.link = TRUE, link.fun = "logit", ... ) } #' @export model_info.gbm <- function(x, ...) { faminfo <- switch( x$distribution$name, laplace = , tdist = , gaussian = list(name = "gaussian", logit = FALSE, link = NULL), coxph = list(name = "survival", logit = TRUE, link = NULL), poisson = list(name = "poisson", logit = FALSE, link = "log"), huberized = , adaboost = , bernoulli = list(name = "binomial", logit = TRUE, link = "logit"), ) .make_family( x = x, fitfam = faminfo$name, logit.link = faminfo$logit, link.fun = faminfo$link, ... ) } #' @export model_info.MCMCglmm <- function(x, ...) { .make_family( x = x, fitfam = x$Residual$family, logit.link = FALSE, link.fun = "", ... ) } #' @export model_info.polr <- function(x, ...) { link <- x$method if (link == "logistic") link <- "logit" faminfo <- stats::binomial(link = link) .make_family( x = x, fitfam = faminfo$family, logit.link = faminfo$link == "logit", link.fun = faminfo$link, ... ) } #' @export model_info.svyolr <- function(x, ...) { l <- switch(x$method, logistic = "logit", x$method) faminfo <- stats::binomial(link = l) .make_family( x = x, fitfam = faminfo$family, logit.link = faminfo$link == "logit", link.fun = faminfo$link, ... ) } #' @export model_info.gamlss <- function(x, ...) { faminfo <- get(x$family[1], asNamespace("gamlss"))() .make_family( x = x, fitfam = faminfo$family[2], logit.link = faminfo$mu.link == "logit", link.fun = faminfo$mu.link, ... ) } insight/R/find_predictors.R0000644000176200001440000001273013602434030015417 0ustar liggesusers#' @title Find names of model predictors #' @name find_predictors #' #' @description Returns the names of the predictor variables for the #' different parts of a model (like fixed or random effects, zero-inflated #' component, ...). Unlike \code{\link{find_parameters}}, the names from #' \code{find_predictors()} match the original variable names from the data #' that was used to fit the model. #' #' @param x A fitted model. #' @param effects Should variables for fixed effects, random effects #' or both be returned? Only applies to mixed models. May be abbreviated. #' @param component Should all predictor variables, predictor variables for the #' conditional model, the zero-inflated part of the model, the dispersion #' term or the instrumental variables be returned? Applies to models #' with zero-inflated and/or dispersion formula, or to models with instrumental #' variable (so called fixed-effects regressions). May be abbreviated. Note that the #' \emph{conditional} component is also called \emph{count} or \emph{mean} #' component, depending on the model. #' @param flatten Logical, if \code{TRUE}, the values are returned #' as character vector, not as list. Duplicated values are removed. #' #' @return A list of character vectors that represent the name(s) of the #' predictor variables. Depending on the combination of the arguments #' \code{effects} and \code{component}, the returned list has following #' elements: #' \itemize{ #' \item \code{conditional}, the "fixed effects" terms from the model #' \item \code{random}, the "random effects" terms from the model #' \item \code{zero_inflated}, the "fixed effects" terms from the zero-inflation component of the model #' \item \code{zero_inflated_random}, the "random effects" terms from the zero-inflation component of the model #' \item \code{dispersion}, the dispersion terms #' \item \code{instruments}, for fixed-effects regressions like \code{ivreg}, \code{felm} or \code{plm}, the instrumental variables #' \item \code{correlation}, for models with correlation-component like \code{gls}, the variables used to describe the correlation structure #' } #' #' @examples #' data(mtcars) #' m <- lm(mpg ~ wt + cyl + vs, data = mtcars) #' find_predictors(m) #' @export find_predictors <- function(x, effects = c("fixed", "random", "all"), component = c("all", "conditional", "zi", "zero_inflated", "dispersion", "instruments", "correlation", "smooth_terms"), flatten = FALSE) { effects <- match.arg(effects) component <- match.arg(component) f <- find_formula(x) is_mv <- is_multivariate(f) elements <- .get_elements(effects, component) # filter formulas, depending on requested effects and components if (is_mv) { f <- lapply(f, function(.x) .prepare_predictors(x, .x, elements)) } else { f <- .prepare_predictors(x, f, elements) } # random effects are returned as list, so we need to unlist here if (is_mv) { l <- lapply(f, function(.i) .return_vars(.i, x)) } else { l <- .return_vars(f, x) } if (.is_empty_object(l) || .is_empty_object(.compact_list(l))) { return(NULL) } # some models, like spatial models, have random slopes that are not defined # as fixed effect predictor. In such cases, we have to add the random slope term # manually, so other functions like "get_data()" work as expected... if (.obj_has_name(l, "random") && effects == "all") { random_slope <- unname(unlist(find_random_slopes(x))) all_predictors <- unlist(unique(l)) rs_not_in_pred <- unique(setdiff(random_slope, all_predictors)) if (length(rs_not_in_pred)) l$random <- c(rs_not_in_pred, l$random) } if (flatten) { unique(unlist(l)) } else { l } } .return_vars <- function(f, x) { l <- lapply(names(f), function(i) { if (i %in% c("random", "zero_inflated_random")) { unique(paste(unlist(f[[i]]))) } else if (is.numeric(f[[i]])) { f[[i]] } else { if (is.list(f[[i]])) { # this is for multivariate response models, where # we have a list of formulas lapply(f[[i]], function(j) unique(all.vars(j))) } else { unique(all.vars(f[[i]])) } } }) empty_elements <- sapply(l, .is_empty_object) l <- .compact_list(l) # here we handle special cases for non-linear model in brms if (inherits(x, "brmsfit")) { nf <- stats::formula(x) if (!is.null(attr(nf$formula, "nl", exact = TRUE)) && .obj_has_name(nf, "pforms")) { nl_parms <- names(nf$pforms) l <- lapply(l, .remove_values, nl_parms) } } # remove constants l <- lapply(l, .remove_values, c(".", "pi", "1", "0")) l <- lapply(l, .remove_values, c(0, 1)) l <- lapply(l, function(i) gsub("`", "", i, fixed = TRUE)) names(l) <- names(f)[!empty_elements] l } .prepare_predictors <- function(x, f, elements) { f <- f[names(f) %in% elements] # from conditional model, remove response if (.obj_has_name(f, "conditional")) { f[["conditional"]] <- f[["conditional"]][[3]] } # if we have random effects, just return grouping variable, not random slopes if (.obj_has_name(f, "random")) { f[["random"]] <- .get_group_factor(x, f[["random"]]) } # same for zi-random effects if (.obj_has_name(f, "zero_inflated_random")) { f[["zero_inflated_random"]] <- .get_group_factor(x, f[["zero_inflated_random"]]) } f } insight/R/find_response.R0000644000176200001440000000506313613251343015106 0ustar liggesusers#' @title Find name of the response variable #' @name find_response #' #' @description Returns the name(s) of the response variable(s) from a model object. #' #' @param x A fitted model. #' @param combine Logical, if \code{TRUE} and the response is a matrix-column, #' the name of the response matches the notation in formula, and would for #' instance also contain patterns like \code{"cbind(...)"}. Else, the original #' variable names from the matrix-column are returned. See 'Examples'. #' #' @return The name(s) of the response variable(s) from \code{x} as character vector. #' #' @examples #' library(lme4) #' data(cbpp) #' cbpp$trials <- cbpp$size - cbpp$incidence #' m <- glm(cbind(incidence, trials) ~ period, data = cbpp, family = binomial) #' #' find_response(m, combine = TRUE) #' find_response(m, combine = FALSE) #' @export find_response <- function(x, combine = TRUE) { f <- find_formula(x) # this is for multivariate response models, where # we have a list of formulas if (is_multivariate(f)) { resp <- unlist(lapply(f, function(i) .safe_deparse(i$conditional[[2L]]))) } else { resp <- .safe_deparse(f$conditional[[2L]]) } check_cbind(resp, combine, model = x) } # should not be called for brms-models! check_cbind <- function(resp, combine, model) { if (!combine && inherits(model, "DirichletRegModel")) { resp <- model$varnames } else if (!combine && any(grepl("cbind\\((.*)\\)", resp))) { resp <- .extract_combined_response(resp, "cbind") } else if (!combine && any(grepl("Surv\\((.*)\\)", resp))) { resp <- .extract_combined_response(resp, "Surv") } else if (!combine && any(grepl("Curv\\((.*)\\)", resp))) { resp <- .extract_combined_response(resp, "Curv") } else if (!combine && any(grepl("/", resp, fixed = TRUE))) { resp <- strsplit(resp, split = "/", fixed = TRUE) resp <- gsub("(I|\\(|\\))", "", .trim(unlist(resp))) } else if (any(.string_contains("|", resp))) { # check for brms Additional Response Information r1 <- .trim(sub("(.*)\\|(.*)", "\\1", resp)) r2 <- .trim(sub("(.*)\\|(.*)\\(([^,)]*).*", "\\3", resp)) resp <- c(r1, r2) } .remove_pattern_from_names(resp, ignore_asis = TRUE) } .extract_combined_response <- function(resp, pattern) { resp <- sub(sprintf("%s\\(([^,].*)([\\)].*)", pattern), "\\1", resp) resp <- strsplit(resp, split = ",", fixed = TRUE) resp <- .trim(unlist(resp)) if (any(.string_contains("-", resp[2]))) { resp[2] <- .trim(sub("(.*)(\\-)(.*)", "\\1", resp[2])) } resp } insight/R/download_model.R0000644000176200001440000000302713524331052015232 0ustar liggesusers#' @title Download circus models #' @name download_model #' #' @description Downloads pre-compiled models from the \emph{circus}-repository. #' The \emph{circus}-repository contains a variety of fitted models to help #' the systematic testing of other packages #' #' @param name Model name. #' @param url String with the URL from where to download the model data. #' Optional, and should only be used in case the repository-URL is #' changing. By default, models are downloaded from #' \code{https://raw.github.com/easystats/circus/master/data/}. #' #' @return A model from the \emph{circus}-repository. #' #' @details The code that generated the model is available at the #' \url{https://easystats.github.io/circus/reference/index.html}. #' #' @references \url{https://easystats.github.io/circus/} #' #' @export download_model <- function(name, url = NULL) { .download_data_github(name, url) } # Download rda files from github .download_data_github <- function(name, url) { if (!requireNamespace("httr", quietly = TRUE)) { stop("Package `httr` required to download models from the circus-repo.", call. = FALSE) } if (is.null(url)) { url <- "https://raw.github.com/easystats/circus/master/data/" } url <- paste0(url, name, ".rda") temp_file <- tempfile() on.exit(unlink(temp_file)) request <- httr::GET(url) httr::stop_for_status(request) writeBin(httr::content(request, type = "raw"), temp_file) x <- load(temp_file) model <- get(x) rm(x) model } insight/R/utils_get_data.R0000644000176200001440000003517013571247604015252 0ustar liggesusers# Function that does the most work for preparing and transforming the data, # to ensure we have a "clean" data frame from the data that was used to fit # the model. This also means that, unless necessary for further processing, # variables transformed during model fitting are not included in this data frame # #' @importFrom stats getCall formula na.omit .prepare_get_data <- function(x, mf, effects = "fixed") { if (.is_empty_object(mf)) { warning("Could not get model data.", call. = F) return(NULL) } # we may store model weights here later mw <- NULL # do we have an offset, not specified in the formula? if ("(offset)" %in% colnames(mf) && .obj_has_name(x, "call") && .obj_has_name(x$call, "offset")) { offcol <- which(colnames(mf) == "(offset)") colnames(mf)[offcol] <- clean_names(.safe_deparse(x$call$offset)) } # clean 1-dimensional matrices mf[] <- lapply(mf, function(.x) { if (is.matrix(.x) && dim(.x)[2] == 1 && !inherits(.x, c("ns", "bs"))) { as.vector(.x) } else { .x } }) # check if we have any matrix columns, e.g. from splines mc <- sapply(mf, is.matrix) # don't change response value, if it's a matrix # bound with cbind() rn <- find_response(x, combine = TRUE) rn_not_combined <- find_response(x, combine = FALSE) trials.data <- NULL if (mc[1] && rn == colnames(mf)[1]) { mc[1] <- FALSE if (inherits(x, c("coxph", "flexsurvreg", "coxme", "survreg", "survfit", "crq", "psm"))) { mf <- cbind(mf[[1]][, 1], mf[[1]][, 2], mf) colnames(mf)[1:2] <- rn_not_combined } else { tryCatch( { trials.data <- as.data.frame(mf[[1]]) colnames(trials.data) <- rn_not_combined # if columns were bound via substraction, e.g. # "cbind(succes, total - success)", we need to sum up success and # total for the original total-column. pattern <- sprintf("%s(\\s*)-(\\s*)%s", rn_not_combined[2], rn_not_combined[1]) if (grepl(pattern = pattern, x = rn)) { trials.data[[2]] <- trials.data[[1]] + trials.data[[2]] } }, error = function(x) { NULL } ) } } # if we have any matrix columns, we remove them from original # model frame and convert them to regular data frames, give # proper column names and bind them back to the original model frame if (any(mc)) { # try to get model data from environment md <- tryCatch( { eval(stats::getCall(x)$data, environment(stats::formula(x))) }, error = function(x) { NULL } ) # if data not found in environment, reduce matrix variables into regular vectors if (is.null(md)) { # we select the non-matrix variables and convert matrix-variables into # regular data frames, then binding them together mf_matrix <- mf[, which(mc), drop = FALSE] mf_nonmatrix <- mf[, -which(mc), drop = FALSE] # fix for rms::rcs() functions if (any(class(mf_matrix[[1]]) == "rms")) class(mf_matrix[[1]]) <- "matrix" mf_list <- lapply(mf_matrix, as.data.frame, stringsAsFactors = FALSE) mf_matrix <- do.call(cbind, mf_list) mf <- cbind(mf_nonmatrix, mf_matrix) } else { # fix NA in column names if (any(is.na(colnames(md)))) colnames(md) <- make.names(colnames(md)) # get "matrix" terms and "normal" predictors, but exclude # response variable(s) mf_matrix <- mf[, -which(mc), drop = FALSE] spline.term <- clean_names(names(which(mc))) other.terms <- clean_names(colnames(mf_matrix))[-1] # now we have all variable names that we need from the original # data set needed.vars <- c(other.terms, spline.term) # if response is a matrix vector (e.g. multivariate response), # we need to include all response names as well, because else # rows may not match due to additional missings in the response variables if (is.matrix(mf[[1]])) { needed.vars <- c(dimnames(mf[[1]])[[2]], needed.vars) } else { needed.vars <- c(colnames(mf)[1], needed.vars) } # check model weights if ("(weights)" %in% needed.vars && !.obj_has_name(md, "(weights)")) { needed.vars <- needed.vars[-which(needed.vars == "(weights)")] mw <- mf[["(weights)"]] } if (inherits(x, c("coxph", "coxme"))) { mf <- md } else { needed.vars <- unique(clean_names(needed.vars)) mf <- md[, needed.vars, drop = FALSE] # we need this hack to save variable and value label attributes, if any value_labels <- lapply(mf, function(.l) attr(.l, "labels", exact = TRUE)) variable_labels <- lapply(mf, function(.l) attr(.l, "label", exact = TRUE)) # removing NAs drops all label-attributes mf <- stats::na.omit(mf) # then set back attributes mf <- as.data.frame(mapply(function(.d, .l) { attr(.d, "labels") <- .l .d }, mf, value_labels, SIMPLIFY = FALSE), stringsAsFactors = FALSE) mf <- as.data.frame(mapply(function(.d, .l) { attr(.d, "label") <- .l .d }, mf, variable_labels, SIMPLIFY = FALSE), stringsAsFactors = FALSE) } # add back model weights, if any if (!is.null(mw)) mf$`(weights)` <- mw } # check if we really have all formula terms in our model frame now pv <- tryCatch( { find_predictors(x, effects = effects, flatten = TRUE) }, error = function(x) { NULL } ) if (!is.null(pv) && !all(pv %in% colnames(mf))) { warning("Some model terms could not be found in model data. You probably need to load the data into the environment.", call. = FALSE) } } # check if we have monotonic variables, included in formula # with "mo()"? If yes, remove from model frame mos_eisly <- grepl(pattern = "^mo\\(([^,)]*).*", x = colnames(mf)) if (any(mos_eisly)) mf <- mf[!mos_eisly] # clean variable names cvn <- .remove_pattern_from_names(colnames(mf), ignore_lag = TRUE) # keep "as is" variable for response variables in data frame if (colnames(mf)[1] == rn[1] && grepl("^I\\(", rn[1])) { md <- tryCatch( { tmp <- .get_data_from_env(x)[, unique(c(rn_not_combined, cvn)), drop = FALSE] tmp[, rn_not_combined, drop = FALSE] }, error = function(x) { NULL } ) if (!is.null(md)) { mf <- cbind(mf, md) cvn <- .remove_pattern_from_names(colnames(mf), ignore_lag = TRUE) cvn[1] <- rn[1] } } # do we have duplicated names? dupes <- which(duplicated(cvn)) if (!.is_empty_string(dupes)) cvn[dupes] <- sprintf("%s.%s", cvn[dupes], 1:length(dupes)) colnames(mf) <- cvn # add weighting variable weighting_var <- find_weights(x) if (!is.null(weighting_var) && !weighting_var %in% colnames(mf) && length(weighting_var) == 1) { mf <- tryCatch( { tmp <- suppressWarnings(cbind(mf, get_weights(x))) colnames(tmp)[ncol(tmp)] <- weighting_var tmp }, error = function(e) { mf } ) } # add back possible trials-data if (!is.null(trials.data)) { new.cols <- setdiff(colnames(trials.data), colnames(mf)) if (!.is_empty_string(new.cols)) mf <- cbind(mf, trials.data[, new.cols, drop = FALSE]) } mf } # combine data from different model components ------------------------------- # This helper functions ensures that data from different model components # are included in the returned data frame # .return_data <- function(x, mf, effects, component, model.terms, is_mv = FALSE) { response <- unlist(model.terms$response) if (is_mv) { fixed.component.data <- switch( component, all = c( sapply(model.terms[-1], function(i) i$conditional), sapply(model.terms[-1], function(i) i$zero_inflated), sapply(model.terms[-1], function(i) i$dispersion) ), conditional = sapply(model.terms[-1], function(i) i$conditional), zi = , zero_inflated = sapply(model.terms[-1], function(i) i$zero_inflated), dispersion = sapply(model.terms[-1], function(i) i$dispersion) ) random.component.data <- switch( component, all = c( sapply(model.terms[-1], function(i) i$random), sapply(model.terms[-1], function(i) i$zero_inflated_random) ), conditional = sapply(model.terms[-1], function(i) i$random), zi = , zero_inflated = sapply(model.terms[-1], function(i) i$zero_inflated_random) ) fixed.component.data <- unlist(fixed.component.data) random.component.data <- unlist(random.component.data) } else { fixed.component.data <- switch( component, all = c(model.terms$conditional, model.terms$zero_inflated, model.terms$dispersion), conditional = model.terms$conditional, zi = , zero_inflated = model.terms$zero_inflated, dispersion = model.terms$dispersion ) random.component.data <- switch( component, all = c(model.terms$random, model.terms$zero_inflated_random), conditional = model.terms$random, zi = , zero_inflated = model.terms$zero_inflated_random ) } # this is to remove the "1" from intercept-ony-models if (!.is_empty_object(fixed.component.data)) { fixed.component.data <- .remove_values(fixed.component.data, c("1", "0")) fixed.component.data <- .remove_values(fixed.component.data, c(1, 0)) } if (!.is_empty_object(random.component.data)) { random.component.data <- .remove_values(random.component.data, c("1", "0")) random.component.data <- .remove_values(random.component.data, c(1, 0)) } dat <- switch( effects, all = mf[, unique(c(response, fixed.component.data, random.component.data, find_weights(x))), drop = FALSE], fixed = mf[, unique(c(response, fixed.component.data, find_weights(x))), drop = FALSE], random = mf[, unique(random.component.data), drop = FALSE] ) if (.is_empty_object(dat)) { print_color(sprintf("Warning: Data frame is empty, probably component '%s' does not exist in the %s-part of the model?\n", component, effects), "red") return(NULL) } if ("(offset)" %in% colnames(mf) && !("(offset)" %in% colnames(dat))) { dat <- cbind(dat, mf[["(offset"]]) } dat } # find zi-data ----------------------------------- # this function tries to get the data from variables from the zero-inflated # component and adds them to the model frame. Useful if the zi-component # has other variables than the count component. # .add_zeroinf_data <- function(x, mf, tn) { tryCatch( { env_data <- eval(x$call$data, envir = parent.frame())[, tn, drop = FALSE] if (.obj_has_name(x$call, "subset")) { env_data <- subset(env_data, subset = eval(x$call$subset)) } .merge_dataframes(env_data, mf, replace = TRUE) }, error = function(x) { mf } ) } # special model handling ----------------------------------- .get_zelig_relogit_frame <- function(x) { vars <- find_variables(x, flatten = TRUE) x$data[, vars, drop = FALSE] } # combine data from count and zi-component ----------------------------------- .return_zeroinf_data <- function(x, component) { model.terms <- find_variables(x, effects = "all", component = "all", flatten = FALSE) mf <- tryCatch( { stats::model.frame(x) }, error = function(x) { NULL } ) mf <- .prepare_get_data(x, mf) # add variables from other model components mf <- .add_zeroinf_data(x, mf, model.terms$zero_inflated) fixed.data <- switch( component, all = c(model.terms$conditional, model.terms$zero_inflated), conditional = model.terms$conditional, zi = , zero_inflated = model.terms$zero_inflated ) mf[, unique(c(model.terms$response, fixed.data, find_weights(x))), drop = FALSE] } # "clean" model frame and get data ----------------------------------- # here we have a model frame with many variables, so just extract the important ones... # .get_data_from_modelframe <- function(x, dat, effects) { cn <- clean_names(colnames(dat)) ft <- switch( effects, fixed = find_variables(x, effects = "fixed", flatten = TRUE), all = find_variables(x, flatten = TRUE), random = find_random(x, split_nested = TRUE, flatten = TRUE) ) remain <- intersect(c(ft, find_weights(x)), cn) mf <- tryCatch( { dat[, remain, drop = FALSE] }, error = function(x) { dat } ) .prepare_get_data(x, mf, effects) } # find data from the environment ----------------------------------- # return data from a data frame that is in the environment, # and subset the data, if necessary .get_data_from_env <- function(x) { # first try, parent frame dat <- tryCatch( { eval(x$call$data, envir = parent.frame()) }, error = function(e) { NULL } ) if (is.null(dat)) { # second try, global env dat <- tryCatch( { eval(x$call$data, envir = globalenv()) }, error = function(e) { NULL } ) } if (!is.null(dat) && .obj_has_name(x$call, "subset")) { dat <- subset(dat, subset = eval(x$call$subset)) } dat } # find data from the environment, for models with S4 -------------------------- # return data from a data frame that is in the environment, # and subset the data, if necessary .get_S4_data_from_env <- function(x) { # first try, parent frame dat <- tryCatch( { eval(x@call$data, envir = parent.frame()) }, error = function(e) { NULL } ) if (is.null(dat)) { # second try, global env dat <- tryCatch( { eval(x@call$data, envir = globalenv()) }, error = function(e) { NULL } ) } if (!is.null(dat) && .obj_has_name(x@call, "subset")) { dat <- subset(dat, subset = eval(x@call$subset)) } dat } # find start vector of nlmer-models from the environment ----------------------------------- # return data from a data frame that is in the environment, # and subset the data, if necessary .get_startvector_from_env <- function(x) { tryCatch( { sv <- eval(parse(text = .safe_deparse(x@call))[[1]]$start) if (is.list(sv)) sv <- sv[["nlpars"]] names(sv) }, error = function(e) { NULL } ) } insight/R/find_random.R0000644000176200001440000000527513531007236014534 0ustar liggesusers#' @title Find names of random effects #' @name find_random #' #' @description Return the name of the grouping factors from mixed effects models. #' #' @param x A fitted mixed model. #' @param split_nested Logical, if \code{TRUE}, terms from nested random #' effects will be returned as separated elements, not as single string #' with colon. See 'Examples'. #' #' @inheritParams find_predictors #' @inheritParams find_variables #' #' @return A list of character vectors that represent the name(s) of the #' random effects (grouping factors). Depending on the model, the #' returned list has following elements: #' \itemize{ #' \item \code{random}, the "random effects" terms from the conditional part of model #' \item \code{zero_inflated_random}, the "random effects" terms from the zero-inflation component of the model #' } #' #' @examples #' library(lme4) #' data(sleepstudy) #' sleepstudy$mygrp <- sample(1:5, size = 180, replace = TRUE) #' sleepstudy$mysubgrp <- NA #' for (i in 1:5) { #' filter_group <- sleepstudy$mygrp == i #' sleepstudy$mysubgrp[filter_group] <- #' sample(1:30, size = sum(filter_group), replace = TRUE) #' } #' #' m <- lmer( #' Reaction ~ Days + (1 | mygrp / mysubgrp) + (1 | Subject), #' data = sleepstudy #' ) #' #' find_random(m) #' find_random(m, split_nested = TRUE) #' @export find_random <- function(x, split_nested = FALSE, flatten = FALSE) { f <- find_formula(x) if (is_multivariate(x)) { rn <- names(find_response(x)) l <- lapply(rn, function(i) .find_random_effects(x, f[[i]], split_nested)) names(l) <- rn l <- .compact_list(l) } else { l <- .find_random_effects(x, f, split_nested) } if (.is_empty_object(l)) { return(NULL) } if (flatten) { unique(unlist(l)) } else { l } } .find_random_effects <- function(x, f, split_nested) { if (!.obj_has_name(f, "random") && !.obj_has_name(f, "zero_inflated_random")) { return(NULL) } if (.obj_has_name(f, "random")) { if (is.list(f$random)) { r1 <- unique(unlist(lapply(f$random, function(.x) .get_model_random(.x, split_nested, x)))) } else { r1 <- unique(unlist(.get_model_random(f$random, split_nested, x))) } } else { r1 <- NULL } if (.obj_has_name(f, "zero_inflated_random")) { if (is.list(f$zero_inflated_random)) { r2 <- unique(unlist(lapply(f$zero_inflated_random, function(.x) .get_model_random(.x, split_nested, x)))) } else { r2 <- unique(.get_model_random(f$zero_inflated_random, split_nested, x)) } } else { r2 <- NULL } .compact_list(list(random = r1, zero_inflated_random = r2)) } insight/R/print.easystats_check.R0000644000176200001440000000104513545706254016566 0ustar liggesusers#' @export print.easystats_check <- function(x, ...) { # check attributes title <- attr(x, "title") text <- attr(x, "text") color <- attr(x, "color") # no attributes found? check list elements then... if (is.null(title) && is.null(text) && is.null(color)) { if ("title" %in% names(x)) title <- x$title if ("text" %in% names(x)) text <- x$text if ("color" %in% names(x)) color <- x$color } if (!is.null(title)) { print_color(paste0("# ", title, "\n\n"), "blue") } print_color(text, color) } insight/R/clean_parameters.R0000644000176200001440000003444713600731467015573 0ustar liggesusers#' @title Get clean names of model parameters #' @name clean_parameters #' #' @description This function "cleans" names of model parameters by removing #' patterns like \code{"r_"} or \code{"b[]"} (mostly applicable to Stan models) #' and adding columns with information to which group or component parameters #' belong (i.e. fixed or random, count or zero-inflated...) #' \cr \cr #' The main purpose of this function is to easily filter and select model parameters, #' in particular of - but not limited to - posterior samples from Stan models, #' depending on certain characteristics. This might be useful when only selective #' results should be reported or results from all parameters should be filtered #' to return only certain results (see \code{\link{print_parameters}}). #' #' @param x A fitted model. #' @inheritParams find_parameters #' #' @return A data frame with "cleaned" parameter names and information on #' effects, component and group where parameters belong to. To be consistent #' across different models, the returned data frame always has at least four #' columns \code{Parameter}, \code{Effects}, \code{Component} and #' \code{Cleaned_Parameter}. See 'Details'. #' #' @details The \code{Effects} column indicate if a parameter is a \emph{fixed} #' or \emph{random} effect. The \code{Component} can either be \emph{conditional} #' or \emph{zero_inflated}. For models with random effects, the \code{Group} #' column indicates the grouping factor of the random effects. For multivariate #' response models from \pkg{brms} or \pkg{rstanarm}, an additional \emph{Response} #' column is included, to indicate which parameters belong to which response #' formula. Furthermore, \emph{Cleaned_Parameter} column is returned that #' contains "human readable" parameter names (which are mostly identical to #' \code{Parameter}, except for for models from \pkg{brms} or \pkg{rstanarm}, #' or for specific terms like smooth- or spline-terms). #' #' @examples #' \dontrun{ #' library(brms) #' model <- download_model("brms_zi_2") #' clean_parameters(model) #' } #' @export clean_parameters <- function(x, ...) { UseMethod("clean_parameters") } #' @export clean_parameters.default <- function(x, ...) { pars <- find_parameters(x, effects = "all", component = "all", flatten = FALSE) l <- lapply(names(pars), function(i) { eff <- if (grepl("random", i, fixed = TRUE)) { "random" } else { "fixed" } com <- if (grepl("zero_inflated", i, fixed = TRUE)) { "zero_inflated" } else if (grepl("nonlinear", i, fixed = TRUE)) { "nonlinear" } else if (grepl("instruments", i, fixed = TRUE)) { "instruments" } else if (grepl("extra", i, fixed = TRUE)) { "extra" } else if (grepl("scale", i, fixed = TRUE)) { "scale" } else { "conditional" } fun <- if (grepl("smooth", i, fixed = TRUE)) { "smooth" } else { "" } if (eff == "random") { rand_eff <- lapply(names(pars[[i]]), function(j) { data.frame( Parameter = pars[[i]][[j]], Effects = eff, Component = com, Group = j, Function = fun, Cleaned_Parameter = pars[[i]][[j]], stringsAsFactors = FALSE, row.names = NULL ) }) do.call(rbind, rand_eff) } else { data.frame( Parameter = pars[[i]], Effects = eff, Component = com, Group = "", Function = fun, Cleaned_Parameter = pars[[i]], stringsAsFactors = FALSE, row.names = NULL ) } }) out <- .remove_backticks_from_parameter_names(do.call(rbind, l)) out <- .remove_empty_columns_from_pars(out) .fix_random_effect_smooth(x, out) } #' @export clean_parameters.BFBayesFactor <- function(x, ...) { pars <- find_parameters(x, effects = "all", component = "all", flatten = FALSE) l <- lapply(names(pars), function(i) { eff <- if (grepl("random", i, fixed = TRUE)) { "random" } else { "fixed" } com <- if (grepl("extra", i, fixed = TRUE)) { "extra" } else { "conditional" } data.frame( Parameter = pars[[i]], Effects = eff, Component = com, Cleaned_Parameter = pars[[i]], stringsAsFactors = FALSE, row.names = NULL ) }) out <- .remove_backticks_from_parameter_names(do.call(rbind, l)) out <- .remove_empty_columns_from_pars(out) .fix_random_effect_smooth(x, out) } #' @export clean_parameters.wbm <- function(x, ...) { pars <- find_parameters(x, effects = "all", component = "all", flatten = FALSE) l <- lapply(names(pars), function(i) { com <- if (grepl("random", i, fixed = TRUE)) { "interactions" } else if (grepl("instruments", i, fixed = TRUE)) { "instruments" } else { "conditional" } fun <- if (grepl("smooth", i, fixed = TRUE)) { "smooth" } else { "" } data.frame( Parameter = pars[[i]], Effects = "fixed", Component = com, Group = "", Function = fun, Cleaned_Parameter = clean_names(pars[[i]]), stringsAsFactors = FALSE, row.names = NULL ) }) out <- .remove_backticks_from_parameter_names(do.call(rbind, l)) out <- .remove_empty_columns_from_pars(out) .fix_random_effect_smooth(x, out) } #' @export clean_parameters.wbgee <- clean_parameters.wbm #' @export clean_parameters.lavaan <- function(x, ...) { params <- get_parameters(x) data.frame( Parameter = params$Parameter, Component = params$Component, Group = "", Function = "", Cleaned_Parameter = params$Parameter, stringsAsFactors = FALSE, row.names = NULL ) } #' @export clean_parameters.blavaan <- function(x, ...) { params <- get_parameters.lavaan(x) data.frame( Parameter = params$Parameter, Component = params$Component, Group = "", Function = "", Cleaned_Parameter = params$Parameter, stringsAsFactors = FALSE, row.names = NULL ) } #' @export clean_parameters.brmsfit <- function(x, ...) { pars <- find_parameters(x, effects = "all", component = "all", flatten = FALSE) is_mv <- is_multivariate(pars) if (is_mv) { l <- do.call( rbind, lapply(names(pars), function(i) .get_stan_params(pars[[i]], response = i)) ) } else { l <- .get_stan_params(pars) } out <- do.call(rbind, l) out <- .remove_empty_columns_from_pars(.clean_brms_params(out, is_mv)) .fix_random_effect_smooth(x, out) } #' @export clean_parameters.stanreg <- function(x, ...) { pars <- find_parameters(x, effects = "all", component = "all", flatten = FALSE) l <- .get_stan_params(pars) out <- do.call(rbind, l) out <- .remove_empty_columns_from_pars(.clean_stanreg_params(out)) .fix_random_effect_smooth(x, out) } #' @export clean_parameters.stanmvreg <- function(x, ...) { pars <- find_parameters(x, effects = "all", component = "all", flatten = FALSE) l <- do.call( rbind, lapply(names(pars), function(i) .get_stan_params(pars[[i]], response = i)) ) out <- do.call(rbind, l) out <- .remove_empty_columns_from_pars(.clean_stanreg_params(out)) .fix_random_effect_smooth(x, out) } .get_stan_params <- function(pars, response = NA) { lapply(names(pars), function(i) { eff <- if (grepl("random", i, fixed = TRUE)) { "random" } else { "fixed" } com <- if (grepl("zero_inflated", i, fixed = TRUE)) { "zero_inflated" } else if (grepl("sigma", i, fixed = TRUE)) { "sigma" } else if (grepl("priors", i, fixed = TRUE)) { "priors" } else { "conditional" } fun <- if (grepl("smooth", i, fixed = TRUE)) { "smooth" } else { "" } data.frame( Parameter = pars[[i]], Effects = eff, Component = com, Group = "", Response = response, Function = fun, stringsAsFactors = FALSE, row.names = NULL ) }) } .clean_brms_params <- function(out, is_mv) { out$Cleaned_Parameter <- out$Parameter # for multivariate response models, remove responses from parameter names if (is_mv) { resp <- unique(out$Response) resp_pattern <- sprintf("_%s_(.*)", resp, resp) for (i in resp_pattern) { out$Cleaned_Parameter <- gsub(pattern = i, "_\\1", out$Cleaned_Parameter, perl = TRUE) } resp_pattern <- sprintf("__%s(.*)", resp, resp) for (i in resp_pattern) { out$Cleaned_Parameter <- gsub(pattern = i, "\\1", out$Cleaned_Parameter, perl = TRUE) } resp_pattern <- sprintf("__zi_%s(.*)", resp, resp) for (i in resp_pattern) { out$Cleaned_Parameter <- gsub(pattern = i, "\\1", out$Cleaned_Parameter, perl = TRUE) } resp_pattern <- sprintf("(sigma)(_%s)", resp, resp) for (i in resp_pattern) { out$Cleaned_Parameter <- gsub(pattern = i, "\\1", out$Cleaned_Parameter, perl = TRUE) } } smooth_function <- grepl(pattern = "(bs_|bs_zi_)", out$Cleaned_Parameter) if (any(smooth_function)) { out$Function[smooth_function] <- "smooth" } # clean fixed effects, conditional and zero-inflated out$Cleaned_Parameter <- gsub(pattern = "(b_|bs_|bsp_|bcs_)(?!zi_)(.*)", "\\2", out$Cleaned_Parameter, perl = TRUE) out$Cleaned_Parameter <- gsub(pattern = "(b_zi_|bs_zi_|bsp_zi_|bcs_zi_)(.*)", "\\2", out$Cleaned_Parameter, perl = TRUE) # correlation and sd cor_sd <- grepl("(sd_|cor_)(.*)", out$Cleaned_Parameter) if (any(cor_sd)) { out$Cleaned_Parameter[cor_sd] <- gsub("(sd_|cor_)(.*)__(.*)", "\\2_\\3", out$Cleaned_Parameter[cor_sd]) out$Group[cor_sd] <- "SD/Cor" } # extract group-names from random effects and clean random effects rand_eff <- grepl("r_(.*)\\.(.*)\\.", out$Cleaned_Parameter) if (any(rand_eff)) { r_pars <- gsub("r_(.*)\\.(.*)\\.", "\\1", out$Cleaned_Parameter[rand_eff]) r_grps <- gsub("r_(.*)\\.(.*)\\.", "\\2", out$Cleaned_Parameter[rand_eff]) r_pars <- gsub("__zi", "", r_pars) r_grps <- sprintf("%s: %s", r_grps, gsub("(.*)\\.(.*)", "\\1", r_pars)) out$Cleaned_Parameter[rand_eff] <- r_pars out$Group[rand_eff] <- r_grps } # clean remaining parameters priors <- grepl("^prior_", out$Cleaned_Parameter) if (length(priors)) { out$Cleaned_Parameter <- gsub("^prior_", "", out$Cleaned_Parameter) out$Component[priors] <- "priors" } simplex <- grepl("^simo_", out$Cleaned_Parameter) if (length(simplex)) { out$Cleaned_Parameter <- gsub("^simo_", "", out$Cleaned_Parameter) out$Component[simplex] <- "simplex" } smooth <- grepl("^sds_", out$Cleaned_Parameter) if (length(smooth)) { out$Cleaned_Parameter <- gsub("^sds_", "", out$Cleaned_Parameter) out$Component[smooth] <- "smooth_sd" out$Function[smooth] <- "smooth" } # fix intercept names intercepts <- which(out$Cleaned_Parameter == "Intercept") if (!.is_empty_object(intercepts)) { out$Cleaned_Parameter[intercepts] <- "(Intercept)" } interaction_terms <- which(grepl("\\.", out$Cleaned_Parameter)) if (length(interaction_terms)) { for (i in interaction_terms) { i_terms <- strsplit(out$Cleaned_Parameter[i], "\\.") find_i_terms <- sapply(i_terms, function(j) j %in% out$Cleaned_Parameter) if (all(find_i_terms)) { out$Cleaned_Parameter[i] <- gsub("\\.", ":", out$Cleaned_Parameter[i]) } } } out } .clean_stanreg_params <- function(out) { out$Cleaned_Parameter <- out$Parameter # extract group-names from random effects and clean random effects rand_intercepts <- grepl("^b\\[\\(Intercept\\)", out$Cleaned_Parameter) if (any(rand_intercepts)) { re_grp_level <- gsub("b\\[(.*) (.*):(.*)\\]", "\\2", out$Cleaned_Parameter[rand_intercepts]) out$Cleaned_Parameter[rand_intercepts] <- gsub( "b\\[\\(Intercept\\) (.*)\\]", "\\1", out$Cleaned_Parameter[rand_intercepts] ) out$Group[rand_intercepts] <- sprintf("Intercept: %s", re_grp_level) } # extract group-names from random effects and clean random effects rand_effects <- grepl("^b\\[", out$Cleaned_Parameter) if (any(rand_effects)) { re_grp_level <- gsub("b\\[(.*) (.*):(.*)\\]", "\\2", out$Cleaned_Parameter[rand_effects]) r_grps <- gsub("b\\[(.*) (.*)\\]", "\\1", out$Cleaned_Parameter[rand_effects]) r_pars <- gsub("b\\[(.*) (.*)\\]", "\\2", out$Cleaned_Parameter[rand_effects]) out$Group[rand_effects] <- sprintf("%s: %s", r_grps, re_grp_level) out$Cleaned_Parameter[rand_effects] <- r_pars } # clean remaining parameters smooth <- grepl("^smooth_sd\\[", out$Cleaned_Parameter) if (length(smooth)) { out$Cleaned_Parameter <- gsub("^smooth_sd\\[(.*)\\]", "\\1", out$Cleaned_Parameter) out$Component[smooth] <- "smooth_sd" out$Function[smooth] <- "smooth" } out } .remove_empty_columns_from_pars <- function(x) { if (.obj_has_name(x, "Response") && all(is.na(x$Response))) { pos <- which(colnames(x) == "Response") x <- x[, -pos] } if (.obj_has_name(x, "Group") && .is_empty_string(x$Group)) { pos <- which(colnames(x) == "Group") x <- x[, -pos] } if (.obj_has_name(x, "Function") && .is_empty_string(x$Function)) { pos <- which(colnames(x) == "Function") x <- x[, -pos] } x } # Fix random effects assignment for smooth terms # # This function checks whether smooth terms were used as random effects, # (i.e. s(term, by="re")) and if so, the value in the "effecs" column will # be set to "random". # .fix_random_effect_smooth <- function(x, out) { if ("Function" %in% colnames(out) && "smooth" %in% out$Function) { vars <- find_terms(x)$conditional vars <- gsub(" ", "", vars, fixed = TRUE) random_smooth_terms <- grepl("^s\\((.*)(bs=\"re\"+)\\)", x = vars) if (any(random_smooth_terms)) { random_term <- paste0( "s(", gsub("^s\\(([^,]*)(.*)(bs=\"re\"+)\\)", "\\1", vars[random_smooth_terms]), ")" ) out$Effects[which(out$Parameter == random_term)] <- "random" } } class(out) <- c("clean_parameters", class(out)) out } insight/R/print_color.R0000644000176200001440000000171113525034155014600 0ustar liggesusers#' @title Coloured console output #' @name print_color #' #' @description Convenient function that allows coloured output in the console. #' Mainly implemented to reduce package dependencies. #' #' @param text The text to print. #' @param color,colour Character vector, indicating the colour for printing. #' May be one of \code{"red"}, \code{"yellow"}, \code{"green"}, \code{"blue"}, #' \code{"violet"}, \code{"cyan"} or \code{"grey"}. Formatting is also possible #' with \code{"bold"} or \code{"italic"}. #' #' @details This function prints \code{text} directly to the console using #' \code{cat()}, so no string is returned. #' #' @return Nothing. #' #' @examples #' print_color("I'm blue dabedi dabedei", "blue") #' @export print_color <- function(text, color) { cat(.colour(colour = color, x = text)) } #' @rdname print_color #' @export print_colour <- function(text, colour) { print_color(color = colour, text = text) } insight/R/format_ci.R0000644000176200001440000000502013602361500014177 0ustar liggesusers#' Confidence/Credible Interval (CI) Formatting #' #' @param CI_low Lower CI bound. #' @param CI_high Upper CI bound. #' @param ci CI level in percentage. #' @param digits Number of significant digits. #' @param brackets Logical, if \code{TRUE} (default), values are encompassed in square brackets. #' @param width Minimum width of the returned string. If not \code{NULL} and \code{width} is larger than the string's length, leading whitespaces are added to the string. If \code{width="auto"}, width will be set to the length of the longest string. #' @param width_low,width_high Like \code{width}, but only applies to the lower or higher confidence interval value. This can be used when the values for the lower and upper CI are of very different length. #' #' @return A formatted string. #' @examples #' format_ci(1.20, 3.57, ci = 0.90) #' format_ci(1.20, 3.57, ci = NULL) #' format_ci(1.20, 3.57, ci = NULL, brackets = FALSE) #' format_ci(c(1.205645, 23.4), c(3.57, -1.35), ci = 0.90) #' format_ci(c(1.20, NA, NA), c(3.57, -1.35, NA), ci = 0.90) #' #' # automatic alignment of width, useful for printing multiple CIs in columns #' x <- format_ci(c(1.205, 23.4, 100.43), c(3.57, -13.35, 9.4)) #' cat(x, sep = "\n") #' #' x <- format_ci(c(1.205, 23.4, 100.43), c(3.57, -13.35, 9.4), width = "auto") #' cat(x, sep = "\n") #' @export format_ci <- function(CI_low, CI_high, ci = 0.95, digits = 2, brackets = TRUE, width = NULL, width_low = width, width_high = width) { if (!is.null(width) && width == "auto") { width_low <- max(unlist(lapply(stats::na.omit(round(CI_low, digits)), function(.i) nchar(as.character(.i))))) width_high <- max(unlist(lapply(stats::na.omit(round(CI_high, digits)), function(.i) nchar(as.character(.i))))) } if (!is.null(ci)) { ifelse(is.na(CI_low) & is.na(CI_high), "", paste0(ci * 100, "% CI ", .format_ci(CI_low, CI_high, digits = digits, brackets = brackets, width_low = width_low, width_high = width_high))) } else { ifelse(is.na(CI_low) & is.na(CI_high), "", .format_ci(CI_low, CI_high, digits = digits, brackets = brackets, width_low = width_low, width_high = width_high)) } } #' @keywords internal .format_ci <- function(CI_low, CI_high, digits = 2, brackets = TRUE, width_low = NULL, width_high = NULL) { paste0( ifelse(isTRUE(brackets), "[", ""), format_value(CI_low, digits = digits, missing = "NA", width = width_low), ", ", format_value(CI_high, digits = digits, missing = "NA", width = width_high), ifelse(isTRUE(brackets), "]", "") ) } insight/R/find_variables.R0000644000176200001440000000520213602434003015205 0ustar liggesusers#' @title Find names of all variables #' @name find_variables #' #' @description Returns a list with the names of all variables, including #' response value and random effects. #' #' @inheritParams find_predictors #' #' @note The difference to \code{\link{find_terms}} is that \code{find_variables()} #' returns each variable name only once, while \code{find_terms()} may return a #' variable multiple times in case of transformations or when arithmetic expressions #' were used in the formula. #' #' @return A list with (depending on the model) following elements (character #' vectors): #' \itemize{ #' \item \code{response}, the name of the response variable #' \item \code{conditional}, the names of the predictor variables from the \emph{conditional} model (as opposed to the zero-inflated part of a model) #' \item \code{random}, the names of the random effects (grouping factors) #' \item \code{zero_inflated}, the names of the predictor variables from the \emph{zero-inflated} part of the model #' \item \code{zero_inflated_random}, the names of the random effects (grouping factors) #' \item \code{dispersion}, the name of the dispersion terms #' \item \code{instruments}, the names of instrumental variables #' } #' #' @examples #' library(lme4) #' data(cbpp) #' data(sleepstudy) #' # some data preparation... #' cbpp$trials <- cbpp$size - cbpp$incidence #' sleepstudy$mygrp <- sample(1:5, size = 180, replace = TRUE) #' sleepstudy$mysubgrp <- NA #' for (i in 1:5) { #' filter_group <- sleepstudy$mygrp == i #' sleepstudy$mysubgrp[filter_group] <- #' sample(1:30, size = sum(filter_group), replace = TRUE) #' } #' #' m1 <- glmer( #' cbind(incidence, size - incidence) ~ period + (1 | herd), #' data = cbpp, #' family = binomial #' ) #' find_variables(m1) #' #' m2 <- lmer( #' Reaction ~ Days + (1 | mygrp / mysubgrp) + (1 | Subject), #' data = sleepstudy #' ) #' find_variables(m2) #' find_variables(m2, flatten = TRUE) #' @export find_variables <- function(x, effects = c("all", "fixed", "random"), component = c("all", "conditional", "zi", "zero_inflated", "dispersion", "instruments", "smooth_terms"), flatten = FALSE) { effects <- match.arg(effects) component <- match.arg(component) if (component %in% c("all", "conditional")) { resp <- find_response(x, combine = FALSE) } else { resp <- NULL } pr <- find_predictors(x, effects = effects, component = component, flatten = flatten) if (flatten) { unique(c(resp, pr)) } else if (is.null(resp)) { pr } else { c(list(response = resp), pr) } } insight/R/get_weights.R0000644000176200001440000000276013554405404014565 0ustar liggesusers#' @title Get the values from model weights #' @name get_weights #' #' @description Returns weighting variable of a model. #' #' @param x A fitted model. #' @param ... Currently not used. #' #' @return The weighting variable, or \code{NULL} if no weights were specified. #' #' @examples #' data(mtcars) #' mtcars$weight <- rnorm(nrow(mtcars), 1, .3) #' m <- lm(mpg ~ wt + cyl + vs, data = mtcars, weights = weight) #' get_weights(m) #' @export get_weights <- function(x, ...) { UseMethod("get_weights") } #' @export get_weights.default <- function(x, ...) { w <- NULL tryCatch( { w <- stats::weights(x) }, error = function(x) { NULL }, warning = function(x) { NULL }, finally = function(x) { NULL } ) if (is.null(w)) { tryCatch( { w <- stats::model.frame(x)[["(weights)"]] }, error = function(x) { NULL }, warning = function(x) { NULL }, finally = function(x) { NULL } ) } if (is.null(w)) { tryCatch( { w <- .get_data_from_env(x)[[find_weights(x)]] }, error = function(x) { NULL }, warning = function(x) { NULL }, finally = function(x) { NULL } ) } w } #' @export get_weights.brmsfit <- function(x, ...) { w <- find_weights(x) if (!is.null(w)) { get_data(x)[[w]] } } insight/R/find_statistic.R0000644000176200001440000001456713613304073015267 0ustar liggesusers#' @title Find statistic for model #' @description Returns the statistic for a regression model (\emph{t}-statistic, #' \emph{z}-statistic, etc.). #' @name find_statistic #' #' @description Small helper that checks if a model is a regression model #' object and return the statistic used. #' #' @param x An object. #' @param ... Currently not used. #' #' @return A character describing the type of statistic. If there is no #' statistic available with a distribution, \code{NULL} will be returned. #' #' @examples #' # regression model object #' data(mtcars) #' m <- lm(mpg ~ wt + cyl + vs, data = mtcars) #' find_statistic(m) #' @export find_statistic <- function(x, ...) { # model object check -------------------------------------------------------- # check if the object is a model object; if so, quit early if (!isTRUE(is_model(x))) { stop(message("The entered object is not a model object."), call. = FALSE) } # t-value objects ---------------------------------------------------------- t.mods <- c( "BBreg", "BBmm", "bcplm", "biglm", "bglmerMod", "blmerMod", "cch", "censReg", "coeftest", "complmrob", "cpglm", "cpglmm", "crq", "drc", "feis", "felm", "gamlss", "garch", "glmmPQL", "gls", "gmm", "ivreg", "iv_robust", "lm", "lm_robust", "lm.beta", "lme", "lmerMod", "lmRob", "lmrob", "maxLik", "mixed", "mlm", "multinom", "nlmerMod", "nlrq", "nls", "orcutt", "polr", "rlm", "rlmerMod", "rq", "rqss", "speedlm", "svyglm", "svyolr", "truncreg", "wbm", "wblm", "zcpglm" ) # z-value objects ---------------------------------------------------------- z.mods <- c( "aareg", "betareg", "bracl", "brglm", "brglmFit", "brmultinom", "cglm", "clm", "clm2", "clmm", "clmm2", "coxme", "coxph", "crch", "DirichletRegModel", "ergm", "feglm", "fixest", "flexsurvreg", "gee", "glimML", "glmmadmb", "glmmLasso", "glmmTMB", "glmx", "gmnl", "hurdle", "lavaan", "loggammacenslmrob", "LORgee", "lrm", "mixor", "MixMod", "mjoint", "mle2", "mlogit", "mclogit", "mmclogit", "mvmeta", "negbin", "nlreg", "objectiveML", "psm", "rma", "rma.uni", "sem", "slm", "survreg", "tobit", "vglm", "wbgee", "zeroinfl", "zerotrunc" ) # F-value objects ---------------------------------------------------------- f.mods <- c( "Anova.mlm", "aov", "aovlist", "anova", "Gam", "manova" ) # chi-squared value objects ------------------------------------------------ chi.mods <- c( "geeglm", "logistf", "MANOVA", "RM", "vgam" ) # mixed bag ---------------------------------------------------------------- # models for which there is no clear t-or z-statistic # which statistic to use will be decided based on the family used g.mods <- c( "bigglm", "cgam", "cgamm", "gam", "glm", "glmc", "glmerMod", "glmRob", "glmrob", "speedglm" ) # t-statistic g.t.mods <- c( "quasi", "gaussian", "quasibinomial", "quasipoisson", "Gamma", "inverse.gaussian" ) # z-statistic g.z.mods <- c( "binomial", "poisson" ) # pattern finding ---------------------------------------------------------- unclear.mods <- c("plm") # no statistic ------------------------------------------------------------- unsupported.mods <- c( "BFBayesFactor", "brmsfit", "stanreg", "stanmvreg", "gbm", "list", "MCMCglmm", "survfit" ) # edge cases --------------------------------------------------------------- # tweedie-check needs to come first, because glm can also have tweedie # family, so this exception needs to be caught before checking for g.mods tryCatch( { suppressWarnings( if (!is_multivariate(x) && model_info(x)$is_tweedie) { return("t-statistic") } ) }, error = function(e) {} ) # statistic check ----------------------------------------------------------- if (class(x)[[1]] %in% unsupported.mods) { return(NULL) } if (class(x)[[1]] %in% t.mods) { return("t-statistic") } if (class(x)[[1]] %in% z.mods) { return("z-statistic") } if (class(x)[[1]] %in% f.mods) { return("F-statistic") } if (class(x)[[1]] %in% chi.mods) { return("chi-squared statistic") } if (class(x)[[1]] %in% g.mods) { if (model_info(x)$family %in% g.t.mods) { return("t-statistic") } else { return("z-statistic") } } # ambiguous cases ----------------------------------------------------------- if (class(x)[[1]] %in% unclear.mods) { col_names <- colnames(as.data.frame(summary(x)$coefficients)) t_names <- c( "t", "t-value", "t value", "t.value", "Pr(>|t|)" ) z_names <- c( "z", "z-value", "z value", "z.value", "Pr(>|z|)", "Pr(>|Z|)", "Naive z", "Robust z", "san.z", "Wald Z" ) f_names <- c("F", "F-value", "F value", "F.value") chi_names <- c("Chisq", "chi-sq", "chi.sq", "Wald", "W", "Pr(>|W|)") if (length(colnames(as.data.frame(summary(x)$coefficients))) == 0L) { return(NULL) } if (any(t_names %in% col_names)) { return("t-statistic") } if (any(z_names %in% col_names)) { return("z-statistic") } if (any(f_names %in% col_names)) { return("F-statistic") } if (any(chi_names %in% col_names)) { return("chi-squared statistic") } } } insight/R/find_terms.R0000644000176200001440000000632313554630176014413 0ustar liggesusers#' @title Find all model terms #' @name find_terms #' #' @description Returns a list with the names of all terms, including #' response value and random effects, "as is". This means, on-the-fly #' tranformations or arithmetic expressions like \code{log()}, \code{I()}, #' \code{as.factor()} etc. are preserved. #' #' @inheritParams find_formula #' @inheritParams find_predictors #' #' @return A list with (depending on the model) following elements (character #' vectors): #' \itemize{ #' \item \code{response}, the name of the response variable #' \item \code{conditional}, the names of the predictor variables from the \emph{conditional} model (as opposed to the zero-inflated part of a model) #' \item \code{random}, the names of the random effects (grouping factors) #' \item \code{zero_inflated}, the names of the predictor variables from the \emph{zero-inflated} part of the model #' \item \code{zero_inflated_random}, the names of the random effects (grouping factors) #' \item \code{dispersion}, the name of the dispersion terms #' \item \code{instruments}, the names of instrumental variables #' } #' #' @note The difference to \code{\link{find_variables}} is that \code{find_terms()} #' may return a variable multiple times in case of multiple transformations #' (see examples below), while \code{find_variables()} returns each variable #' name only once. #' #' @examples #' library(lme4) #' data(sleepstudy) #' m <- lmer( #' log(Reaction) ~ Days + I(Days^2) + (1 + Days + exp(Days) | Subject), #' data = sleepstudy #' ) #' #' find_terms(m) #' @export find_terms <- function(x, flatten = FALSE, ...) { f <- find_formula(x) if (is_multivariate(f)) { l <- lapply(f, .get_variables_list) } else { l <- .get_variables_list(f) } if (flatten) { unique(unlist(l)) } else { l } } .get_variables_list <- function(f) { f$response <- .safe_deparse(f$conditional[[2L]]) f$conditional <- .safe_deparse(f$conditional[[3L]]) f <- lapply(f, function(.x) { if (is.list(.x)) { .x <- sapply(.x, .formula_to_string) } else { if (!is.character(.x)) .x <- .safe_deparse(.x) } .x }) f <- lapply(f, function(.x) { f_parts <- gsub("~", "", .trim(unlist(strsplit(split = "[\\*\\+\\:\\-\\|](?![^(]*\\))", x = .x, perl = TRUE)))) # if user has used namespace in formula-functions, these are returned # as empty elements. rempove those here if (any(nchar(f_parts) == 0)) { f_parts <- f_parts[-which(nchar(f_parts) == 0)] } .remove_backticks_from_string(unique(f_parts)) }) # remove "1" and "0" from variables in random effects if (.obj_has_name(f, "random")) { pos <- which(f$random %in% c("1", "0")) if (length(pos)) f$random <- f$random[-pos] } if (.obj_has_name(f, "zero_inflated_random")) { pos <- which(f$zero_inflated_random %in% c("1", "0")) if (length(pos)) f$zero_inflated_random <- f$zero_inflated_random[-pos] } # reorder, so response is first .compact_list(f[c(length(f), 1:(length(f) - 1))]) } .formula_to_string <- function(f) { if (!is.character(f)) f <- .safe_deparse(f) f } insight/R/get_variances.R0000644000176200001440000002310513602213234015052 0ustar liggesusers#' @title Get variance components from random effects models #' @name get_variance #' #' @description This function extracts the different variance components of a #' mixed model and returns the result as list. Functions like #' \code{get_variance_residual(x)} or \code{get_variance_fixed(x)} are shortcuts #' for \code{get_variance(x, component = "residual")} etc. #' #' @param x A mixed effects model. #' @param component Character value, indicating the variance component that should #' be returned. By default, all variance components are returned. The #' distribution-specific (\code{"distribution"}) and residual (\code{"residual"}) #' variance are the most computational intensive components, and hence may #' take a few seconds to calculate. #' @param verbose Toggle off warnings. #' @param ... Currently not used. #' #' @return A list with following elements: #' \itemize{ #' \item \code{var.fixed}, variance attributable to the fixed effects #' \item \code{var.random}, (mean) variance of random effects #' \item \code{var.residual}, residual variance (sum of dispersion and distribution) #' \item \code{var.distribution}, distribution-specific variance #' \item \code{var.dispersion}, variance due to additive dispersion #' \item \code{var.intercept}, the random-intercept-variance, or between-subject-variance (\ifelse{html}{\out{τ00}}{\eqn{\tau_{00}}}) #' \item \code{var.slope}, the random-slope-variance (\ifelse{html}{\out{τ11}}{\eqn{\tau_{11}}}) #' \item \code{cor.slope_intercept}, the random-slope-intercept-correlation (\ifelse{html}{\out{ρ01}}{\eqn{\rho_{01}}}) #' } #' #' @details This function returns different variance components from mixed models, #' which are needed, for instance, to calculate r-squared measures or the #' intraclass-correlation coefficient (ICC). #' \subsection{Fixed effects variance}{ #' The fixed effects variance, \ifelse{html}{\out{σ2f}}{\eqn{\sigma^2_f}}, #' is the variance of the matrix-multiplication \ifelse{html}{\out{β∗X}}{\eqn{\beta*X}} #' (parameter vector by model matrix). #' } #' \subsection{Random effects variance}{ #' The random effect variance, \ifelse{html}{\out{σ2i}}{\eqn{\sigma^2_i}}, #' represents the \emph{mean} random effect variance of the model. Since #' this variance reflect the "average" random effects variance for mixed #' models, it is also appropriate for models with more complex random #' effects structures, like random slopes or nested random effects. #' Details can be found in \cite{Johnson 2014}, in particular equation 10. #' For simple random-intercept models, the random effects variance equals #' the random-intercept variance. #' } #' \subsection{Distribution-specific variance}{ #' The distribution-specific variance, #' \ifelse{html}{\out{σ2d}}{\eqn{\sigma^2_d}}, #' depends on the model family. For Gaussian models, it is #' \ifelse{html}{\out{σ2}}{\eqn{\sigma^2}} (i.e. #' \code{sigma(model)^2}). For models with binary outcome, it is #' \eqn{\pi^2 / 3} for logit-link and \code{1} for probit-link. For all #' other models, the distribution-specific variance is based on lognormal #' approximation, \eqn{log(1 + var(x) / \mu^2)} (see \cite{Nakagawa et al. 2017}). #' The expected variance of a zero-inflated model is computed according #' to \cite{Zuur et al. 2012, p277}. #' } #' \subsection{Variance for the additive overdispersion term}{ #' The variance for the additive overdispersion term, #' \ifelse{html}{\out{σ2e}}{\eqn{\sigma^2_e}}, #' represents \dQuote{the excess variation relative to what is expected #' from a certain distribution} (Nakagawa et al. 2017). In (most? many?) #' cases, this will be \code{0}. #' } #' \subsection{Residual variance}{ #' The residual variance, \ifelse{html}{\out{σ2ε}}{\eqn{\sigma^2_\epsilon}}, #' is simply \ifelse{html}{\out{σ2d + σ2e}}{\eqn{\sigma^2_d + \sigma^2_e}}. #' } #' \subsection{Random intercept variance}{ #' The random intercept variance, or \emph{between-subject} variance #' (\ifelse{html}{\out{τ00}}{\eqn{\tau_{00}}}), #' is obtained from \code{VarCorr()}. It indicates how much groups #' or subjects differ from each other, while the residual variance #' \ifelse{html}{\out{σ2ε}}{\eqn{\sigma^2_\epsilon}} #' indicates the \emph{within-subject variance}. #' } #' \subsection{Random slope variance}{ #' The random slope variance (\ifelse{html}{\out{τ11}}{\eqn{\tau_{11}}}) #' is obtained from \code{VarCorr()}. This measure is only available #' for mixed models with random slopes. #' } #' \subsection{Random slope-intercept correlation}{ #' The random slope-intercept correlation #' (\ifelse{html}{\out{ρ01}}{\eqn{\rho_{01}}}) #' is obtained from \code{VarCorr()}. This measure is only available #' for mixed models with random intercepts and slopes. #' } #' #' @note This function supports models of class \code{merMod} (including models #' from \pkg{blme}), \code{clmm}, \code{cpglmm}, \code{glmmadmb}, \code{glmmTMB}, #' \code{MixMod}, \code{lme}, \code{mixed}, \code{rlmerMod}, \code{stanreg} or #' \code{wbm}. Support for objects of class \code{MixMod} (\pkg{GLMMadaptiv}) or #' \code{lme} (\pkg{nlme}) is experimental and may not work for all models. #' #' @references \itemize{ #' \item Johnson, P. C. D. (2014). Extension of Nakagawa & Schielzeth’s R2 GLMM to random slopes models. Methods in Ecology and Evolution, 5(9), 944–946. \doi{10.1111/2041-210X.12225} #' \item Nakagawa, S., Johnson, P. C. D., & Schielzeth, H. (2017). The coefficient of determination R2 and intra-class correlation coefficient from generalized linear mixed-effects models revisited and expanded. Journal of The Royal Society Interface, 14(134), 20170213. \doi{10.1098/rsif.2017.0213} #' \item Zuur, A. F., Savel'ev, A. A., & Ieno, E. N. (2012). Zero inflated models and generalized linear mixed models with R. Newburgh, United Kingdom: Highland Statistics. #' } #' #' @examples #' \dontrun{ #' library(lme4) #' data(sleepstudy) #' m <- lmer(Reaction ~ Days + (1 + Days | Subject), data = sleepstudy) #' #' get_variance(m) #' get_variance_fixed(m) #' get_variance_residual(m) #' } #' @export get_variance <- function(x, component = c("all", "fixed", "random", "residual", "distribution", "dispersion", "intercept", "slope", "rho01"), verbose = TRUE, ...) { UseMethod("get_variance") } #' @export get_variance.default <- function(x, component = c("all", "fixed", "random", "residual", "distribution", "dispersion", "intercept", "slope", "rho01"), verbose = TRUE, ...) { warning(sprintf("Objects of class `%s` are not supported.", class(x)[1])) NULL } #' @export get_variance.merMod <- function(x, component = c("all", "fixed", "random", "residual", "distribution", "dispersion", "intercept", "slope", "rho01"), verbose = TRUE, ...) { component <- match.arg(component) tryCatch( { .compute_variances(x, component = component, name_fun = "get_variance", name_full = "random effect variances", verbose = verbose) }, error = function(e) { NULL } ) } #' @export get_variance.rlmerMod <- get_variance.merMod #' @export get_variance.cpglmm <- get_variance.merMod #' @export get_variance.glmmTMB <- get_variance.merMod #' @export get_variance.glmmadmb <- get_variance.merMod #' @export get_variance.stanreg <- get_variance.merMod #' @export get_variance.MixMod <- get_variance.merMod #' @export get_variance.clmm <- get_variance.merMod #' @export get_variance.wbm <- get_variance.merMod #' @export get_variance.wblm <- get_variance.merMod #' @export get_variance.lme <- get_variance.merMod #' @export get_variance.mixed <- function(x, component = c("all", "fixed", "random", "residual", "distribution", "dispersion", "intercept", "slope", "rho01"), verbose = TRUE, ...) { component <- match.arg(component) .compute_variances(x$full_model, component = component, name_fun = "get_variance", name_full = "random effect variances", verbose = verbose) } #' @rdname get_variance #' @export get_variance_residual <- function(x, ...) { unlist(get_variance(x, component = "residual", ...)) } #' @rdname get_variance #' @export get_variance_fixed <- function(x, ...) { unlist(get_variance(x, component = "fixed", ...)) } #' @rdname get_variance #' @export get_variance_random <- function(x, ...) { unlist(get_variance(x, component = "random", ...)) } #' @rdname get_variance #' @export get_variance_distribution <- function(x, ...) { unlist(get_variance(x, component = "distribution", ...)) } #' @rdname get_variance #' @export get_variance_dispersion <- function(x, ...) { unlist(get_variance(x, component = "dispersion", ...)) } #' @rdname get_variance #' @export get_variance_intercept <- function(x, ...) { unlist(get_variance(x, component = "intercept", ...)) } #' @rdname get_variance #' @export get_variance_slope <- function(x, ...) { unlist(get_variance(x, component = "slope", ...)) } #' @rdname get_variance #' @export get_correlation_slope_intercept <- function(x, ...) { unlist(get_variance(x, component = "rho01", ...)) } insight/R/format_value.R0000644000176200001440000001000613615554702014734 0ustar liggesusers#' Numeric Values Formatting #' #' @param x Numeric value. #' @param digits Number of significant digits. #' @param protect_integers Should integers be kept as integers (i.e., without decimals)? #' @param missing Value by which \code{NA} values are replaced. By default, an empty string (i.e. \code{""}) is returned for \code{NA}. #' @param width Minimum width of the returned string. If not \code{NULL} and \code{width} is larger than the string's length, leading whitespaces are added to the string. #' @param as_percent Logical, if \code{TRUE}, value is formatted as percentage value. #' @param ... Arguments passed to or from other methods. #' #' #' @return A formatted string. #' #' @examples #' format_value(1.20) #' format_value(1.2) #' format_value(1.2012313) #' format_value(c(0.0045, 234, -23)) #' format_value(c(0.0045, .12, .34)) #' format_value(c(0.0045, .12, .34), as_percent = TRUE) #' #' format_value(as.factor(c("A", "B", "A"))) #' format_value(iris$Species) #' #' format_value(3) #' format_value(3, protect_integers = TRUE) #' #' format_value(iris) #' @export format_value <- function(x, digits = 2, protect_integers = FALSE, missing = "", width = NULL, as_percent = FALSE, ...) { UseMethod("format_value") } #' @export format_value.data.frame <- function(x, digits = 2, protect_integers = FALSE, missing = "", width = NULL, as_percent = FALSE, ...) { as.data.frame(sapply(x, format_value, digits = digits, protect_integers = protect_integers, missing = missing, width = width, as_percent = as_percent, simplify = FALSE)) } #' @export format_value.numeric <- function(x, digits = 2, protect_integers = FALSE, missing = "", width = NULL, as_percent = FALSE, ...) { if (protect_integers) { out <- .format_value_unless_integer(x, digits = digits, .missing = missing, .width = width, .as_percent = as_percent, ...) } else { out <- .format_value(x, digits = digits, .missing = missing, .width = width, .as_percent = as_percent, ...) } # Deal with negative zeros if (!is.factor(x)) { whitespace <- ifelse(is.null(width), "", " ") out[out == "-0"] <- paste0(whitespace, "0") out[out == "-0.0"] <- paste0(whitespace, "0.0") out[out == "-0.00"] <- paste0(whitespace, "0.00") out[out == "-0.000"] <- paste0(whitespace, "0.000") out[out == "-0.0000"] <- paste0(whitespace, "0.0000") } out } #' @export format_value.double <- format_value.numeric #' @export format_value.character <- format_value.numeric #' @export format_value.factor <- format_value.numeric #' @export format_value.logical <- format_value.numeric #' @importFrom stats na.omit .format_value_unless_integer <- function(x, digits = 2, .missing = "", .width = NULL, .as_percent = FALSE, ...) { if (is.numeric(x) && !all(.is.int(stats::na.omit(x)))) { .format_value(x, digits = digits, .missing = .missing, .width = .width, .as_percent = .as_percent) } else if (anyNA(x)) { .convert_missing(x, .missing) } else { as.character(x) } } .format_value <- function(x, digits = 2, .missing = "", .width = NULL, .as_percent = FALSE, ...) { if (is.numeric(x)) { if (isTRUE(.as_percent)) { x <- ifelse(is.na(x), .missing, ifelse(x > 1e+5, sprintf("%.5e", x), sprintf("%.*f%%", digits, 100 * x))) } else { x <- ifelse(is.na(x), .missing, ifelse(x > 1e+5, sprintf("%.5e", x), sprintf("%.*f", digits, x))) } } else if (anyNA(x)) { x <- .convert_missing(x, .missing) } if (!is.null(.width)) { x <- format(x, justify = "right", width = .width) } x } .convert_missing <- function(x, .missing) { if (length(x) == 1) { return(as.character(.missing)) } missings <- which(is.na(x)) x[missings] <- as.character(.missing) x[!missings] <- as.character(x) x } .is.int <- function(x) { tryCatch( expr = { ifelse(is.infinite(x), FALSE, x %% 1 == 0) }, warning = function(w) { is.integer(x) }, error = function(e) { FALSE } ) } insight/R/get_priors.R0000644000176200001440000002035513615512325014430 0ustar liggesusers#' @title Get summary of priors used for a model #' @name get_priors #' #' @description Provides a summary of the prior distributions used #' for the parameters in a given model. #' #' @param x A Bayesian model. #' @param ... Currently not used. #' #' @return A data frame with a summary of the prior distributions used #' for the parameters in a given model. #' #' @examples #' \dontrun{ #' library(rstanarm) #' model <- stan_glm(Sepal.Width ~ Species * Petal.Length, data = iris) #' get_priors(model) #' } #' #' @export get_priors <- function(x, ...) { UseMethod("get_priors") } #' @export get_priors.stanreg <- function(x, ...) { if (!requireNamespace("rstanarm", quietly = TRUE)) { stop("To use this function, please install package 'rstanarm'.") } ps <- rstanarm::prior_summary(x) l <- .compact_list(lapply(ps[c("prior_intercept", "prior")], function(.x) { if (!is.null(.x)) { # quick and dirty fix for flat priors # else, .compact_list() will set this item as "NA" if (is.na(.x$dist)) { .x$dist <- "uniform" .x$location <- 0 .x$scale <- 0 .x$adjusted_scale <- 0 } do.call(cbind, .x) } })) if (length(l) > 1) { prior_info <- Reduce(function(x, y) merge(x, y, all = TRUE, sort = FALSE), l) } else { cn <- colnames(l[[1]]) prior_info <- as.data.frame(l) colnames(prior_info) <- cn } # fix parameters for flat priors here flat <- which(prior_info$dist == "uniform") if (length(flat) > 0) { prior_info$location[flat] <- NA prior_info$scale[flat] <- NA prior_info$adjusted_scale[flat] <- NA } prior_info$parameter <- find_parameters(x)$conditional prior_info <- prior_info[, intersect(c("parameter", "dist", "location", "scale", "adjusted_scale"), colnames(prior_info))] colnames(prior_info) <- gsub("dist", "distribution", colnames(prior_info)) colnames(prior_info) <- gsub("df", "DoF", colnames(prior_info)) priors <- as.data.frame(lapply(prior_info, function(x) { if (.is_numeric_character(x)) { as.numeric(as.character(x)) } else { as.character(x) } }), stringsAsFactors = FALSE) string <- strsplit(names(priors), "_", fixed = TRUE) string <- lapply(string, .capitalize) names(priors) <- unlist(lapply(string, paste0, collapse = "_")) priors } #' @export get_priors.stanmvreg <- function(x, ...) { if (!requireNamespace("rstanarm", quietly = TRUE)) { stop("To use this function, please install package 'rstanarm'.") } ps <- rstanarm::prior_summary(x) l <- .compact_list(lapply(ps[c("prior_intercept", "prior")], function(.x) { lapply(.x, function(.i) { if (!is.null(.i)) do.call(cbind, .i) }) })) prior_info <- do.call(rbind, lapply(l, function(.x) { if (length(.x) > 1) { out <- lapply(names(.x), function(.i) { if (!("adjusted_scale" %in% colnames(.x[[.i]]))) .x[[.i]] <- cbind(.x[[.i]], adjusted_scale = NA) data.frame(.x[[.i]], response = .i, stringsAsFactors = FALSE) }) do.call(rbind, out) } else { cn <- colnames(.x[[1]]) prior_info <- as.data.frame(.x) colnames(prior_info) <- cn } })) # find parameter names params <- unlist(lapply(find_parameters(x), function(.i) .i$conditional)) params <- params[c(which(params == "(Intercept)"), which(params != "(Intercept)"))] prior_info$parameter <- params prior_info <- prior_info[, intersect(c("parameter", "dist", "location", "scale", "adjusted_scale", "response"), colnames(prior_info))] colnames(prior_info) <- gsub("dist", "distribution", colnames(prior_info)) colnames(prior_info) <- gsub("df", "DoF", colnames(prior_info)) priors <- as.data.frame(lapply(prior_info, function(x) { if (.is_numeric_character(x)) { as.numeric(as.character(x)) } else { as.character(x) } }), stringsAsFactors = FALSE) string <- strsplit(names(priors), "_", fixed = TRUE) string <- lapply(string, .capitalize) names(priors) <- unlist(lapply(string, paste0, collapse = "_")) # minor fixes priors$Parameter <- sprintf("%s|%s", priors$Response, priors$Parameter) priors } #' @export get_priors.brmsfit <- function(x, ...) { ## TODO needs testing for edge cases - check if "coef"-column is # always empty for intercept-class x$prior$coef[x$prior$class == "Intercept"] <- "(Intercept)" # get default prior for all parameters, if defined def_prior_b <- which(x$prior$prior != "" & x$prior$class == "b" & x$prior$coef == "") # check which parameters have a default prior need_def_prior <- which(x$prior$prior == "" & x$prior$class == "b" & x$prior$coef != "") if (!.is_empty_object(def_prior_b) && !.is_empty_object(need_def_prior)) { x$prior$prior[need_def_prior] <- x$prior$prior[def_prior_b] } # get default prior for all parameters, if defined def_prior_intercept <- which(x$prior$prior != "" & x$prior$class == "Intercept" & x$prior$coef == "") # check which parameters have a default prior need_def_prior <- which(x$prior$prior == "" & x$prior$class == "Intercept" & x$prior$coef != "") if (!.is_empty_object(def_prior_intercept) && !.is_empty_object(need_def_prior)) { x$prior$prior[need_def_prior] <- x$prior$prior[def_prior_intercept] } prior_info <- x$prior[x$prior$coef != "" & x$prior$class %in% c("b", "(Intercept)"), ] # find additional components, avoid duplicated coef-names components <- prior_info$dpar != "" prior_info$dpar[components] <- paste0(prior_info$dpar[components], "_") prior_info$coef <- paste0(prior_info$dpar, prior_info$coef) prior_info$Distribution <- gsub("(.*)\\(.*", "\\1", prior_info$prior) prior_info$Location <- gsub("(.*)\\((.*)\\,(.*)", "\\2", prior_info$prior) prior_info$Scale <- gsub("(.*)\\,(.*)\\)(.*)", "\\2", prior_info$prior) prior_info$Parameter <- prior_info$coef prior_info <- prior_info[, c("Parameter", "Distribution", "Location", "Scale")] pinfo <- as.data.frame(lapply(prior_info, function(x) { if (.is_numeric_character(x)) { as.numeric(as.character(x)) } else { as.character(x) } }), stringsAsFactors = FALSE) if (.is_empty_string(pinfo$Distribution)) { print_color("Model was fitted with uninformative (flat) priors!\n", "red") pinfo$Distribution <- "uniform" pinfo$Location <- 0 pinfo$Scale <- NA } pinfo } #' @importFrom utils tail #' @export get_priors.BFBayesFactor <- function(x, ...) { prior <- .compact_list(utils::tail(x@numerator, 1)[[1]]@prior[[1]]) switch( .classify_BFBayesFactor(x), "correlation" = names(prior) <- "rho", "ttest" = names(prior) <- "Difference" ) data.frame( Parameter = names(prior), Distribution = "cauchy", Location = 0, Scale = unlist(prior), stringsAsFactors = FALSE, row.names = NULL ) } #' @export get_priors.blavaan <- function(x, ...) { if (!requireNamespace("lavaan", quietly = TRUE)) { stop("Package 'lavaan' required for this function to work. Please install it.") } PE <- lavaan::parameterEstimates( x, se = FALSE, ci = FALSE, remove.eq = FALSE, remove.system.eq = TRUE, remove.ineq = FALSE, remove.def = FALSE, add.attributes = TRUE ) if (!("group" %in% names(PE))) PE$group <- 1 newpt <- x@ParTable pte2 <- which(newpt$free > 0) relevant_rows <- match( with(newpt, paste(lhs[pte2], op[pte2], rhs[pte2], group[pte2], sep = "")), paste(PE$lhs, PE$op, PE$rhs, PE$group, sep = "") ) # Priors priors <- rep(NA, nrow(PE)) priors[relevant_rows] <- newpt$prior[pte2] priors[is.na(PE$prior)] <- NA stats::na.omit(data.frame( Parameter = paste(PE$lhs, PE$op, PE$rhs, sep = ""), Distribution = gsub("(.*)\\((.*)", "\\1", priors), Location = as.numeric(gsub("(.*)\\((.*)\\,(.*)\\)(.*)", "\\2", priors)), Scale = as.numeric(gsub("(.*)\\((.*)\\,(.*)\\)(.*)", "\\3", priors)), stringsAsFactors = FALSE )) } #' @importFrom stats na.omit .is_numeric_character <- function(x) { (is.character(x) && !anyNA(suppressWarnings(as.numeric(stats::na.omit(x))))) || (is.factor(x) && !anyNA(suppressWarnings(as.numeric(levels(x))))) } insight/R/format_table.R0000644000176200001440000000360313531534744014715 0ustar liggesusers#' Dataframe and Tables Pretty Formatting #' #' @param x A data frame. #' @param sep Column separator. #' @param header Header separator. Can be \code{NULL}. #' @inheritParams format_value #' #' @return A data frame in character format. #' @examples #' cat(format_table(iris)) #' cat(format_table(iris, sep = " ", header = "*", digits = 1)) #' @export format_table <- function(x, sep = " | ", header = "-", digits = 2, protect_integers = TRUE, missing = "", width = NULL) { df <- x # round all numerics col_names <- names(df) df <- as.data.frame(sapply(df, function(i) { if (is.numeric(i)) { format_value(i, digits = digits, protect_integers = protect_integers, missing = missing, width = width) } else { i } }, simplify = FALSE), stringsAsFactors = FALSE) # Convert to character df <- as.data.frame(sapply(df, as.character, simplify = FALSE), stringsAsFactors = FALSE) names(df) <- col_names df[is.na(df)] <- as.character(missing) # Add colnames as row df <- rbind(colnames(df), df) # Align aligned <- format(df, justify = "right") # Centre first row first_row <- as.character(aligned[1, ]) for (i in 1:length(first_row)) { aligned[1, i] <- format(trimws(first_row[i]), width = nchar(first_row[i]), justify = "right") } final <- as.matrix(aligned) # left-align first column (if a character or a factor) if (!is.numeric(x[, 1])) { final[, 1] <- format(trimws(final[, 1]), justify = "left") } # Transform to character rows <- c() for (row in 1:nrow(final)) { final_row <- paste0(final[row, ], collapse = sep) rows <- paste0(rows, final_row, sep = "\n") # First row separation if (row == 1) { if (!is.null(header)) { rows <- paste0(rows, paste0(rep_len(header, nchar(final_row)), collapse = ""), sep = "\n") } } } rows } insight/R/has_intercept.R0000644000176200001440000000160513524331052015073 0ustar liggesusers#' @title Checks if model has an intercept #' @name has_intercept #' #' @description Checks if model has an intercept. #' #' @param x A model object. #' #' @return \code{TRUE} if \code{x} has an intercept, \code{FALSE} otherwise. #' #' @examples #' model <- lm(mpg ~ 0 + gear, data = mtcars) #' has_intercept(model) #' #' model <- lm(mpg ~ gear, data = mtcars) #' has_intercept(model) #' #' library(lme4) #' model <- lmer(Reaction ~ 0 + Days + (Days | Subject), data = sleepstudy) #' has_intercept(model) #' #' model <- lmer(Reaction ~ Days + (Days | Subject), data = sleepstudy) #' has_intercept(model) #' @export has_intercept <- function(x) { if (is_multivariate(x)) { unlist(lapply(find_terms(x), .check_for_intercept)) } else { .check_for_intercept(find_terms(x)) } } .check_for_intercept <- function(vars) { !("0" %in% vars[["conditional"]]) } insight/R/get_response.R0000644000176200001440000000330513613305061014737 0ustar liggesusers#' @title Get the values from the response variable #' @name get_response #' #' @description Returns the values the response variable(s) from a model object. #' If the model is a multivariate response model, a data frame with values #' from all response variables is returned. #' #' @param select Optional name(s) of response variables for which to extract values. #' Can be used in case of regression models with multiple response variables. #' @inheritParams find_predictors #' #' @return The values of the response variable, as vector, or a data frame if #' \code{x} has more than one defined response variable. #' #' @examples #' library(lme4) #' data(cbpp) #' data(mtcars) #' cbpp$trials <- cbpp$size - cbpp$incidence #' #' m <- glm(cbind(incidence, trials) ~ period, data = cbpp, family = binomial) #' head(get_response(m)) #' get_response(m, select = "incidence") #' #' m <- lm(mpg ~ wt + cyl + vs, data = mtcars) #' get_response(m) #' @export get_response <- function(x, select = NULL) { rn <- find_response(x, combine = FALSE) # exceptions if (inherits(x, "DirichletRegModel")) { rv <- x$Y class(rv) <- "matrix" data.frame(rv) } else if (length(rn) > 1) { rv <- get_data(x)[, rn, drop = FALSE] colnames(rv) <- rn # if user only wants specific response value, return this only if (!is.null(select) && all(select %in% colnames(rv))) { rv <- rv[, select, drop = TRUE] } rv } else { rv <- get_data(x)[[find_response(x, combine = TRUE)]] if (!is.factor(rv) && !is.numeric(rv) && !is.character(rv) && !is.logical(rv) && !is.integer(rv)) { as.vector(rv) } else { rv } } } insight/R/is_multivariate.R0000644000176200001440000000246413554405404015456 0ustar liggesusers#' @title Checks if an object stems from a multivariate response model #' @name is_multivariate #' #' @description Small helper that checks if a model is a multivariate response #' model, i.e. a model with multiple outcomes. #' #' @param x A model object, or an object returned by a function from this package. #' #' @return A logical, \code{TRUE} if either \code{x} is a model object and is #' a multivariate response model, or \code{TRUE} if a return value from a #' function of \pkg{insight} is from a multivariate response model. #' #' @examples #' \dontrun{ #' library(rstanarm) #' data("pbcLong") #' model <- stan_mvmer( #' formula = list( #' logBili ~ year + (1 | id), #' albumin ~ sex + year + (year | id) #' ), #' data = pbcLong, #' chains = 1, cores = 1, seed = 12345, iter = 1000 #' ) #' #' f <- find_formula(model) #' is_multivariate(model) #' is_multivariate(f) #' } #' @export is_multivariate <- function(x) { if (inherits(x, "gam", which = TRUE) == 1) { f <- .gam_family(x) gam_mv <- !is.null(f) && f$family == "Multivariate normal" } else { gam_mv <- FALSE } (inherits(x, "brmsfit") && !is.null(stats::formula(x)$response)) | inherits(x, "stanmvreg") | inherits(x, "mlm") | gam_mv | !is.null(attr(x, "is_mv", exact = TRUE)) } insight/R/is_model.R0000644000176200001440000000663313614067316014055 0ustar liggesusers#' @title Checks if an object is a regression model object #' @name is_model #' #' @description Small helper that checks if a model is a regression model #' object. #' #' @param x An object. #' #' @return A logical, \code{TRUE} if \code{x} is a (supported) model object. #' #' @details This function returns \code{TRUE} if \code{x} is a model object. #' #' @examples #' data(mtcars) #' m <- lm(mpg ~ wt + cyl + vs, data = mtcars) #' #' is_model(m) #' is_model(mtcars) #' @export is_model <- function(x) { inherits( x, c( "_ranger", "aareg", "anova", "Anova.mlm", "aov", "aovlist", "Arima", "bamlss", "bamlss.frame", "bayesmeta", "bayesx", "BBmm", "BBreg", "bcplm", "betareg", "BFBayesFactor", "bglmerMod", "biglm", "bigglm", "blavaan", "blmerMod", "bracl", "brglm", "brglmFit", "brmsfit", "brmultinom", "btergm", "cch", "censReg", "cgam", "cgamm", "cglm", "clm", "clm2", "clmm", "clmm2", "coeftest", "complmrob", "confusionMatrix", "coxme", "coxph", "cpglm", "cpglmm", "crch", "crq", "crqs", "DirichletRegModel", "drc", "emmGrid", "epi.2by2", "ergm", "feglm", "feis", "felm", "fitdistr", "fixest", "flexsurvreg", "gam", "Gam", "GAMBoost", "gamlr", "gamlss", "gamm", "gamm4", "garch", "gbm", "gee", "geeglm", "glimML", "glm", "glmaag", "glmbb", "glmboostLSS", "glmc", "glmdm", "glmdisc", "glmerMod", "glmlep", "glmmadmb", "glmmEP", "glmmfields", "glmmLasso", "glmmPQL", "glmmTMB", "glmnet", "glmrob", "glmRob", "glmx", "gls", "gmnl", "gmm", "htest", "hurdle", "iv_robust", "ivreg", "lavaan", "lm", "lm_robust", "lme", "lmrob", "lmRob", "loggammacenslmrob", "logistf", "LogitBoost", "loo", "LORgee", "lmodel2", "lqmm", "lrm", "manova", "MANOVA", "maxLik", "mboostLSS", "mclogit", "mmclogit", "mcmc", "MCMCglmm", "mediate", "merMod", "mixed", "mixor", "MixMod", "mjoint", "mle2", "mlm", "mlogit", "multinom", "mvmeta", "mvr", "negbin", "nlreg", "nlrq", "nls", "objectiveML", "ols", "orcutt", "plm", "plmm", "polr", "psm", "rdrobust", "ridgelm", "rjags", "rlm", "rlme", "rlmerMod", "RM", "rma", "rma.uni", "rms", "rq", "rqss", "sem", "slm", "speedlm", "speedglm", "stanmvreg", "stanreg", "survfit", "survreg", "survPresmooth", "svyglm", "svyolr", "tobit", "truncreg", "vgam", "vglm", "wbm", "wblm", "zcpglm", "zeroinfl", "zerotrunc" ) ) } insight/R/is_nullmodel.R0000644000176200001440000000207013524331052014726 0ustar liggesusers#' @title Checks if model is a null-model (intercept-only) #' @name is_nullmodel #' #' @description Checks if model is a null-model (intercept-only), i.e. if #' the conditional part of the model has no predictors. #' #' @param x A model object. #' #' @return \code{TRUE} if \code{x} is a null-model, \code{FALSE} otherwise. #' #' @examples #' model <- lm(mpg ~ 1, data = mtcars) #' is_nullmodel(model) #' #' model <- lm(mpg ~ gear, data = mtcars) #' is_nullmodel(model) #' #' library(lme4) #' model <- lmer(Reaction ~ 1 + (Days | Subject), data = sleepstudy) #' is_nullmodel(model) #' #' model <- lmer(Reaction ~ Days + (Days | Subject), data = sleepstudy) #' is_nullmodel(model) #' @export is_nullmodel <- function(x) { if (is_multivariate(x)) { unlist(lapply(find_predictors(x, effects = "fixed", component = "conditional"), .check_for_nullmodel)) } else { .check_for_nullmodel(find_predictors(x, effects = "fixed", component = "conditional")) } } .check_for_nullmodel <- function(preds) { is.null(preds[["conditional"]]) } insight/R/link_function.R0000644000176200001440000002535213614067316015123 0ustar liggesusers#' @title Get link-function from model object #' @name link_function #' #' @description Returns the link-function from a model object. #' #' @inheritParams find_predictors #' @inheritParams find_formula #' @inheritParams link_inverse #' #' @return A function, describing the link-function from a model-object. #' For multivariate-response models, a list of functions is returned. #' #' @examples #' # example from ?stats::glm #' counts <- c(18, 17, 15, 20, 10, 20, 25, 13, 12) #' outcome <- gl(3, 1, 9) #' treatment <- gl(3, 3) #' m <- glm(counts ~ outcome + treatment, family = poisson()) #' #' link_function(m)(.3) #' # same as #' log(.3) #' @export #' @importFrom stats family make.link link_function <- function(x, ...) { UseMethod("link_function") } # Default method --------------------------- #' @export link_function.default <- function(x, ...) { if (inherits(x, "list") && .obj_has_name(x, "gam")) { x <- x$gam class(x) <- c(class(x), c("glm", "lm")) } tryCatch( { # get model family ff <- .gam_family(x) # return link function, if exists if ("linkfun" %in% names(ff)) { return(ff$linkfun) } # else, create link function from link-string if ("link" %in% names(ff)) { return(match.fun(ff$link)) } NULL }, error = function(x) { NULL } ) } # Gaussian family ------------------------------------------ #' @export link_function.lm <- function(x, ...) { stats::gaussian(link = "identity")$linkfun } #' @export link_function.lme <- link_function.lm #' @export link_function.bayesx <- link_function.lm #' @export link_function.mixed <- link_function.lm #' @export link_function.truncreg <- link_function.lm #' @export link_function.censReg <- link_function.lm #' @export link_function.gls <- link_function.lm #' @export link_function.rq <- link_function.lm #' @export link_function.rqss <- link_function.lm #' @export link_function.crq <- link_function.lm #' @export link_function.crqs <- link_function.lm #' @export link_function.lmRob <- link_function.lm #' @export link_function.complmRob <- link_function.lm #' @export link_function.speedlm <- link_function.lm #' @export link_function.biglm <- link_function.lm #' @export link_function.lmrob <- link_function.lm #' @export link_function.lm_robust <- link_function.lm #' @export link_function.iv_robust <- link_function.lm #' @export link_function.aovlist <- link_function.lm #' @export link_function.felm <- link_function.lm #' @export link_function.feis <- link_function.lm #' @export link_function.ivreg <- link_function.lm #' @export link_function.plm <- link_function.lm #' @export link_function.MANOVA <- link_function.lm #' @export link_function.RM <- link_function.lm # General family --------------------------------- #' @export link_function.glm <- link_function.default #' @export link_function.speedglm <- link_function.default #' @export link_function.bigglm <- link_function.default #' @export link_function.brglm <- link_function.default #' @export link_function.cgam <- link_function.default # Logit link ------------------------ #' @export link_function.multinom <- function(x, ...) { stats::make.link(link = "logit")$linkfun } #' @export link_function.BBreg <- link_function.multinom #' @export link_function.BBmm <- link_function.multinom #' @export link_function.gmnl <- link_function.multinom #' @export link_function.logistf <- link_function.multinom #' @export link_function.lrm <- link_function.multinom #' @export link_function.mlogit <- link_function.multinom #' @export link_function.coxph <- link_function.multinom #' @export link_function.survfit <- link_function.multinom #' @export link_function.coxme <- link_function.multinom # Log links ------------------------ #' @export link_function.zeroinfl <- function(x, ...) { stats::make.link("log")$linkfun } #' @export link_function.hurdle <- link_function.zeroinfl #' @export link_function.zerotrunc <- link_function.zeroinfl # Tobit links --------------------------------- #' @export link_function.tobit <- function(x, ...) { .make_tobit_family(x)$linkfun } #' @export link_function.crch <- link_function.tobit #' @export link_function.survreg <- link_function.tobit #' @export link_function.psm <- link_function.tobit #' @export link_function.flexsurvreg <- function(x, ...) { dist <- parse(text = .safe_deparse(x$call))[[1]]$dist .make_tobit_family(x, dist)$linkfun } # Ordinal and cumulative links -------------------------- #' @export link_function.clm <- function(x, ...) { stats::make.link(link = .get_ordinal_link(x))$linkfun } #' @export link_function.clm2 <- link_function.clm #' @export link_function.clmm <- link_function.clm #' @export link_function.mixor <- link_function.clm # Other models ----------------------------- #' @export link_function.cglm <- function(x, ...) { link <- parse(text = .safe_deparse(x$call))[[1]]$link method <- parse(text = .safe_deparse(x$call))[[1]]$method if (!is.null(method) && method == "clm") { link <- "identiy" } stats::make.link(link = link)$linkfun } #' @export link_function.fixest <- function(x, ...) { if (is.null(x$family)) { if (!is.null(x$method) && x$method == "feols") { stats::gaussian(link = "identity")$linkfun } } else if (inherits(x$family, "family")) { x$family$linkfun } else { link <- switch( x$family, "poisson" = , "negbin" = "log", "logit" = "logit", "gaussian" = "identity" ) stats::make.link(link)$linkfun } } #' @export link_function.feglm <- link_function.fixest #' @export link_function.glmx <- function(x, ...) { x$family$glm$linkfun } #' @export link_function.cpglmm <- function(x, ...) { f <- .get_cplm_family(x) f$linkfun } #' @export link_function.cpglm <- link_function.cpglmm #' @export link_function.gam <- function(x, ...) { lf <- tryCatch( { # get model family ff <- .gam_family(x) # return link function, if exists if ("linkfun" %in% names(ff)) { return(ff$linkfun) } # else, create link function from link-string if ("link" %in% names(ff)) { return(match.fun(ff$link)) } NULL }, error = function(x) { NULL } ) if (is.null(lf)) { mi <- .gam_family(x) if (.obj_has_name(mi, "linfo")) { if (.obj_has_name(mi$linfo, "linkfun")) { lf <- mi$linfo$linkfun } else { lf <- mi$linfo[[1]]$linkfun } } } lf } #' @export link_function.glimML <- function(x, ...) { stats::make.link(link = x@link)$linkfun } #' @export link_function.glmmadmb <- function(x, ...) { x$linkfun } #' @rdname link_function #' @export link_function.gamlss <- function(x, what = c("mu", "sigma", "nu", "tau"), ...) { what <- match.arg(what) faminfo <- get(x$family[1], asNamespace("gamlss"))() switch( what, "mu" = faminfo$mu.linkfun, "sigma" = faminfo$sigma.linkfun, "nu" = faminfo$nu.linkfun, "tau" = faminfo$tau.linkfun, faminfo$mu.linkfun ) } #' @export link_function.gamm <- function(x, ...) { x <- x$gam class(x) <- c(class(x), c("glm", "lm")) NextMethod() } #' @export link_function.bamlss <- function(x, ...) { flink <- stats::family(x)$links[1] tryCatch( { stats::make.link(flink)$linkfun }, error = function(e) { print_colour("\nCould not find appropriate link-function.\n", "red") } ) } #' @export link_function.LORgee <- function(x, ...) { if (grepl(pattern = "logit", x = x$link, fixed = TRUE)) { link <- "logit" } else if (grepl(pattern = "probit", x = x$link, fixed = TRUE)) { link <- "probit" } else if (grepl(pattern = "cauchit", x = x$link, fixed = TRUE)) { link <- "cauchit" } else if (grepl(pattern = "cloglog", x = x$link, fixed = TRUE)) { link <- "cloglog" } else { link <- "logit" } stats::make.link(link)$linkfun } #' @export link_function.vgam <- function(x, ...) { x@family@linkfun } #' @export link_function.vglm <- function(x, ...) { x@family@linkfun } #' @export link_function.polr <- function(x, ...) { link <- switch( x$method, logistic = "logit", probit = "probit", "log" ) stats::make.link(link)$linkfun } #' @export link_function.svyolr <- function(x, ...) { link <- switch( x$method, logistic = "logit", probit = "probit", "log" ) stats::make.link(link)$linkfun } #' @rdname link_function #' @export link_function.betareg <- function(x, what = c("mean", "precision"), ...) { what <- match.arg(what) switch( what, "mean" = x$link$mean$linkfun, "precision" = x$link$precision$linkfun ) } #' @rdname link_function #' @export link_function.DirichletRegModel <- function(x, what = c("mean", "precision"), ...) { what <- match.arg(what) if (x$parametrization == "common") { stats::make.link("logit")$linkfun } else { switch( what, "mean" = stats::make.link("logit")$linkfun, "precision" = stats::make.link("log")$linkfun ) } } #' @importFrom stats poisson #' @export link_function.gbm <- function(x, ...) { switch( x$distribution$name, laplace = , tdist = , gaussian = stats::gaussian(link = "identity")$linkfun, poisson = stats::poisson(link = "log")$linkfun, huberized = , adaboost = , coxph = , bernoulli = stats::make.link("logit")$linkfun ) } #' @export link_function.stanmvreg <- function(x, ...) { fam <- stats::family(x) lapply(fam, function(.x) .x$linkfun) } #' @export link_function.brmsfit <- function(x, ...) { fam <- stats::family(x) if (is_multivariate(x)) { lapply(fam, .brms_link_fun) } else { .brms_link_fun(fam) } } # helper ----------------------- .brms_link_fun <- function(fam) { # do we have custom families? if (!is.null(fam$family) && (is.character(fam$family) && fam$family == "custom")) { il <- stats::make.link(fam$link)$linkfun } else { if ("linkfun" %in% names(fam)) { il <- fam$linkfun } else if ("link" %in% names(fam) && is.character(fam$link)) { il <- stats::make.link(fam$link)$linkfun } else { ff <- get(fam$family, asNamespace("stats")) il <- ff(fam$link)$linkfun } } il } insight/R/color_if.R0000644000176200001440000000727513554405404014056 0ustar liggesusers#' @title Color-formatting for data columns based on condition #' @name color_if #' #' @description Convenient function that formats columns in data frames #' with color codes, where the color is chosen based on certain conditions. #' Columns are then printed in color in the console. #' #' @param x A data frame #' @param columns Character vector with column names of \code{x} that should be formatted. #' @param predicate A function that takes \code{columns} and \code{value} as input #' and which should return \code{TRUE} or \code{FALSE}, based on if the condition #' (in comparison with \code{value}) is met. #' @param value The comparator. May be used in conjunction with \code{predicate} #' to quickly set up a function which compares elements in \code{colums} to \code{value}. #' May be ignored when \code{predicate} is a function that internally computes other #' comparisons. See 'Examples'. #' @param color_if,colour_if Character vector, indicating the color code used to #' format values in \code{x} that meet the condition of \code{predicate} and \code{value}. #' May be one of \code{"red"}, \code{"yellow"}, \code{"green"}, \code{"blue"}, #' \code{"violet"}, \code{"cyan"} or \code{"grey"}. Formatting is also possible #' with \code{"bold"} or \code{"italic"}. #' @param color_else,colour_else See \code{color_if}, but only for conditions #' that are \emph{not} met. #' @param digits Digits for rounded values. #' #' @details The predicate-function simply works like this: #' \code{which(predicate(x[, columns], value))} #' #' @return The . #' #' @examples #' # all values in Sepal.Length larger than 5 in green, all remaining in red #' x <- color_if(iris[1:10, ], columns = "Sepal.Length", predicate = `>`, value = 5) #' x #' cat(x$Sepal.Length) #' #' # all levels "setosa" in Species in green, all remaining in red #' x <- color_if(iris, columns = "Species", predicate = `==`, value = "setosa") #' cat(x$Species) #' #' # own function, argument "value" not needed here #' p <- function(x, y) { #' x >= 4.9 & x <= 5.1 #' } #' # all values in Sepal.Length between 4.9 and 5.1 in green, all remaining in red #' x <- color_if(iris[1:10, ], columns = "Sepal.Length", predicate = p) #' cat(x$Sepal.Length) #' @export color_if <- function(x, columns, predicate = `>`, value = 0, color_if = "green", color_else = "red", digits = 2) { xnew <- x if (columns %in% names(x)) { x_if <- which(predicate(x[, columns], value)) x_else <- which(!predicate(x[, columns], value)) values <- x[, columns] xnew[, columns] <- format( if (is.numeric(values)) { round(values, digits = digits) } else { values }, width = nchar(columns), nsmall = digits, justify = "right" ) # remove NA xnew[, columns][trimws(xnew[, columns]) == "NA"] <- "" if (!is.null(color_if) && length(x_if)) { xnew[, columns][x_if] <- .colour(color_if, xnew[, columns][x_if]) } if (!is.null(color_else) && length(x_else)) { xnew[, columns][x_else] <- .colour(color_else, xnew[, columns][x_else]) } } xnew } #' Detect coloured cells #' @keywords internal .colour_detect <- function(x) { ansi_regex <- paste0( "(?:(?:\\x{001b}\\[)|\\x{009b})", "(?:(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?[A-M|f-m])", "|\\x{001b}[A-M]" ) grepl(ansi_regex, x, perl = TRUE) } #' @rdname color_if #' @export colour_if <- function(x, columns, predicate = `>`, value = 0, colour_if = "green", colour_else = "red", digits = 2) { color_if(x = x, columns = columns, predicate = predicate, value = value, color_if = colour_if, color_else = colour_else, digits = digits) } insight/R/find_random_slopes.R0000644000176200001440000000333413602424413016112 0ustar liggesusers#' @title Find names of random slopes #' @name find_random_slopes #' #' @description Return the name of the random slopes from mixed effects models. #' #' @param x A fitted mixed model. #' #' @return A list of character vectors with the name(s) of the random slopes, or #' \code{NULL} if model has no random slopes. Depending on the model, the #' returned list has following elements: #' \itemize{ #' \item \code{random}, the random slopes from the conditional part of model #' \item \code{zero_inflated_random}, the random slopes from the zero-inflation component of the model #' } #' #' @examples #' library(lme4) #' data(sleepstudy) #' #' m <- lmer(Reaction ~ Days + (1 + Days | Subject), data = sleepstudy) #' find_random_slopes(m) #' @export find_random_slopes <- function(x) { random_slopes <- vector(mode = "list") forms <- find_formula(x) random_slopes$random <- .extract_random_slopes(forms$random) random_slopes$zero_inflated_random <- .extract_random_slopes(forms$zero_inflated_random) random_slopes <- .compact_list(random_slopes) if (.is_empty_object(random_slopes)) { NULL } else { random_slopes } } .extract_random_slopes <- function(fr) { if (is.null(fr)) { return(NULL) } if (!is.list(fr)) fr <- list(fr) random_slope <- lapply(fr, function(forms) { if (grepl("(.*)\\|(.*)\\|(.*)", .safe_deparse(forms))) { pattern <- "(.*)\\|(.*)\\|(.*)" } else { pattern <- "(.*)\\|(.*)" } pattern <- gsub(pattern, "\\1", .safe_deparse(forms)) re <- all.vars(forms) re[sapply(re, function(x) { grepl(x, pattern, fixed = TRUE) })] }) unique(unlist(.compact_list(random_slope))) } insight/R/find_interactions.R0000644000176200001440000000444513577635053015772 0ustar liggesusers#' @title Find interaction terms from models #' @name find_interactions #' #' @description Returns all lowest to highest order interaction terms from a model. #' #' @inheritParams find_predictors #' #' @return A list of character vectors that represent the interaction terms. #' Depending on \code{component}, the returned list has following #' elements (or \code{NULL}, if model has no interaction term): #' \itemize{ #' \item \code{conditional}, interaction terms that belong to the "fixed effects" terms from the model #' \item \code{zero_inflated}, interaction terms that belong to the "fixed effects" terms from the zero-inflation component of the model #' \item \code{instruments}, for fixed-effects regressions like \code{ivreg}, \code{felm} or \code{plm}, interaction terms that belong to the instrumental variables #' } #' #' @examples #' data(mtcars) #' #' m <- lm(mpg ~ wt + cyl + vs, data = mtcars) #' find_interactions(m) #' #' m <- lm(mpg ~ wt * cyl + vs * hp * gear + carb, data = mtcars) #' find_interactions(m) #' @export find_interactions <- function(x, component = c("all", "conditional", "zi", "zero_inflated", "dispersion", "instruments"), flatten = FALSE) { component <- match.arg(component) .find_interactions(x, effects = "fixed", component, flatten, main_effects = FALSE) } .find_interactions <- function(x, effects = "fixed", component, flatten, main_effects = FALSE) { f <- find_formula(x) is_mv <- is_multivariate(f) elements <- .get_elements(effects = effects, component = component) if (is_mv) { l <- lapply(f, function(.x) .compact_list(lapply(.x[elements], function(i) .get_interaction_terms(i, main_effects)))) } else { l <- .compact_list(lapply(f[elements], function(i) .get_interaction_terms(i, main_effects))) } if (.is_empty_object(l)) { return(NULL) } if (flatten) { unique(unlist(l)) } else { l } } #' @importFrom stats terms .get_interaction_terms <- function(f, main_effects = FALSE) { if (is.null(f)) { return(NULL) } terms <- labels(stats::terms(f)) if (main_effects) { terms } else { interaction_terms <- grepl(":", terms, fixed = TRUE) if (any(interaction_terms)) { terms[interaction_terms] } else { NULL } } } insight/R/find_parameters.R0000644000176200001440000010465713615253624015432 0ustar liggesusers#' @title Find names of model parameters #' @name find_parameters #' #' @description Returns the names of model parameters, like they typically #' appear in the \code{summary()} output. For Bayesian models, the parameter #' names equal the column names of the posterior samples after coercion #' from \code{as.data.frame()}. #' #' @param parameters Regular expression pattern that describes the parameters that #' should be returned. #' @param effects Should parameters for fixed effects, random effects #' or both be returned? Only applies to mixed models. May be abbreviated. #' @param component Should all parameters, parameters for the #' conditional model, the zero-inflated part of the model, the dispersion #' term or the instrumental variables be returned? Applies to models #' with zero-inflated and/or dispersion formula, or to models with instrumental #' variable (so called fixed-effects regressions). May be abbreviated. Note that the #' \emph{conditional} component is also called \emph{count} or \emph{mean} #' component, depending on the model. #' @param ... Currently not used. #' @inheritParams find_predictors #' #' @return A list of parameter names. For simple models, only one list-element, #' \code{conditional}, is returned. For more complex models, the returned #' list may have following elements: #' \itemize{ #' \item \code{conditional}, the "fixed effects" part from the model #' \item \code{random}, the "random effects" part from the model #' \item \code{zero_inflated}, the "fixed effects" part from the zero-inflation component of the model #' \item \code{zero_inflated_random}, the "random effects" part from the zero-inflation component of the model #' \item \code{dispersion}, the dispersion parameters #' \item \code{simplex}, simplex parameters of monotonic effects (\pkg{brms} only) #' \item \code{smooth_terms}, the smooth parameters #' } #' #' @details In most cases when models either return different "effects" (fixed, #' random) or "components" (conditional, zero-inflated, ...), the arguments #' \code{effects} and \code{component} can be used. Not all model classes that #' support these arguments are listed here in the 'Usage' section. #' #' @examples #' data(mtcars) #' m <- lm(mpg ~ wt + cyl + vs, data = mtcars) #' find_parameters(m) #' @importFrom stats coef #' @export find_parameters <- function(x, ...) { UseMethod("find_parameters") } # Default methods ------------------------------------------- #' @export find_parameters.default <- function(x, flatten = FALSE, ...) { if (inherits(x, "list") && .obj_has_name(x, "gam")) { x <- x$gam class(x) <- c(class(x), c("glm", "lm")) pars <- find_parameters.gam(x) } else { pars <- tryCatch( { p <- .remove_backticks_from_string(names(stats::coef(x))) list(conditional = p) }, error = function(x) { NULL } ) } if (is.null(pars$conditional) || is.null(pars)) { print_color(sprintf("Parameters can't be retrieved for objects of class '%s'.\n", class(x)[1]), "red") return(NULL) } if (flatten) { unique(unlist(pars)) } else { pars } } #' @export find_parameters.data.frame <- function(x, flatten = FALSE, ...) { stop("A data frame is no valid object for this function.") } # Ordinal ----------------------------------------------- #' @export find_parameters.polr <- function(x, flatten = FALSE, ...) { pars <- list(conditional = c(sprintf("Intercept: %s", names(x$zeta)), names(stats::coef(x)))) pars$conditional <- .remove_backticks_from_string(pars$conditional) if (flatten) { unique(unlist(pars)) } else { pars } } #' @export find_parameters.clm2 <- function(x, flatten = FALSE, ...) { cf <- stats::coef(x) n_intercepts <- length(x$xi) n_location <- length(x$beta) n_scale <- length(x$zeta) if (n_scale == 0) { pars <- list(conditional = names(cf)) pars$conditional <- .remove_backticks_from_string(pars$conditional) } else { pars <- .compact_list(list( conditional = names(cf)[1:(n_intercepts + n_location)], scale = names(cf)[(1 + n_intercepts + n_location):(n_scale + n_intercepts + n_location)] )) pars <- rapply(pars, .remove_backticks_from_string, how = "list") } if (flatten) { unique(unlist(pars)) } else { pars } } #' @export find_parameters.clmm2 <- find_parameters.clm2 #' @export find_parameters.bracl <- function(x, flatten = FALSE, ...) { pars <- list(conditional = names(stats::coef(x))) pars$conditional <- .remove_backticks_from_string(pars$conditional) if (flatten) { unique(unlist(pars)) } else { pars } } #' @export find_parameters.betareg <- function(x, flatten = FALSE, ...) { pars <- list( conditional = names(x$coefficients$mean), precision = names(x$coefficients$precision) ) pars$conditional <- .remove_backticks_from_string(pars$conditional) if (flatten) { unique(unlist(pars)) } else { pars } } #' @export find_parameters.DirichletRegModel <- function(x, flatten = FALSE, ...) { if (x$parametrization == "common") { pars <- list(conditional = names(unlist(stats::coef(x)))) } else { pars <- .compact_list(list( conditional = names(unlist(stats::coef(x)[["beta"]])), precision = names(unlist(stats::coef(x)[["gamma"]])) )) pars$precision <- .remove_backticks_from_string(pars$precision) } pars$conditional <- .remove_backticks_from_string(pars$conditional) if (flatten) { unique(unlist(pars)) } else { pars } } #' @export find_parameters.mixor <- function(x, effects = c("all", "fixed", "random"), flatten = FALSE, ...) { effects <- match.arg(effects) coefs <- x$Model random_start <- grep("(\\(Intercept\\) \\(Intercept\\)|Random\\.\\(Intercept\\))", rownames(coefs)) thresholds <- grep("Threshold\\d", rownames(coefs)) l <- list( conditional = rownames(coefs)[c(1, thresholds, 2:(random_start - 1))], random = rownames(coefs)[random_start:(thresholds[1] - 1)] ) .filter_parameters(l, effects = effects, flatten = flatten) } #' @export find_parameters.multinom <- function(x, flatten = FALSE, ...) { params <- stats::coef(x) pars <- if (is.matrix(params)) { list(conditional = colnames(params)) } else { list(conditional = names(params)) } pars$conditional <- .remove_backticks_from_string(pars$conditional) if (flatten) { unique(unlist(pars)) } else { pars } } #' @export find_parameters.brmultinom <- find_parameters.multinom # GAM (additive models) --------------------------------------------- #' @importFrom stats na.omit coef #' @export find_parameters.gamlss <- function(x, flatten = FALSE, ...) { pars <- lapply(x$parameters, function(i) { .remove_backticks_from_string(names(stats::na.omit(stats::coef(x, what = i)))) }) names(pars) <- x$parameters if ("mu" %in% names(pars)) names(pars)[1] <- "conditional" pars <- .compact_list(pars) if (flatten) { unique(unlist(pars)) } else { pars } } #' @rdname find_parameters #' @export find_parameters.gam <- function(x, component = c("all", "conditional", "smooth_terms"), flatten = FALSE, ...) { pars <- list(conditional = names(stats::coef(x))) pars$conditional <- .remove_backticks_from_string(pars$conditional) st <- summary(x)$s.table pars$conditional <- pars$conditional[.grep_non_smoothers(pars$conditional)] pars$smooth_terms <- row.names(st) pars <- .compact_list(pars) component <- match.arg(component) elements <- .get_elements(effects = "all", component = component) pars <- .compact_list(pars[elements]) if (flatten) { unique(unlist(pars)) } else { pars } } #' @export find_parameters.Gam <- function(x, component = c("all", "conditional", "smooth_terms"), flatten = FALSE, ...) { pars <- names(stats::coef(x)) component <- match.arg(component) l <- .compact_list(list( conditional = pars[.grep_non_smoothers(pars)], smooth_terms = pars[.grep_smoothers(pars)] )) .filter_parameters(l, effects = "all", component = component, flatten = flatten, recursive = TRUE) } #' @export find_parameters.vgam <- find_parameters.Gam #' @export find_parameters.gamm <- function(x, component = c("all", "conditional", "smooth_terms"), flatten = FALSE, ...) { x <- x$gam class(x) <- c(class(x), c("glm", "lm")) component <- match.arg(component) l <- find_parameters.gam(x, component = component) if (flatten) { unique(unlist(l)) } else { l } } #' @export find_parameters.cgam <- function(x, component = c("all", "conditional", "smooth_terms"), flatten = FALSE, ...) { component <- match.arg(component) sc <- summary(x) estimates <- sc$coefficients smooth_terms <- sc$coefficients2 l <- .compact_list(list( conditional = rownames(estimates), smooth_terms = rownames(smooth_terms) )) l <- lapply(l, .remove_backticks_from_string) component <- match.arg(component) elements <- .get_elements(effects = "all", component = component) l <- .compact_list(l[elements]) if (flatten) { unique(unlist(l)) } else { l } } # Mixed Models ------------------------------------------------------- #' @export find_parameters.glmmTMB <- function(x, effects = c("all", "fixed", "random"), component = c("all", "conditional", "zi", "zero_inflated", "dispersion"), flatten = FALSE, ...) { effects <- match.arg(effects) component <- match.arg(component) if (!requireNamespace("lme4", quietly = TRUE)) { stop("Package 'lme4' required for this function to work. Please install it.") } # we extract random effects only when really necessary, to save # computational time. In particular model with large sample and # many random effects groups may take some time to return random effects if (effects == "fixed") { l <- .compact_list(list( conditional = names(lme4::fixef(x)$cond), zero_inflated = names(lme4::fixef(x)$zi), dispersion = names(lme4::fixef(x)$disp) )) } else { l <- .compact_list(list( conditional = names(lme4::fixef(x)$cond), random = lapply(lme4::ranef(x)$cond, colnames), zero_inflated = names(lme4::fixef(x)$zi), zero_inflated_random = lapply(lme4::ranef(x)$zi, colnames), dispersion = names(lme4::fixef(x)$disp) )) } .filter_parameters(l, effects = effects, component = component, flatten = flatten) } #' @export find_parameters.MixMod <- function(x, effects = c("all", "fixed", "random"), component = c("all", "conditional", "zi", "zero_inflated"), flatten = FALSE, ...) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("Package 'lme4' required for this function to work. Please install it.") } re.names <- dimnames(lme4::ranef(x))[[2]] has_zeroinf <- !is.null(find_formula(x)[["zero_inflated"]]) if (has_zeroinf) { z_inflated <- names(lme4::fixef(x, sub_model = "zero_part")) z_inflated_random <- re.names[grepl("^zi_", re.names, perl = TRUE)] } else { z_inflated <- NULL z_inflated_random <- NULL } l <- .compact_list(list( conditional = names(lme4::fixef(x, sub_model = "main")), random = re.names[grepl("^(?!zi_)", re.names, perl = TRUE)], zero_inflated = z_inflated, zero_inflated_random = z_inflated_random )) l <- lapply(l, .remove_backticks_from_string) effects <- match.arg(effects) component <- match.arg(component) elements <- .get_elements(effects = effects, component = component) l <- .compact_list(l[elements]) if (flatten) { unique(unlist(l)) } else { l } } #' @export find_parameters.nlmerMod <- function(x, effects = c("all", "fixed", "random"), flatten = FALSE, ...) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("Package 'lme4' required for this function to work. Please install it.") } effects <- match.arg(effects) startvectors <- .get_startvector_from_env(x) if (effects == "fixed") { l <- .compact_list(list( conditional = setdiff(names(lme4::fixef(x)), startvectors), nonlinear = startvectors )) } else { l <- .compact_list(list( conditional = setdiff(names(lme4::fixef(x)), startvectors), nonlinear = startvectors, random = lapply(lme4::ranef(x), colnames) )) } .filter_parameters(l, effects = effects, flatten = flatten) } #' @rdname find_parameters #' @export find_parameters.merMod <- function(x, effects = c("all", "fixed", "random"), flatten = FALSE, ...) { effects <- match.arg(effects) if (!requireNamespace("lme4", quietly = TRUE)) { stop("Package 'lme4' required for this function to work. Please install it.") } # we extract random effects only when really necessary, to save # computational time. In particular model with large sample and # many random effects groups may take some time to return random effects if (effects == "fixed") { l <- list(conditional = names(lme4::fixef(x))) } else { l <- .compact_list(list( conditional = names(lme4::fixef(x)), random = lapply(lme4::ranef(x), colnames) )) } .filter_parameters(l, effects = effects, flatten = flatten) } #' @export find_parameters.rlmerMod <- find_parameters.merMod #' @export find_parameters.glmmadmb <- find_parameters.merMod #' @export find_parameters.cpglmm <- function(x, effects = c("all", "fixed", "random"), flatten = FALSE, ...) { if (!requireNamespace("cplm", quietly = TRUE)) { stop("Package 'cplm' required for this function to work. Please install it.") } effects <- match.arg(effects) # we extract random effects only when really necessary, to save # computational time. In particular model with large sample and # many random effects groups may take some time to return random effects if (effects == "fixed") { l <- list(conditional = names(cplm::fixef(x))) } else { l <- .compact_list(list( conditional = names(cplm::fixef(x)), random = lapply(cplm::ranef(x), colnames) )) } .filter_parameters(l, effects = effects, flatten = flatten) } #' @export find_parameters.coxme <- function(x, effects = c("all", "fixed", "random"), flatten = FALSE, ...) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("Package 'lme4' required for this function to work. Please install it.") } effects <- match.arg(effects) if (effects == "fixed") { l <- list(conditional = names(lme4::fixef(x))) } else { l <- .compact_list(list( conditional = names(lme4::fixef(x)), random = names(lme4::ranef(x)) )) } .filter_parameters(l, effects = effects, flatten = flatten, recursive = FALSE) } #' @export find_parameters.mixed <- function(x, effects = c("all", "fixed", "random"), flatten = FALSE, ...) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("Package 'lme4' required for this function to work. Please install it.") } effects <- match.arg(effects) if (effects == "fixed") { l <- list(conditional = names(lme4::fixef(x$full_model))) } else { l <- .compact_list(list( conditional = names(lme4::fixef(x$full_model)), random = lapply(lme4::ranef(x$full_model), colnames) )) } .filter_parameters(l, effects = effects, flatten = flatten) } #' @export find_parameters.lme <- function(x, effects = c("all", "fixed", "random"), flatten = FALSE, ...) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("Package 'lme4' required for this function to work. Please install it.") } effects <- match.arg(effects) if (effects == "fixed") { l <- list(conditional = names(lme4::fixef(x))) } else { re <- lme4::ranef(x) if (is.data.frame(re)) { rn <- colnames(re) } else { rn <- lapply(re, colnames) } l <- .compact_list(list( conditional = names(lme4::fixef(x)), random = rn )) } .filter_parameters(l, effects = effects, flatten = flatten) } # zero-inflated models -------------------------------------------- #' @rdname find_parameters #' @export find_parameters.zeroinfl <- function(x, component = c("all", "conditional", "zi", "zero_inflated"), flatten = FALSE, ...) { cf <- names(stats::coef(x)) component <- match.arg(component) l <- .compact_list(list( conditional = cf[grepl("^count_", cf, perl = TRUE)], zero_inflated = cf[grepl("^zero_", cf, perl = TRUE)] )) .filter_parameters(l, effects = "all", component = component, flatten = flatten, recursive = FALSE) } #' @rdname find_parameters #' @export find_parameters.hurdle <- find_parameters.zeroinfl #' @export find_parameters.zerotrunc <- find_parameters.default # Bayesian models ----------------------------------------- #' @rdname find_parameters #' @export find_parameters.BFBayesFactor <- function(x, effects = c("all", "fixed", "random"), component = c("all", "extra"), flatten = FALSE, ...) { conditional <- NULL random <- NULL extra <- NULL effects <- match.arg(effects) component <- match.arg(component) if (.classify_BFBayesFactor(x) == "correlation") { conditional <- "rho" } else if (.classify_BFBayesFactor(x) == "ttest") { conditional <- "Difference" } else if (.classify_BFBayesFactor(x) == "meta") { conditional <- "Effect" } else if (.classify_BFBayesFactor(x) == "linear") { posteriors <- as.data.frame(suppressMessages( BayesFactor::posterior(x, iterations = 20, progress = FALSE, index = 1, ...) )) params <- colnames(posteriors) vars <- find_variables(x, effects = "all") dat <- get_data(x) if ("conditional" %in% names(vars)) { conditional <- unlist(lapply(vars$conditional, function(i) { if (is.factor(dat[[i]])) { sprintf("%s-%s", i, levels(dat[[i]])) } else { i } })) } if ("random" %in% names(vars)) { random <- unlist(lapply(vars$random, function(i) { if (is.factor(dat[[i]])) { sprintf("%s-%s", i, levels(dat[[i]])) } else { i } })) } extra <- setdiff(params, c(conditional, random)) } elements <- .get_elements(effects, component = component) l <- lapply(.compact_list(list(conditional = conditional, random = random, extra = extra)), .remove_backticks_from_string) l <- .compact_list(l[elements]) if (flatten) { unique(unlist(l)) } else { l } } #' @export find_parameters.MCMCglmm <- function(x, effects = c("all", "fixed", "random"), flatten = FALSE, ...) { sc <- summary(x) effects <- match.arg(effects) l <- .compact_list(list( conditional = rownames(sc$solutions), random = rownames(sc$Gcovariances) )) .filter_parameters(l, effects = effects, flatten = flatten, recursive = FALSE) } #' @rdname find_parameters #' @export find_parameters.brmsfit <- function(x, effects = c("all", "fixed", "random"), component = c("all", "conditional", "zi", "zero_inflated", "dispersion", "simplex", "sigma", "smooth_terms"), flatten = FALSE, parameters = NULL, ...) { ## TODO remove "make.names()" in a future update fe <- make.names(colnames(as.data.frame(x))) is_mv <- NULL cond <- fe[grepl(pattern = "(b_|bs_|bsp_|bcs_)(?!zi_)(.*)", fe, perl = TRUE)] zi <- fe[grepl(pattern = "(b_zi_|bs_zi_|bsp_zi_|bcs_zi_)", fe, perl = TRUE)] rand <- fe[grepl(pattern = "(?!.*__zi)(?=.*r_)", fe, perl = TRUE) & !grepl(pattern = "^prior_", fe, perl = TRUE)] randzi <- fe[grepl(pattern = "r_(.*__zi)", fe, perl = TRUE)] simo <- fe[grepl(pattern = "^simo_", fe, perl = TRUE)] smooth_terms <- fe[grepl(pattern = "^sds_", fe, perl = TRUE)] priors <- fe[grepl(pattern = "^prior_", fe, perl = TRUE)] sigma <- fe[grepl(pattern = "^sigma_", fe, perl = TRUE)] l <- .compact_list(list( conditional = cond, random = rand, zero_inflated = zi, zero_inflated_random = randzi, simplex = simo, smooth_terms = smooth_terms, sigma = sigma, priors = priors )) effects <- match.arg(effects) component <- match.arg(component) elements <- .get_elements(effects = effects, component = component) elements <- c(elements, "priors") if (is_multivariate(x)) { rn <- names(find_response(x)) l <- lapply(rn, function(i) { if (.obj_has_name(l, "conditional")) { conditional <- l$conditional[grepl(sprintf("^(b_|bs_|bsp_|bcs_)\\Q%s\\E_", i), l$conditional)] } else { conditional <- NULL } if (.obj_has_name(l, "random")) { random <- l$random[grepl(sprintf("__\\Q%s\\E\\.", i), l$random)] } else { random <- NULL } if (.obj_has_name(l, "zero_inflated")) { zero_inflated <- l$zero_inflated[grepl(sprintf("^(b_zi_|bs_zi_|bsp_zi_|bcs_zi_)\\Q%s\\E_", i), l$zero_inflated)] } else { zero_inflated <- NULL } if (.obj_has_name(l, "zero_inflated_random")) { zero_inflated_random <- l$zero_inflated_random[grepl(sprintf("__zi_\\Q%s\\E\\.", i), l$zero_inflated_random)] } else { zero_inflated_random <- NULL } if (.obj_has_name(l, "simplex")) { simplex <- l$simplex } else { simplex <- NULL } if (.obj_has_name(l, "sigma")) { sigma <- l$sigma[grepl(sprintf("^sigma_\\Q%s\\E", i), l$sigma)] } else { sigma <- NULL } if (.obj_has_name(l, "smooth_terms")) { smooth_terms <- l$smooth_terms } else { smooth_terms <- NULL } if (.obj_has_name(l, "priors")) { priors <- l$priors } else { priors <- NULL } pars <- .compact_list(list( conditional = conditional, random = random, zero_inflated = zero_inflated, zero_inflated_random = zero_inflated_random, simplex = simplex, smooth_terms = smooth_terms, sigma = sigma, priors = priors )) .compact_list(pars[elements]) }) names(l) <- rn is_mv <- "1" } else { l <- .compact_list(l[elements]) } l <- .filter_pars(l, parameters, !is.null(is_mv) && is_mv == "1") attr(l, "is_mv") <- is_mv if (flatten) { unique(unlist(l)) } else { l } } #' @importFrom stats coef #' @rdname find_parameters #' @export find_parameters.bayesx <- function(x, component = c("all", "conditional", "smooth_terms"), flatten = FALSE, parameters = NULL, ...) { cond <- rownames(stats::coef(x)) smooth_terms <- rownames(x$smooth.hyp) l <- .compact_list(list( conditional = cond, smooth_terms = smooth_terms )) l <- .filter_pars(l, parameters) component <- match.arg(component) elements <- .get_elements(effects = "all", component) l <- .compact_list(l[elements]) if (flatten) { unique(unlist(l)) } else { l } } #' @rdname find_parameters #' @export find_parameters.stanreg <- function(x, effects = c("all", "fixed", "random"), component = c("all", "conditional", "smooth_terms"), flatten = FALSE, parameters = NULL, ...) { fe <- colnames(as.data.frame(x)) cond <- fe[grepl(pattern = "^(?!(b\\[|sigma|Sigma))", fe, perl = TRUE) & .grep_non_smoothers(fe)] rand <- fe[grepl(pattern = "^b\\[", fe, perl = TRUE)] smooth_terms <- fe[grepl(pattern = "^smooth_sd", fe, perl = TRUE)] l <- .compact_list(list( conditional = cond, random = rand, smooth_terms = smooth_terms )) l <- .filter_pars(l, parameters) effects <- match.arg(effects) component <- match.arg(component) elements <- .get_elements(effects, component) l <- .compact_list(l[elements]) if (flatten) { unique(unlist(l)) } else { l } } #' @export find_parameters.stanmvreg <- function(x, effects = c("all", "fixed", "random"), component = c("all", "conditional", "sigma"), flatten = FALSE, parameters = NULL, ...) { fe <- colnames(as.data.frame(x)) rn <- names(find_response(x)) cond <- fe[grepl(pattern = "^(?!(b\\[|sigma|Sigma))", fe, perl = TRUE) & .grep_non_smoothers(fe) & !grepl(pattern = "\\|sigma$", fe, perl = TRUE)] rand <- fe[grepl(pattern = "^b\\[", fe, perl = TRUE)] sigma <- fe[grepl(pattern = "\\|sigma$", fe, perl = TRUE) & .grep_non_smoothers(fe)] l <- .compact_list(list( conditional = cond, random = rand, sigma = sigma )) if (.obj_has_name(l, "conditional")) { x1 <- sub(pattern = "(.*)(\\|)(.*)", "\\1", l$conditional) x2 <- sub(pattern = "(.*)(\\|)(.*)", "\\3", l$conditional) l.cond <- lapply(rn, function(i) { list(conditional = x2[which(x1 == i)]) }) names(l.cond) <- rn } else { l.cond <- NULL } if (.obj_has_name(l, "random")) { x1 <- sub(pattern = "b\\[(.*)(\\|)(.*)", "\\1", l$random) x2 <- sub(pattern = "(b\\[).*(.*)(\\|)(.*)", "\\1\\4", l$random) l.random <- lapply(rn, function(i) { list(random = x2[which(x1 == i)]) }) names(l.random) <- rn } else { l.random <- NULL } if (.obj_has_name(l, "sigma")) { l.sigma <- lapply(rn, function(i) { list(sigma = "sigma") }) names(l.sigma) <- rn } else { l.sigma <- NULL } l <- mapply(c, l.cond, l.random, l.sigma, SIMPLIFY = FALSE) l <- .filter_pars(l, parameters, is_mv = TRUE) effects <- match.arg(effects) component <- match.arg(component) elements <- .get_elements(effects, component) l <- lapply(l, function(i) .compact_list(i[elements])) attr(l, "is_mv") <- "1" if (flatten) { unique(unlist(l)) } else { l } } # Simulation models ----------------------------- #' @rdname find_parameters #' @export find_parameters.sim.merMod <- function(x, effects = c("all", "fixed", "random"), flatten = FALSE, parameters = NULL, ...) { fe <- colnames(.get_armsim_fixef_parms(x)) re <- colnames(.get_armsim_ranef_parms(x)) l <- .compact_list(list( conditional = fe, random = re )) l <- .filter_pars(l, parameters) effects <- match.arg(effects) elements <- .get_elements(effects, component = "all") l <- .compact_list(l[elements]) if (flatten) { unique(unlist(l)) } else { l } } #' @export find_parameters.sim <- function(x, flatten = FALSE, parameters = NULL, ...) { l <- .filter_pars( list(conditional = colnames(.get_armsim_fixef_parms(x))), parameters ) if (flatten) { unique(unlist(l)) } else { l } } #' @export find_parameters.mcmc <- function(x, flatten = FALSE, parameters = NULL, ...) { l <- .filter_pars(list(conditional = colnames(x)), parameters) if (flatten) { unique(unlist(l)) } else { l } } # SEM models ------------------------------------------------------ #' @export find_parameters.blavaan <- function(x, flatten = FALSE, ...) { if (!requireNamespace("lavaan", quietly = TRUE)) { stop("Package 'lavaan' required for this function to work. Please install it.") } pars <- data.frame( pars = names(lavaan::coef(x)), comp = NA, stringsAsFactors = FALSE ) pars$comp[grepl("~", pars$pars, fixed = TRUE)] <- "regression" pars$comp[grepl("=~", pars$pars, fixed = TRUE)] <- "latent" pars$comp[grepl("~~", pars$pars, fixed = TRUE)] <- "residual" pars$comp[grepl("~1", pars$pars, fixed = TRUE)] <- "intercept" pos_latent <- grep("=~", pars$pars, fixed = TRUE) pos_residual <- grep("~~", pars$pars, fixed = TRUE) pos_intercept <- grep("~1", pars$pars, fixed = TRUE) pos_regression <- setdiff(1:nrow(pars), c(pos_latent, pos_residual, pos_intercept)) pos <- c(min(pos_latent), min(pos_residual), min(pos_intercept), min(pos_regression)) comp_levels <- c("latent", "residual", "intercept", "regression") comp_levels <- comp_levels[order(pos)] pars$comp <- factor(pars$comp, levels = comp_levels) pars <- split(pars, pars$comp) pars <- lapply(pars, function(i) i$pars) if (flatten) { unique(unlist(pars)) } else { pars } } #' @export find_parameters.lavaan <- function(x, flatten = FALSE, ...) { if (!requireNamespace("lavaan", quietly = TRUE)) { stop("Package 'lavaan' required for this function to work. Please install it.") } pars <- get_parameters(x) pars$Component <- factor(pars$Component, levels = unique(pars$Component)) pars <- split(pars$Parameter, pars$Component) if (flatten) { unique(unlist(pars)) } else { pars } } # Panel models ---------------------------------------- #' @export find_parameters.wbm <- function(x, flatten = FALSE, ...) { s <- summary(x) pars <- .compact_list(list( conditional = rownames(s$within_table), instruments = rownames(s$between_table), random = rownames(s$ints_table) )) pars$conditional <- .remove_backticks_from_string(pars$conditional) if (flatten) { unique(unlist(pars)) } else { pars } } #' @export find_parameters.wbgee <- find_parameters.wbm # Other models ----------------------------------- #' @export find_parameters.mlm <- function(x, flatten = FALSE, ...) { cs <- stats::coef(summary(x)) out <- lapply(cs, function(i) { list(conditional = .remove_backticks_from_string(rownames(i))) }) names(out) <- gsub("^Response (.*)", "\\1", names(cs)) attr(out, "is_mv") <- TRUE if (flatten) { unique(unlist(out)) } else { out } } #' @export find_parameters.glmx <- function(x, flatten = FALSE, ...) { cf <- stats::coef(summary(x)) out <- list( conditional = .remove_backticks_from_string(names(cf$glm[, 1])), extra = .remove_backticks_from_string(rownames(cf$extra)) ) if (flatten) { unique(unlist(out)) } else { out } } #' @export find_parameters.gbm <- function(x, flatten = FALSE, ...) { s <- summary(x, plotit = FALSE) pars <- list(conditional = as.character(s$var)) pars$conditional <- .remove_backticks_from_string(pars$conditional) if (flatten) { unique(unlist(pars)) } else { pars } } #' @export find_parameters.BBreg <- function(x, flatten = FALSE, ...) { pars <- list(conditional = rownames(stats::coef(x))) pars$conditional <- .remove_backticks_from_string(pars$conditional) if (flatten) { unique(unlist(pars)) } else { pars } } #' @export find_parameters.lrm <- function(x, flatten = FALSE, ...) { pars <- list(conditional = names(stats::coef(x))) pars$conditional <- .remove_backticks_from_string(pars$conditional) if (flatten) { unique(unlist(pars)) } else { pars } } #' @export find_parameters.flexsurvreg <- find_parameters.lrm #' @export find_parameters.BBmm <- function(x, effects = c("all", "fixed", "random"), flatten = FALSE, ...) { l <- .compact_list(list( conditional = rownames(x$fixed.coef), random = x$namesRand )) effects <- match.arg(effects) .filter_parameters(l, effects = effects, flatten = flatten, recursive = FALSE) } #' @export find_parameters.glimML <- function(x, effects = c("all", "fixed", "random"), flatten = FALSE, ...) { l <- .compact_list(list( conditional = names(x@fixed.param), random = names(x@random.param) )) effects <- match.arg(effects) .filter_parameters(l, effects = effects, flatten = flatten, recursive = FALSE) } #' @export find_parameters.aovlist <- function(x, flatten = FALSE, ...) { l <- lapply(stats::coef(x), names) # merge "intercept" and "block" into conditional # while "Within" becomes "random" l <- list(unname(unlist(l[c(1, 2)])), l[[3]]) l <- lapply(l, .remove_backticks_from_string) names(l) <- c("conditional", "random") if (flatten) { unique(unlist(l)) } else { l } } #' @export find_parameters.crq <- function(x, flatten = FALSE, ...) { sc <- summary(x) if (all(lapply(sc, is.list))) { pars <- list(conditional = rownames(sc[[1]]$coefficients)) } else { pars <- list(conditional = rownames(sc$coefficients)) } pars$conditional <- .remove_backticks_from_string(pars$conditional) if (flatten) { unique(unlist(pars)) } else { pars } } #' @export find_parameters.crqs <- find_parameters.crq #' @export find_parameters.rqss <- function(x, component = c("all", "conditional", "smooth_terms"), flatten = FALSE, ...) { sc <- summary(x) pars <- list( conditional = rownames(sc$coef), smooth_terms = rownames(sc$qsstab) ) pars$conditional <- .remove_backticks_from_string(pars$conditional) pars$smooth_terms <- .remove_backticks_from_string(pars$smooth_terms) component <- match.arg(component) elements <- .get_elements(effects = "all", component) pars <- .compact_list(pars[elements]) if (flatten) { unique(unlist(pars)) } else { pars } } #' @export find_parameters.aareg <- function(x, flatten = FALSE, ...) { sc <- summary(x) pars <- list(conditional = rownames(sc$table)) pars$conditional <- .remove_backticks_from_string(pars$conditional) if (flatten) { unique(unlist(pars)) } else { pars } } #' @export find_parameters.rma <- function(x, flatten = FALSE, ...) { tryCatch( { cf <- stats::coef(x) pars <- list(conditional = names(cf)) pars$conditional[grepl("intrcpt", pars$conditional)] <- "(Intercept)" pars$conditional <- .remove_backticks_from_string(pars$conditional) if (flatten) { unique(unlist(pars)) } else { pars } }, error = function(x) { NULL } ) } # helper ---------------------------- .filter_parameters <- function(l, effects, component = "all", flatten, recursive = TRUE) { if (isTRUE(recursive)) { # recursively remove back-ticks from all list-elements parameters l <- rapply(l, .remove_backticks_from_string, how = "list") } else { l <- lapply(l, .remove_backticks_from_string) } # keep only requested effects elements <- .get_elements(effects, component = component) # remove empty list-elements l <- .compact_list(l[elements]) if (flatten) { unique(unlist(l)) } else { l } } insight/R/get_nested_lme_varcorr.R0000644000176200001440000000335313524331052016761 0ustar liggesusers# Caution! this is somewhat experimental... # It retrieves the variance-covariance matrix of random effects # from nested lme-models. .get_nested_lme_varcorr <- function(x) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("Package `lme4` needs to be installed to compute variances for mixed models.", call. = FALSE) } vcor <- lme4::VarCorr(x) class(vcor) <- "matrix" re_index <- (which(rownames(vcor) == "(Intercept)") - 1)[-1] vc_list <- split(data.frame(vcor, stringsAsFactors = FALSE), findInterval(1:nrow(vcor), re_index)) vc_rownames <- split(rownames(vcor), findInterval(1:nrow(vcor), re_index)) re_pars <- unique(unlist(find_parameters(x)["random"])) re_names <- find_random(x, split_nested = TRUE, flatten = TRUE) names(vc_list) <- re_names mapply( function(x, y) { if ("Corr" %in% colnames(x)) { g_cor <- suppressWarnings(stats::na.omit(as.numeric(x[, "Corr"]))) } else { g_cor <- NULL } row.names(x) <- as.vector(y) vl <- rownames(x) %in% re_pars x <- suppressWarnings(apply(x[vl, vl, drop = FALSE], MARGIN = c(1, 2), FUN = as.numeric)) m1 <- matrix(, nrow = nrow(x), ncol = ncol(x)) m1[1:nrow(m1), 1:ncol(m1)] <- as.vector(x[, 1]) rownames(m1) <- rownames(x) colnames(m1) <- rownames(x) if (!is.null(g_cor)) { m1_cov <- sqrt(prod(diag(m1))) * g_cor for (j in 1:ncol(m1)) { m1[j, nrow(m1) - j + 1] <- m1_cov[1] } } attr(m1, "cor_slope_intercept") <- g_cor m1 }, vc_list, vc_rownames, SIMPLIFY = FALSE ) } .is_nested_lme <- function(x) { sapply(find_random(x), function(i) any(grepl(":", i, fixed = TRUE))) } insight/R/compute_variances.R0000644000176200001440000005141413600232625015756 0ustar liggesusers#' @importFrom stats nobs .compute_variances <- function(x, component, name_fun = NULL, name_full = NULL, verbose = TRUE) { ## Original code taken from GitGub-Repo of package glmmTMB ## Author: Ben Bolker, who used an cleaned-up/adapted ## version of Jon Lefcheck's code from SEMfit ## Major revisions and adaption to more complex models and other packages ## by Daniel Lüdecke faminfo <- model_info(x) if (!faminfo$is_mixed) { stop("Model is not a mixed model.", call. = FALSE) } if (faminfo$family %in% c("truncated_nbinom1", "truncated_nbinom2")) { if (verbose) { warning(sprintf("Truncated negative binomial families are currently not supported by `%s`.", name_fun), call. = F) } return(NA) } # get necessary model information, like fixed and random effects, # variance-covariance matrix etc. vals <- .get_variance_information(x, faminfo = faminfo, name_fun = name_fun, verbose = verbose) # Test for non-zero random effects ((near) singularity) no_random_variance <- FALSE if (.is_singular(x, vals) && !(component %in% c("slope", "intercept"))) { if (verbose) { warning(sprintf("Can't compute %s. Some variance components equal zero.\n Solution: Respecify random structure!", name_full), call. = F) } no_random_variance <- TRUE } # initialize return values, if not all components are requested var.fixed <- NULL var.random <- NULL var.residual <- NULL var.distribution <- NULL var.dispersion <- NULL var.intercept <- NULL var.slope <- NULL cor.slope_intercept <- NULL # Get variance of fixed effects: multiply coefs by design matrix if (component %in% c("fixed", "all")) { var.fixed <- .compute_variance_fixed(vals) } # Are random slopes present as fixed effects? Warn. if (!.random_slopes_in_fixed(x) && verbose) { warning(sprintf("Random slopes not present as fixed effects. This artificially inflates the conditional %s.\n Solution: Respecify fixed structure!", name_full), call. = FALSE) } # Separate observation variance from variance of random effects nr <- sapply(vals$re, nrow) not.obs.terms <- names(nr[nr != n_obs(x)]) obs.terms <- names(nr[nr == n_obs(x)]) # Variance of random effects if (component %in% c("random", "all") && !isTRUE(no_random_variance)) { var.random <- .compute_variance_random(not.obs.terms, x = x, vals = vals) } # Residual variance, which is defined as the variance due to # additive dispersion and the distribution-specific variance (Johnson et al. 2014) if (component %in% c("residual", "distribution", "all")) { var.distribution <- .compute_variance_distribution(x, var.cor = vals$vc, faminfo, name = name_full, verbose = verbose) } if (component %in% c("residual", "dispersion", "all")) { var.dispersion <- .compute_variance_dispersion(x = x, vals = vals, faminfo = faminfo, obs.terms = obs.terms) } if (component %in% c("residual", "all")) { var.residual <- var.distribution + var.dispersion } if (component %in% c("intercept", "all")) { var.intercept <- .between_subject_variance(vals, x) } if (component %in% c("slope", "all")) { var.slope <- .random_slope_variance(vals, x) } if (component %in% c("rho01", "all")) { cor.slope_intercept <- .random_slope_intercept_corr(vals, x) } # if we only need residual variance, we can delete those # values again... if (component == "residual") { var.distribution <- NULL var.dispersion <- NULL } .compact_list(list( "var.fixed" = var.fixed, "var.random" = var.random, "var.residual" = var.residual, "var.distribution" = var.distribution, "var.dispersion" = var.dispersion, "var.intercept" = var.intercept, "var.slope" = var.slope, "cor.slope_intercept" = cor.slope_intercept )) } # store essential information on coefficients, model matrix and so on # as list, since we need these information throughout the functions to # calculate the variance components... # #' @importFrom stats model.matrix .get_variance_information <- function(x, faminfo, name_fun = "get_variances", verbose = TRUE) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("Package `lme4` needs to be installed to compute variances for mixed models.", call. = FALSE) } if (inherits(x, "lme") && !requireNamespace("nlme", quietly = TRUE)) { stop("Package `nlme` needs to be installed to compute variances for mixed models.", call. = FALSE) } if (inherits(x, "rstanarm") && !requireNamespace("rstanarm", quietly = TRUE)) { stop("Package `rstanarm` needs to be installed to compute variances for mixed models.", call. = FALSE) } if (inherits(x, "stanreg")) { vals <- list( beta = lme4::fixef(x), X = rstanarm::get_x(x), vc = lme4::VarCorr(x), re = lme4::ranef(x) ) } else if (inherits(x, "MixMod")) { vals <- list( beta = lme4::fixef(x), X = stats::model.matrix(x), vc = x$D, re = list(lme4::ranef(x)) ) names(vals$re) <- x$id_name } else if (inherits(x, "lme")) { re_names <- find_random(x, split_nested = TRUE, flatten = TRUE) comp_x <- as.matrix(cbind(`(Intercept)` = 1, get_predictors(x))) rownames(comp_x) <- 1:nrow(comp_x) if (.is_nested_lme(x)) { vals_vc <- .get_nested_lme_varcorr(x) vals_re <- lme4::ranef(x) } else { vals_vc <- list(nlme::getVarCov(x)) vals_re <- list(lme4::ranef(x)) } vals <- list( beta = lme4::fixef(x), X = comp_x, vc = vals_vc, re = vals_re ) names(vals$re) <- re_names names(vals$vc) <- re_names } else if (inherits(x, "clmm")) { if (requireNamespace("ordinal", quietly = TRUE)) { f <- find_formula(x)$conditional mm <- stats::model.matrix(f, x$model) vals <- list( beta = c("(Intercept)" = 1, stats::coef(x)[intersect(names(coef(x)), colnames(mm))]), X = mm, vc = ordinal::VarCorr(x), re = ordinal::ranef(x) ) } } else if (inherits(x, "glmmadmb")) { vals <- list( beta = lme4::fixef(x), X = stats::model.matrix(x), vc = lme4::VarCorr(x), re = lme4::ranef(x) ) } else if (inherits(x, "cpglmm")) { if (!requireNamespace("cplm", quietly = TRUE)) { stop("Package 'cplm' required. Please install it.") } vals <- list( beta = cplm::fixef(x), X = cplm::model.matrix(x), vc = cplm::VarCorr(x), re = cplm::ranef(x) ) } else { vals <- list( beta = lme4::fixef(x), X = lme4::getME(x, "X"), vc = lme4::VarCorr(x), re = lme4::ranef(x) ) } # for glmmTMB, tell user that dispersion model is ignored if (inherits(x, "glmmTMB")) { vals <- lapply(vals, .collapse_cond) } if (!is.null(find_formula(x)[["dispersion"]]) && verbose) { warning(sprintf("%s ignores effects of dispersion model.", name_fun), call. = FALSE) } vals } # helper-function, telling user if family / distribution is supported or not .badlink <- function(link, family, verbose = TRUE) { if (verbose) { warning(sprintf("Model link '%s' is not yet supported for the %s distribution.", link, family), call. = FALSE) } return(NA) } # glmmTMB returns a list of model information, one for conditional # and one for zero-inflated part, so here we "unlist" it, returning # only the conditional part. .collapse_cond <- function(x) { if (is.list(x) && "cond" %in% names(x)) { x[["cond"]] } else { x } } # Get fixed effects variance # #' @importFrom stats var .compute_variance_fixed <- function(vals) { with(vals, stats::var(as.vector(beta %*% t(X)))) } # Compute variance associated with a random-effects term (Johnson 2014) # #' @importFrom stats nobs .compute_variance_random <- function(terms, x, vals) { .sigma_sum <- function(Sigma) { rn <- rownames(Sigma) if (!is.null(rn)) { valid <- rownames(Sigma) %in% colnames(vals$X) if (!all(valid)) { rn <- rn[valid] Sigma <- Sigma[valid, valid] } } Z <- vals$X[, rn, drop = FALSE] Z.m <- Z %*% Sigma sum(diag(crossprod(Z.m, Z))) / n_obs(x) } if (inherits(x, "MixMod")) { .sigma_sum(vals$vc) } else { sum(sapply(vals$vc[terms], .sigma_sum)) } } # Calculate Distribution-specific variance (Nakagawa et al. 2017) .compute_variance_distribution <- function(x, var.cor, faminfo, name, verbose = TRUE) { if (inherits(x, "lme")) { sig <- x$sigma } else { sig <- attr(var.cor, "sc") } if (is.null(sig)) sig <- 1 # Distribution-specific variance depends on the model-family # and the related link-function if (faminfo$is_linear && !faminfo$is_tweedie) { dist.variance <- sig^2 } else { if (faminfo$is_binomial) { dist.variance <- switch( faminfo$link_function, logit = pi^2 / 3, probit = 1, cloglog = , clogloglink = pi^2 / 6, .badlink(faminfo$link_function, faminfo$family, verbose = verbose) ) } else if (faminfo$is_count) { dist.variance <- switch( faminfo$link_function, log = .variance_distributional(x, faminfo, sig, name = name, verbose = verbose), sqrt = 0.25, .badlink(faminfo$link_function, faminfo$family, verbose = verbose) ) } else if (faminfo$family %in% c("Gamma", "gamma")) { ## TODO needs some more checking dist.variance <- switch( faminfo$link_function, inverse = , identity = stats::family(x)$variance(sig), log = .variance_distributional(x, faminfo, sig, name = name, verbose = verbose), .badlink(faminfo$link_function, faminfo$family, verbose = verbose) ) } else if (faminfo$family == "beta") { dist.variance <- switch( faminfo$link_function, logit = .variance_distributional(x, faminfo, sig, name = name, verbose = verbose), .badlink(faminfo$link_function, faminfo$family, verbose = verbose) ) } else if (faminfo$is_tweedie) { dist.variance <- switch( faminfo$link_function, log = .variance_distributional(x, faminfo, sig, name = name, verbose = verbose), .badlink(faminfo$link_function, faminfo$family, verbose = verbose) ) } else { dist.variance <- sig } } dist.variance } # Get dispersion-specific variance .compute_variance_dispersion <- function(x, vals, faminfo, obs.terms) { if (faminfo$is_linear) { 0 } else { if (length(obs.terms) == 0) { 0 } else { .compute_variance_random(obs.terms, x = x, vals = vals) } } } # This is the core-function to calculate the distribution-specific variance # Nakagawa et al. 2017 propose three different methods, here we only rely # on the lognormal-approximation. # #' @importFrom stats family .variance_distributional <- function(x, faminfo, sig, name, verbose = TRUE) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("Package `lme4` needs to be installed to compute variances for mixed models.", call. = FALSE) } # lognormal-approximation of distributional variance, # see Nakagawa et al. 2017 # in general want log(1+var(x)/mu^2) null_model <- .null_model(x, verbose = verbose) # check if null-model could be computed if (!is.null(null_model)) { if (inherits(null_model, "cpglmm")) { if (!requireNamespace("cplm", quietly = TRUE)) { stop("Package 'cplm' required. Please install it.") } null_fixef <- unname(cplm::fixef(null_model)) } else { null_fixef <- unname(.collapse_cond(lme4::fixef(null_model))) } mu <- exp(null_fixef) } else { mu <- NA } if (is.na(mu)) { if (verbose) { warning("Can't calculate model's distribution-specific variance. Results are not reliable.", call. = F) } return(0) } else if (mu < 6) { if (verbose) { warning(sprintf("mu of %0.1f is too close to zero, estimate of %s may be unreliable.\n", mu, name), call. = FALSE) } } cvsquared <- tryCatch( { vv <- switch( faminfo$family, # (zero-inflated) poisson `zero-inflated poisson` = , poisson = .variance_family_poisson(x, mu, faminfo), # hurdle-poisson `hurdle poisson` = , truncated_poisson = stats::family(x)$variance(sig), # Gamma, exponential Gamma = stats::family(x)$variance(sig), # (zero-inflated) negative binomial `zero-inflated negative binomial` = , `negative binomial` = , genpois = , nbinom1 = , nbinom2 = .variance_family_nbinom(x, mu, sig, faminfo), # other distributions tweedie = .variance_family_tweedie(x, mu, sig), beta = .variance_family_beta(x, mu, sig), # default variance for non-captured distributions .variance_family_default(x, mu, verbose) ) vv / mu^2 }, error = function(x) { if (verbose) { warning("Can't calculate model's distribution-specific variance. Results are not reliable.", call. = F) } 0 } ) log1p(cvsquared) } # Get distributional variance for poisson-family .variance_family_poisson <- function(x, mu, faminfo) { if (faminfo$is_zero_inflated) { .variance_zip(x, faminfo, family_var = mu) } else { if (inherits(x, "MixMod")) { return(mu) } else if (inherits(x, "cpglmm")) { .get_cplm_family(x)$variance(mu) } else { stats::family(x)$variance(mu) } } } # Get distributional variance for beta-family .variance_family_beta <- function(x, mu, phi) { if (inherits(x, "MixMod")) { stats::family(x)$variance(mu) } else { mu * (1 - mu) / (1 + phi) } } # Get distributional variance for tweedie-family # #' @importFrom stats plogis .variance_family_tweedie <- function(x, mu, phi) { p <- unname(stats::plogis(x$fit$par["thetaf"]) + 1) phi * mu^p } # Get distributional variance for nbinom-family .variance_family_nbinom <- function(x, mu, sig, faminfo) { if (faminfo$is_zero_inflated) { if (missing(sig)) sig <- 0 .variance_zinb(x, sig, faminfo, family_var = mu * (1 + sig)) } else { if (inherits(x, "MixMod")) { if (missing(sig)) { return(rep(1e-16, length(mu))) } mu * (1 + sig) } else { stats::family(x)$variance(mu, sig) } } } # For zero-inflated negative-binomial models, the distributional variance # is based on Zuur et al. 2012 # #' @importFrom stats plogis family predict .variance_zinb <- function(model, sig, faminfo, family_var) { if (inherits(model, "glmmTMB")) { v <- stats::family(model)$variance # zi probability p <- stats::predict(model, type = "zprob") # mean of conditional distribution mu <- stats::predict(model, type = "conditional") # sigma betad <- model$fit$par["betad"] k <- switch( faminfo$family, gaussian = exp(0.5 * betad), Gamma = exp(-0.5 * betad), exp(betad) ) pvar <- (1 - p) * v(mu, k) + mu^2 * (p^2 + p) } else if (inherits(model, "MixMod")) { v <- family_var p <- stats::plogis(stats::predict(model, type_pred = "link", type = "zero_part")) mu <- stats::predict(model, type_pred = "link", type = "mean_subject") k <- sig pvar <- (1 - p) * v(mu, k) + mu^2 * (p^2 + p) } else { pvar <- family_var } mean(pvar) # pearson residuals # pred <- predict(model, type = "response") ## (1 - p) * mu # pred <- stats::predict(model, type_pred = "response", type = "mean_subject") # (insight::get_response(model) - pred) / sqrt(pvar) } # For zero-inflated poisson models, the distributional variance # is based on Zuur et al. 2012 # #' @importFrom stats plogis family predict .variance_zip <- function(model, faminfo, family_var) { if (inherits(model, "glmmTMB")) { p <- stats::predict(model, type = "zprob") mu <- stats::predict(model, type = "conditional") pvar <- (1 - p) * (mu + p * mu^2) } else if (inherits(model, "MixMod")) { p <- stats::plogis(stats::predict(model, type_pred = "link", type = "zero_part")) mu <- stats::predict(model, type = "mean_subject") pvar <- (1 - p) * (mu + p * mu^2) } else { pvar <- family_var } mean(pvar) } # Get distribution-specific variance for general and # undefined families / link-functions .variance_family_default <- function(x, mu, verbose) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("Package `lme4` needs to be installed to compute variances for mixed models.", call. = FALSE) } tryCatch( { if (inherits(x, "merMod")) { mu * (1 + mu / lme4::getME(x, "glmer.nb.theta")) } else if (inherits(x, "MixMod")) { stats::family(x)$variance(mu) } else { mu * (1 + mu / x$theta) } }, error = function(x) { if (verbose) { warning("Can't calculate model's distribution-specific variance. Results are not reliable.", call. = F) } 0 } ) } # Null model is needed to calculate the mean for the model's response, # which we need to compute the distribution-specific variance # (see .variance_distributional()) # #' @importFrom stats as.formula update reformulate .null_model <- function(model, verbose = TRUE) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("Package `lme4` needs to be installed to compute variances for mixed models.", call. = FALSE) } if (inherits(model, "MixMod")) { nullform <- stats::as.formula(paste(find_response(model), "~ 1")) null.model <- stats::update(model, fixed = nullform) } else if (inherits(model, "cpglmm")) { nullform <- find_formula(model)[["random"]] null.model <- stats::update(model, nullform) } else { f <- stats::formula(model) resp <- find_response(model) re.terms <- paste0("(", sapply(lme4::findbars(f), .safe_deparse), ")") nullform <- stats::reformulate(re.terms, response = resp) null.model <- tryCatch( { stats::update(model, nullform) }, error = function(e) { msg <- e$message if (verbose) { if (grepl("(^object)(.*)(not found$)", msg)) { insight::print_color("Can't calculate null-model. Probably the data that was used to fit the model cannot be found.\n", "red") } else if (grepl("^could not find function", msg)) { insight::print_color("Can't calculate null-model. Probably you need to load the package that was used to fit the model.\n", "red") } } return(NULL) } ) } null.model } # return existence of random slopes .random_slopes_in_fixed <- function(model) { rs <- find_random_slopes(model) fe <- find_predictors(model, effects = "fixed", component = "all") # if model has no random slopes, there are no random slopes that # are *not* present as fixed effects if (is.null(rs)) { return(TRUE) } # make sure we have identical subcomponents between random and # fixed effects fe <- .compact_list(fe[c("conditional", "zero_inflated")]) if (length(rs) > length(fe)) rs <- rs[1:length(fe)] if (length(fe) > length(rs)) fe <- fe[1:length(rs)] all(mapply(function(r, f) all(r %in% f), rs, fe, SIMPLIFY = TRUE)) } # random intercept-variances, i.e. # between-subject-variance (tau 00) .between_subject_variance <- function(vals, x) { # retrieve only intercepts if (inherits(x, "MixMod")) { vars <- lapply(vals$vc, function(i) i)[1] } else { vars <- lapply(vals$vc, function(i) i[1]) } sapply(vars, function(i) i) } # random slope-variances (tau 11) .random_slope_variance <- function(vals, x) { if (inherits(x, "MixMod")) { diag(vals$vc)[-1] } else if (inherits(x, "lme")) { unlist(lapply(vals$vc, function(x) diag(x)[-1])) } else { unlist(lapply(vals$vc, function(x) diag(x)[-1])) } } # slope-intercept-correlations (rho 01) .random_slope_intercept_corr <- function(vals, x) { if (inherits(x, "lme")) { rho01 <- unlist(sapply(vals$vc, function(i) attr(i, "cor_slope_intercept"))) if (is.null(rho01)) { vc <- lme4::VarCorr(x) if ("Corr" %in% colnames(vc)) { rho01 <- as.vector(suppressWarnings(na.omit(as.numeric(vc[, "Corr"])))) } } rho01 } else { corrs <- lapply(vals$vc, attr, "correlation") rho01 <- sapply(corrs, function(i) { if (!is.null(i)) { i[-1, 1] } else { NULL } }) unlist(rho01) } } insight/R/utils_model_info.R0000644000176200001440000001762213615526274015621 0ustar liggesusers.make_family <- function(x, fitfam = "gaussian", zero.inf = FALSE, hurdle = FALSE, logit.link = FALSE, multi.var = FALSE, link.fun = "identity", ...) { # create logical for family binom_fam <- fitfam %in% c("bernoulli", "binomial", "quasibinomial", "binomialff") | grepl("\\Qbinomial\\E", fitfam, ignore.case = TRUE) poisson_fam <- fitfam %in% c("poisson", "quasipoisson", "genpois", "ziplss") | grepl("\\Qpoisson\\E", fitfam, ignore.case = TRUE) neg_bin_fam <- grepl("\\Qnegative binomial\\E", fitfam, ignore.case = TRUE) | grepl("\\Qnbinom\\E", fitfam, ignore.case = TRUE) | grepl("\\Qnegbin\\E", fitfam, ignore.case = TRUE) | grepl("\\Qnzbinom\\E", fitfam, ignore.case = TRUE) | grepl("\\Qgenpois\\E", fitfam, ignore.case = TRUE) | grepl("\\Qnegbinomial\\E", fitfam, ignore.case = TRUE) | grepl("\\Qneg_binomial\\E", fitfam, ignore.case = TRUE) | fitfam %in% c("ztnbinom", "nbinom") beta_fam <- inherits(x, "betareg") | fitfam %in% c( "beta", "Beta", "betabinomial", "Beta Inflated", "Zero Inflated Beta", "Beta Inflated zero", "Beta Inflated one" ) betabin_fam <- inherits(x, "BBreg") | fitfam %in% "betabinomial" dirichlet_fam <- inherits(x, "DirichletRegModel") | fitfam %in% "dirichlet" ## TODO beta-binomial = binomial? if (betabin_fam) binom_fam <- TRUE exponential_fam <- fitfam %in% c("Gamma", "gamma", "weibull") linear_model <- (!binom_fam & !exponential_fam & !poisson_fam & !neg_bin_fam & !logit.link) || fitfam %in% c("Student's-t", "t Family", "gaussian", "Gaussian") || grepl("(\\st)$", fitfam) tweedie_fam <- grepl("^(tweedie|Tweedie)", fitfam) tweedie_model <- (linear_model && tweedie_fam) || inherits(x, c("cpglm", "cpglmm")) zero.inf <- zero.inf | fitfam == "ziplss" | grepl("\\Qzero_inflated\\E", fitfam, ignore.case = TRUE) | grepl("\\Qzero-inflated\\E", fitfam, ignore.case = TRUE) | grepl("\\Qneg_binomial\\E", fitfam, ignore.case = TRUE) | grepl("\\Qhurdle\\E", fitfam, ignore.case = TRUE) | grepl("^(zt|zi|za|hu)", fitfam, perl = TRUE) | grepl("^truncated", fitfam, perl = TRUE) hurdle <- hurdle | grepl("\\Qhurdle\\E", fitfam, ignore.case = TRUE) | grepl("^hu", fitfam, perl = TRUE) | grepl("^truncated", fitfam, perl = TRUE) | fitfam == "ztnbinom" | fitfam %in% c("truncpoiss", "truncnbinom", "truncnbinom1") is.ordinal <- inherits(x, c("svyolr", "polr", "clm", "clm2", "clmm", "gmnl", "mixor", "mlogit", "DirichletRegModel", "multinom", "LORgee", "brmultinom")) | fitfam %in% c("cumulative", "cratio", "sratio", "acat", "ordinal", "multinomial", "dirichlet") is.multinomial <- inherits(x, c("gmnl", "mlogit", "DirichletRegModel", "multinom", "brmultinom")) | fitfam %in% c("cratio", "sratio", "acat", "multinomial", "dirichlet") is.categorical <- fitfam == "categorical" is.bayes <- inherits(x, c( "brmsfit", "stanfit", "MCMCglmm", "stanreg", "stanmvreg", "bmerMod", "BFBayesFactor", "bamlss", "bayesx", "mcmc" )) is.survival <- inherits(x, c("aareg", "survreg", "survfit", "survPresmooth", "flexsurvreg", "coxph", "coxme")) # check if we have binomial models with trials instead of binary outcome # and check if we have truncated or censored brms-regression is.trial <- FALSE is.censored <- FALSE is.truncated <- FALSE if (inherits(x, "brmsfit") && is.null(stats::formula(x)$responses)) { rv <- tryCatch( { .safe_deparse(stats::formula(x)$formula[[2L]]) }, error = function(x) { NULL } ) if (!is.null(rv)) { is.trial <- .trim(sub("(.*)\\|(.*)\\(([^,)]*).*", "\\2", rv)) %in% c("trials", "resp_trials") is.censored <- grepl("(.*)\\|(.*)cens\\(", rv) is.truncated <- grepl("(.*)\\|(.*)trunc\\(", rv) } } if (binom_fam && !inherits(x, "brmsfit")) { is.trial <- tryCatch( { rv <- .safe_deparse(stats::formula(x)[[2L]]) grepl("cbind\\((.*)\\)", rv) }, error = function(x) { FALSE } ) } dots <- list(...) if (.obj_has_name(dots, "no_terms") && isTRUE(dots$no_terms)) { model_terms <- NULL } else { if (inherits(x, "mcmc")) { model_terms <- find_parameters(x) } else { model_terms <- tryCatch( { find_variables(x, effects = "all", component = "all", flatten = FALSE) }, error = function(x) { NULL } ) } } if (inherits(x, "htest")) { if (grepl("t-test", x$method)) { is_ttest <- TRUE is_correlation <- FALSE } else { is_ttest <- FALSE is_correlation <- TRUE } } else { is_ttest <- FALSE is_correlation <- FALSE } is_meta <- FALSE if (inherits(x, "BFBayesFactor")) { is_ttest <- FALSE is_correlation <- FALSE obj_type <- .classify_BFBayesFactor(x) if (obj_type == "correlation") { is_correlation <- TRUE } else if (obj_type == "ttest") { is_ttest <- TRUE } else if (obj_type == "meta") { is_meta <- TRUE } } if (inherits(x, "rma")) is_meta <- TRUE list( is_binomial = binom_fam & !neg_bin_fam, is_count = poisson_fam | neg_bin_fam, is_poisson = poisson_fam, is_negbin = neg_bin_fam, is_beta = beta_fam, is_betabinomial = betabin_fam, is_dirichlet = dirichlet_fam, is_exponential = exponential_fam, is_logit = logit.link, is_probit = link.fun == "probit", is_censored = inherits(x, c("tobit", "crch", "censReg")) | is.censored | is.survival, is_truncated = inherits(x, "truncreg") | is.truncated, is_survival = is.survival, is_linear = linear_model, is_tweedie = tweedie_model, is_zeroinf = zero.inf, is_zero_inflated = zero.inf, is_hurdle = hurdle, is_ordinal = is.ordinal, is_cumulative = is.ordinal, is_multinomial = is.multinomial | is.categorical, is_categorical = is.categorical, is_mixed = !is.null(find_random(x)), is_multivariate = multi.var, is_trial = is.trial, is_bayesian = is.bayes, is_anova = inherits(x, c("aov", "aovlist", "MANOVA", "RM")), is_ttest = is_ttest, is_correlation = is_correlation, is_meta = is_meta, link_function = link.fun, family = fitfam, n_obs = n_obs(x), model_terms = model_terms ) } .get_ordinal_link <- function(x) { switch( x$link, logistic = "logit", cloglog = "log", x$link ) } #' @importFrom stats gaussian binomial Gamma .make_tobit_family <- function(x, dist = NULL) { if (is.null(dist)) { if (inherits(x, "flexsurvreg")) { dist <- parse(text = .safe_deparse(x$call))[[1]]$dist } else { dist <- x$dist } } f <- switch( dist, gaussian = stats::gaussian("identity"), logistic = stats::binomial("logit"), llogis = , loglogistic = stats::binomial("log"), lnorm = , lognormal = stats::gaussian("log"), gompertz = stats::Gamma("log"), gamma = , gengamma = , gengamma.orig = stats::Gamma(), exponential = , exp = , weibull = stats::Gamma("log"), stats::gaussian("identity") ) if (dist == "weibull") f$family <- "weibull" f } .classify_BFBayesFactor <- function(x) { if (!requireNamespace("BayesFactor", quietly = TRUE)) { stop("This function needs `BayesFactor` to be installed.") } if (any(class(x@denominator) %in% c("BFcorrelation"))) { "correlation" } else if (any(class(x@denominator) %in% c("BFoneSample", "BFindepSample"))) { "ttest" } else if (any(class(x@denominator) %in% c("BFmetat"))) { "meta" } else if (any(class(x@denominator) %in% c("BFlinearModel"))) { "linear" } else { class(x@denominator) } } insight/R/get_varcov.R0000644000176200001440000003144013613276575014423 0ustar liggesusers#' @title Get variance-covariance matrix from models #' #' @description Returns the variance-covariance, as retrieved by #' \code{stats::vcov()}, but works for more model objects that probably #' don't provide a \code{vcov()}-method. #' @name get_varcov #' #' @param x A model. #' @param component Should the complete variance-covariance matrix of the model #' be returned, or only for specific model components only (like count or #' zero-inflated model parts)? Applies to models with zero-inflated component, #' or models with precision (e.g. \code{betareg}) component. \code{component} #' may be one of \code{"conditional"}, \code{"zi"}, \code{"zero-inflated"}, #' \code{"precision"}, or \code{"all"}. May be abbreviated. Note that the #' \emph{conditional} component is also called \emph{count} or \emph{mean} #' component, depending on the model. #' @param effects Should the complete variance-covariance matrix of the model #' be returned, or only for specific model parameters only? Currently only #' applies to models of class \code{mixor}. #' @param ... Currently not used. #' #' @note \code{get_varcov()} tries to return the nearest positive definite matrix #' in case of a negative variance-covariance matrix. #' #' @return The variance-covariance matrix, as \code{matrix}-object. #' #' @examples #' data(mtcars) #' m <- lm(mpg ~ wt + cyl + vs, data = mtcars) #' get_varcov(m) #' @importFrom stats vcov #' @export get_varcov <- function(x, ...) { UseMethod("get_varcov") } # Default models ---------------------------------------------------- #' @export get_varcov.default <- function(x, ...) { vc <- suppressWarnings(stats::vcov(x)) if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @export get_varcov.maxLik <- get_varcov.default # models with special components --------------------------------------------- #' @rdname get_varcov #' @export get_varcov.betareg <- function(x, component = c("conditional", "precision", "all"), ...) { component <- match.arg(component) vc <- switch( component, "conditional" = stats::vcov(object = x, model = "mean"), "precision" = stats::vcov(object = x, model = "precision"), stats::vcov(object = x) ) if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @rdname get_varcov #' @export get_varcov.DirichletRegModel <- function(x, component = c("conditional", "precision", "all"), ...) { component <- match.arg(component) if (x$parametrization == "common") { vc <- stats::vcov(x) } else { if (component == "conditional") { vc <- stats::vcov(x) keep <- grepl("^(?!\\(phi\\))", rownames(vc), perl = TRUE) vc <- vc[keep, keep] } else if (component == "precision") { vc <- stats::vcov(x) keep <- grepl("^\\(phi\\)", rownames(vc), perl = TRUE) vc <- vc[keep, keep] } else { vc <- stats::vcov(x) } } if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @rdname get_varcov #' @export get_varcov.clm2 <- function(x, component = c("all", "conditional", "scale"), ...) { component <- match.arg(component) n_intercepts <- length(x$xi) n_location <- length(x$beta) n_scale <- length(x$zeta) vc <- stats::vcov(x) if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } range <- switch( component, "all" = 1:(n_scale + n_intercepts + n_location), "conditional" = 1:(n_intercepts + n_location), "scale" = (1 + n_intercepts + n_location):(n_scale + n_intercepts + n_location) ) vc <- vc[range, range] .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @export get_varcov.clmm2 <- get_varcov.clm2 #' @export get_varcov.glmx <- function(x, component = c("all", "conditional", "extra"), ...) { component <- match.arg(component) vc <- stats::vcov(object = x) if (component != "all") { keep <- match(insight::find_parameters(x)[[component]], rownames(vc)) vc <- vc[keep, keep] } if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @rdname get_varcov #' @export get_varcov.truncreg <- function(x, component = c("conditional", "all"), ...) { component <- match.arg(component) vc <- stats::vcov(x) if (component == "conditional") { vc <- vc[1:(nrow(vc) - 1), 1:(ncol(vc) - 1)] } if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @rdname get_varcov #' @export get_varcov.gamlss <- function(x, component = c("conditional", "all"), ...) { component <- match.arg(component) vc <- suppressWarnings(stats::vcov(x)) if (component == "conditional") { cond_pars <- length(find_parameters(x)$conditional) vc <- as.matrix(vc)[1:cond_pars, 1:cond_pars] } if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } # Zero-Inflated models ---------------------------------------------------- #' @rdname get_varcov #' @export get_varcov.hurdle <- function(x, component = c("conditional", "zero_inflated", "zi", "all"), ...) { component <- match.arg(component) vc <- switch( component, "conditional" = stats::vcov(object = x, model = "count"), "zi" = , "zero_inflated" = stats::vcov(object = x, model = "zero"), stats::vcov(object = x) ) if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @export get_varcov.zeroinfl <- get_varcov.hurdle #' @export get_varcov.zerocount <- get_varcov.hurdle # Zero-Inflated mixed models ------------------------------------------------ #' @rdname get_varcov #' @export get_varcov.MixMod <- function(x, component = c("conditional", "zero_inflated", "zi", "all"), ...) { component <- match.arg(component) vc <- switch( component, "conditional" = stats::vcov(x, parm = "fixed-effects"), "zi" = , "zero_inflated" = stats::vcov(x, parm = "zero_part"), stats::vcov(x) ) if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @rdname get_varcov #' @export get_varcov.glmmTMB <- function(x, component = c("conditional", "zero_inflated", "zi", "all"), ...) { component <- match.arg(component) vc <- switch( component, "conditional" = stats::vcov(x)[["cond"]], "zi" = , "zero_inflated" = stats::vcov(x)[["zi"]], stats::vcov(x, full = TRUE) ) if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } # Bayesian models ------------------------------------------------ #' @rdname get_varcov #' @export get_varcov.brmsfit <- function(x, component = c("conditional", "zero_inflated", "zi", "all"), ...) { component <- match.arg(component) params <- find_parameters(x, effects = "fixed", component = component, flatten = TRUE) params <- gsub("^b_", "", params) vc <- stats::vcov(x)[params, params] if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } # Other models with special handling ----------------------------------------- #' @export get_varcov.rq <- function(x, ...) { s <- summary(x, covariance = TRUE) vc <- as.matrix(s$cov) if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @export get_varcov.crq <- get_varcov.rq #' @export get_varcov.nlrq <- get_varcov.rq #' @export get_varcov.flexsurvreg <- function(x, ...) { pars <- find_parameters(x, flatten = TRUE) vc <- as.matrix(stats::vcov(x))[pars, pars] if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @export get_varcov.mixed <- function(x, ...) { vc <- as.matrix(stats::vcov(x$full_model)) if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @export get_varcov.cpglmm <- function(x, ...) { vc <- as.matrix(x@vcov) if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @export get_varcov.cpglm <- get_varcov.cpglmm #' @export get_varcov.cglm <- function(x, ...) { vc <- as.matrix(x$var) if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @rdname get_varcov #' @export get_varcov.mixor <- function(x, effects = c("all", "fixed", "random"), ...) { effects <- match.arg(effects) params <- find_parameters(x, effects = effects, flatten = TRUE) vc <- as.matrix(stats::vcov(x))[params, params] if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @export get_varcov.gamm <- function(x, ...) { vc <- stats::vcov(x$gam) if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @export get_varcov.list <- function(x, ...) { if ("gam" %in% names(x)) { vc <- stats::vcov(x$gam) if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } } #' @export get_varcov.BBmm <- function(x, ...) { vc <- x$fixed.vcov if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @export get_varcov.BBreg <- function(x, ...) { vc <- x$vcov if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @export get_varcov.feis <- function(x, ...) { vc <- x$vcov if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @export get_varcov.glimML <- function(x, ...) { if (!requireNamespace("aod", quietly = TRUE)) { stop("Package 'aod' required for this function to work. Please install it.") } vc <- aod::vcov(x) if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @export get_varcov.vglm <- function(x, ...) { if (!requireNamespace("VGAM", quietly = TRUE)) { stop("Package 'VGAM' required for this function to work. Please install it.") } vc <- VGAM::vcov(x) if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @export get_varcov.vgam <- get_varcov.vglm #' @export get_varcov.geeglm <- function(x, ...) { vc <- summary(x)$cov.unscaled if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @export get_varcov.tobit <- function(x, ...) { coef_names <- find_parameters(x, flatten = TRUE) vc <- stats::vcov(x)[coef_names, coef_names] if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @export get_varcov.lmRob <- function(x, ...) { vc <- x$cov if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @export get_varcov.glmRob <- get_varcov.lmRob #' @export get_varcov.gee <- function(x, ...) { vc <- x$naive.variance if (.is_negativ_matrix(vc)) { vc <- .fix_negative_matrix(vc) } .remove_backticks_from_matrix_names(as.matrix(vc)) } #' @export get_varcov.LORgee <- get_varcov.gee # helper-functions ----------------------------------------------------- .is_negativ_matrix <- function(x) { if (is.matrix(x) && (nrow(x) == ncol(x))) { rv <- tryCatch( { eigenvalues <- eigen(x, only.values = TRUE)$values eigenvalues[abs(eigenvalues) < 1e-07] <- 0 any(eigenvalues <= 0) }, error = function(e) { FALSE } ) } else { rv <- FALSE } rv } .fix_negative_matrix <- function(m) { if (requireNamespace("Matrix", quietly = TRUE)) { as.matrix(Matrix::nearPD(m)$mat) } else { m } } insight/R/get_data.R0000644000176200001440000005154413613305554014031 0ustar liggesusers#' @title Get the data that was used to fit the model #' @name get_data #' #' @description This functions tries to get the data that was used to fit the #' model and returns it as data frame. #' #' @param effects Should model data for fixed effects, random effects #' or both be returned? Only applies to mixed models. #' #' @inheritParams find_predictors #' @inheritParams find_formula #' #' @return The data that was used to fit the model. #' #' @note Unlike \code{model.frame()}, which may contain transformed variables #' (e.g. if \code{poly()} or \code{scale()} was used inside the formula to #' specify the model), \code{get_data()} aims at returning the "original", #' untransformed data. #' #' @examples #' data(cbpp, package = "lme4") #' cbpp$trials <- cbpp$size - cbpp$incidence #' m <- glm(cbind(incidence, trials) ~ period, data = cbpp, family = binomial) #' head(get_data(m)) #' @importFrom stats model.frame na.omit #' @export get_data <- function(x, ...) { UseMethod("get_data") } # default method ------------------------------------------------------ #' @export get_data.default <- function(x, ...) { if (inherits(x, "list") && .obj_has_name(x, "gam")) { x <- x$gam class(x) <- c(class(x), c("glm", "lm")) } mf <- tryCatch( { if (inherits(x, "Zelig-relogit")) { .get_zelig_relogit_frame(x) } else { stats::model.frame(x) } }, error = function(x) { NULL } ) if (is.null(mf)) { mf <- tryCatch( { .get_data_from_env(x)[, find_variables(x, flatten = TRUE), drop = FALSE] }, error = function(x) { NULL } ) } .prepare_get_data(x, mf) } #' @export get_data.data.frame <- function(x, ...) { x } # classical and survival models ----------------------------------------------- #' @rdname get_data #' @export get_data.gee <- function(x, effects = c("all", "fixed", "random"), ...) { effects <- match.arg(effects) mf <- tryCatch( { dat <- .get_data_from_env(x) switch( effects, all = dat[, find_variables(x, flatten = TRUE), drop = FALSE], fixed = dat[, find_variables(x, effects = "fixed", flatten = TRUE), drop = FALSE], random = dat[, find_random(x, flatten = TRUE), drop = FALSE] ) }, error = function(x) { NULL } ) .prepare_get_data(x, stats::na.omit(mf)) } #' @rdname get_data #' @export get_data.rqss <- function(x, component = c("all", "conditional", "smooth_terms"), ...) { component <- match.arg(component) mf <- tryCatch( { dat <- .get_data_from_env(x) dat[, find_variables(x, effects = "all", component = component, flatten = TRUE), drop = FALSE] }, error = function(x) { NULL } ) .prepare_get_data(x, stats::na.omit(mf)) } #' @export get_data.gls <- function(x, ...) { mf <- tryCatch( { dat <- .get_data_from_env(x) data_columns <- intersect(colnames(dat), find_variables(x, flatten = TRUE)) dat[, data_columns, drop = FALSE] }, error = function(x) { NULL } ) .prepare_get_data(x, stats::na.omit(mf)) } #' @export get_data.survfit <- get_data.gls #' @export get_data.aareg <- get_data.gls #' @export get_data.complmrob <- get_data.gls #' @export get_data.nlrq <- get_data.gls # zero-inflated models ------------------------------------------------------- #' @rdname get_data #' @export get_data.hurdle <- function(x, component = c("all", "conditional", "zi", "zero_inflated", "dispersion"), ...) { component <- match.arg(component) .return_zeroinf_data(x, component) } #' @export get_data.zeroinfl <- get_data.hurdle #' @export get_data.zerotrunc <- get_data.default # mixed models ------------------------------------------------------------- #' @rdname get_data #' @export get_data.glmmTMB <- function(x, effects = c("all", "fixed", "random"), component = c("all", "conditional", "zi", "zero_inflated", "dispersion"), ...) { effects <- match.arg(effects) component <- match.arg(component) model.terms <- find_variables(x, effects = "all", component = "all", flatten = FALSE) mf <- tryCatch( { stats::model.frame(x) }, error = function(x) { NULL } ) mf <- .prepare_get_data(x, mf) # add variables from other model components mf <- .add_zeroinf_data(x, mf, model.terms$dispersion) mf <- .add_zeroinf_data(x, mf, model.terms$zero_inflated) mf <- .add_zeroinf_data(x, mf, model.terms$zero_inflated_random) .return_data(x, mf, effects, component, model.terms) } #' @rdname get_data #' @export get_data.merMod <- function(x, effects = c("all", "fixed", "random"), ...) { effects <- match.arg(effects) mf <- tryCatch( { switch( effects, fixed = stats::model.frame(x, fixed.only = TRUE), all = stats::model.frame(x, fixed.only = FALSE), random = stats::model.frame(x, fixed.only = FALSE)[, find_random(x, split_nested = TRUE, flatten = TRUE), drop = FALSE] ) }, error = function(x) { NULL } ) .prepare_get_data(x, mf, effects) } #' @export get_data.MANOVA <- function(x, effects = c("all", "fixed", "random"), ...) { effects <- match.arg(effects) mf <- tryCatch( { switch( effects, fixed = .remove_column(x$input$data, x$input$subject), all = x$input$data, random = x$input$data[, x$input$subject, drop = FALSE] ) }, error = function(x) { NULL } ) .prepare_get_data(x, mf, effects) } #' @export get_data.RM <- get_data.MANOVA #' @export get_data.cpglmm <- function(x, effects = c("all", "fixed", "random"), ...) { effects <- match.arg(effects) dat <- stats::model.frame(x) mf <- tryCatch( { switch( effects, fixed = dat[, find_predictors(x, effects = "fixed", flatten = TRUE), drop = FALSE], all = dat, random = dat[, find_random(x, split_nested = TRUE, flatten = TRUE), drop = FALSE] ) }, error = function(x) { NULL } ) .prepare_get_data(x, mf, effects) } #' @export get_data.mixor <- function(x, effects = c("all", "fixed", "random"), ...) { effects <- match.arg(effects) mf <- tryCatch( { switch( effects, fixed = stats::model.frame(x), all = cbind(stats::model.frame(x), x$id), random = data.frame(x$id) ) }, error = function(x) { NULL } ) fix_cn <- which(colnames(mf) %in% c("x.id", "x$id")) colnames(mf)[fix_cn] <- deparse(x$call$id) .prepare_get_data(x, mf, effects) } #' @rdname get_data #' @export get_data.glmmadmb <- function(x, effects = c("all", "fixed", "random"), ...) { effects <- match.arg(effects) fixed_data <- x$frame random_data <- .get_data_from_env(x)[, find_random(x, split_nested = TRUE, flatten = TRUE), drop = FALSE] mf <- tryCatch( { switch( effects, fixed = fixed_data, all = cbind(fixed_data, random_data), random = random_data ) }, error = function(x) { NULL } ) .prepare_get_data(x, mf, effects) } #' @rdname get_data #' @export get_data.rlmerMod <- function(x, effects = c("all", "fixed", "random"), ...) { effects <- match.arg(effects) .get_data_from_modelframe(x, stats::model.frame(x), effects) } #' @rdname get_data #' @export get_data.clmm <- get_data.rlmerMod #' @rdname get_data #' @export get_data.mixed <- function(x, effects = c("all", "fixed", "random"), ...) { effects <- match.arg(effects) .get_data_from_modelframe(x, x$data, effects) } #' @rdname get_data #' @export get_data.lme <- function(x, effects = c("all", "fixed", "random"), ...) { effects <- match.arg(effects) dat <- tryCatch( { x$data }, error = function(x) { NULL } ) stats::na.omit(.get_data_from_modelframe(x, dat, effects)) } #' @rdname get_data #' @export get_data.MixMod <- function(x, effects = c("all", "fixed", "random"), component = c("all", "conditional", "zi", "zero_inflated", "dispersion"), ...) { effects <- match.arg(effects) component <- match.arg(component) tryCatch( { fitfram <- x$model_frames$mfX if (!.is_empty_object(x$model_frames$mfZ)) { fitfram <- .merge_dataframes(x$model_frames$mfZ, fitfram, replace = TRUE) } if (!.is_empty_object(x$model_frames$mfX_zi)) { fitfram <- .merge_dataframes(x$model_frames$mfX_zi, fitfram, replace = TRUE) } if (!.is_empty_object(x$model_frames$mfZ_zi)) { fitfram <- .merge_dataframes(x$model_frames$mfZ_zi, fitfram, replace = TRUE) } fitfram$grp__id <- unlist(x$id) colnames(fitfram)[ncol(fitfram)] <- x$id_name[1] # test... fitfram <- .prepare_get_data(x, fitfram) model.terms <- find_variables(x, effects = "all", component = "all", flatten = FALSE) .return_data(x, mf = fitfram, effects, component, model.terms) }, error = function(x) { NULL } ) } #' @export get_data.BBmm <- function(x, effects = c("all", "fixed", "random"), ...) { effects <- match.arg(effects) mf <- tryCatch( { dat <- .get_data_from_env(x)[, find_variables(x, flatten = TRUE), drop = FALSE] switch( effects, all = dat[, find_variables(x, flatten = TRUE), drop = FALSE], fixed = dat[, find_variables(x, effects = "fixed", flatten = TRUE), drop = FALSE], random = dat[, find_random(x, flatten = TRUE), drop = FALSE] ) }, error = function(x) { x$X } ) .prepare_get_data(x, stats::na.omit(mf)) } #' @export get_data.glimML <- function(x, effects = c("all", "fixed", "random"), ...) { effects <- match.arg(effects) dat <- x@data mf <- switch( effects, all = dat[, find_variables(x, flatten = TRUE), drop = FALSE], fixed = dat[, find_variables(x, effects = "fixed", flatten = TRUE), drop = FALSE], random = dat[, find_random(x, flatten = TRUE), drop = FALSE] ) .prepare_get_data(x, stats::na.omit(mf)) } # sem models ------------------------------------- #' @export get_data.lavaan <- function(x, ...) { mf <- tryCatch( { .get_S4_data_from_env(x) }, error = function(x) { NULL } ) .prepare_get_data(x, stats::na.omit(mf)) } #' @export get_data.blavaan <- get_data.lavaan # additive models (gam) ------------------------------------- #' @export get_data.vgam <- function(x, ...) { mf <- tryCatch( { get(x@misc$dataname, envir = parent.frame())[, find_variables(x, flatten = TRUE), drop = FALSE] }, error = function(x) { NULL } ) .prepare_get_data(x, mf) } #' @export get_data.gamm <- function(x, ...) { x <- x$gam class(x) <- c(class(x), c("glm", "lm")) mf <- stats::model.frame(x) .prepare_get_data(x, mf) } #' @export get_data.gamlss <- function(x, ...) { mf <- tryCatch( { elements <- c("mu", "sigma", "nu", "tau") mf_list <- .compact_list(lapply(elements, function(e) { if (paste0(e, ".x") %in% names(x)) { stats::model.frame(x, what = e) } else { NULL } })) mf_data <- mf_list[[1]] if (length(mf_list) > 1) { for (i in 2:length(mf_list)) { cn <- setdiff(colnames(mf_list[[i]]), colnames(mf_data)) if (length(cn)) mf_data <- cbind(mf_data, mf_list[[i]][, cn, drop = FALSE]) } } mf_data }, error = function(x) { NULL } ) .prepare_get_data(x, mf, effects = "all") } # fixed effects and panel regression -------------------------------------- #' @export get_data.felm <- function(x, effects = c("all", "fixed", "random"), ...) { effects <- match.arg(effects) .get_data_from_modelframe(x, stats::model.frame(x), effects) } #' @export get_data.feis <- function(x, effects = c("all", "fixed", "random"), ...) { effects <- match.arg(effects) mf <- tryCatch( { .get_data_from_env(x) }, error = function(x) { stats::model.frame(x) } ) .get_data_from_modelframe(x, mf, effects) } #' @export get_data.fixest <- function(x, ...) { mf <- .get_data_from_env(x) .get_data_from_modelframe(x, mf, effects = "all") } #' @export get_data.feglm <- function(x, ...) { mf <- as.data.frame(x$data) .get_data_from_modelframe(x, mf, effects = "all") } #' @export get_data.plm <- function(x, ...) { mf <- stats::model.frame(x) model_terms <- find_variables(x, effects = "all", component = "all", flatten = TRUE) cn <- colnames(mf) mf <- as.data.frame(lapply(mf, as.vector)) colnames(mf) <- clean_names(cn) # find index variables index <- eval(parse(text = .safe_deparse(x$call))[[1]]$index) # try to get index variables from orignal data if (!is.null(index)) { original_data <- .get_data_from_env(x) keep <- intersect(index, colnames(original_data)) if (length(keep)) { mf <- cbind(mf, original_data[, keep, drop = FALSE]) model_terms <- c(model_terms, keep) } } .prepare_get_data(x, mf[, model_terms, drop = FALSE]) } #' @export get_data.wbm <- function(x, effects = c("all", "fixed", "random"), ...) { effects <- match.arg(effects) mf <- stats::model.frame(x) # dat <- as.data.frame(x@orig_data) if (effects == "random") { return(stats::na.omit(mf[, unique(find_random(x, split_nested = TRUE, flatten = TRUE)), drop = FALSE])) } resp.col <- which(colnames(mf) == find_response(x)) mf <- mf[, c(resp.col, (1:ncol(mf))[-resp.col])] .prepare_get_data(x, stats::na.omit(mf)) } #' @export get_data.wbgee <- get_data.wbm #' @export get_data.ivreg <- function(x, ...) { mf <- stats::model.frame(x) cn <- clean_names(colnames(mf)) ft <- find_variables(x, flatten = TRUE) remain <- setdiff(ft, cn) if (.is_empty_object(remain)) { final_mf <- mf } else { final_mf <- tryCatch( { dat <- .get_data_from_env(x) cbind(mf, dat[, remain, drop = FALSE]) }, error = function(x) { NULL } ) } .prepare_get_data(x, stats::na.omit(final_mf)) } #' @export get_data.iv_robust <- get_data.ivreg # Bayesian regression --------------------------------------------------- #' @rdname get_data #' @export get_data.brmsfit <- function(x, effects = c("all", "fixed", "random"), component = c("all", "conditional", "zi", "zero_inflated"), ...) { effects <- match.arg(effects) component <- match.arg(component) model.terms <- find_variables(x, effects = "all", component = "all", flatten = FALSE) mf <- stats::model.frame(x) if (.is_multi_membership(x)) { model.terms <- lapply(model.terms, .clean_brms_mm) rs <- setdiff(unname(unlist(find_random_slopes(x))), unname(unlist(model.terms))) if (!.is_empty_object(rs)) model.terms$random <- c(rs, model.terms$random) } .return_data( x, .prepare_get_data(x, mf, effects = effects), effects, component, model.terms, is_mv = is_multivariate(x) ) } #' @rdname get_data #' @export get_data.stanreg <- function(x, effects = c("all", "fixed", "random"), ...) { effects <- match.arg(effects) model.terms <- find_variables(x, effects = "all", component = "all", flatten = FALSE) mf <- stats::model.frame(x) .return_data( x, .prepare_get_data(x, mf, effects = effects), effects, component = "all", model.terms, is_mv = is_multivariate(x) ) } #' @export get_data.BFBayesFactor <- function(x, ...) { x@data } #' @rdname get_data #' @export get_data.MCMCglmm <- function(x, effects = c("all", "fixed", "random"), ...) { effects <- match.arg(effects) mf <- tryCatch( { env_dataframes <- names(which(unlist(eapply(.GlobalEnv, is.data.frame)))) pv <- find_predictors(x, effects = effects, component = "all", flatten = TRUE) matchframe <- unlist(lapply(env_dataframes, function(.x) { dat <- get(.x) all(pv %in% colnames(dat)) })) mf <- env_dataframes[matchframe][1] if (!is.na(mf)) { dat <- get(mf) switch( effects, fixed = dat[, setdiff(colnames(dat), find_random(x, flatten = T)), drop = FALSE], all = dat, random = dat[, find_random(x, flatten = TRUE), drop = FALSE] ) } else { NULL } }, error = function(x) { NULL } ) .prepare_get_data(x, mf, effects = effects) } #' @export get_data.stanmvreg <- function(x, ...) { mf <- tryCatch( { out <- data.frame() for (i in stats::model.frame(x)) { out <- .merge_dataframes(out, i) } out }, error = function(x) { NULL } ) .prepare_get_data(x, mf) } # other models ------------------------------------------------------ #' @export get_data.DirichletRegModel <- function(x, ...) { mf <- x$data resp <- sapply(x$data, inherits, "DirichletRegData") .prepare_get_data(x, mf[!resp]) } #' @export get_data.vglm <- function(x, ...) { mf <- tryCatch( { if (!length(x@model)) { env <- environment(x@terms$terms) if (is.null(env)) env <- parent.frame() fcall <- x@call fcall$method <- "model.frame" fcall$smart <- FALSE eval(fcall, env, parent.frame()) } else { x@model } }, error = function(x) { NULL } ) .prepare_get_data(x, mf) } #' @export get_data.biglm <- function(x, ...) { mf <- stats::model.frame(x) .prepare_get_data(x, mf) } #' @export get_data.bigglm <- get_data.biglm #' @export get_data.LORgee <- function(x, effects = c("all", "fixed", "random"), ...) { effects <- match.arg(effects) mf <- tryCatch( { dat <- .get_data_from_env(x)[, find_variables(x, flatten = TRUE), drop = FALSE] switch( effects, all = dat[, find_variables(x, flatten = TRUE), drop = FALSE], fixed = dat[, find_variables(x, effects = "fixed", flatten = TRUE), drop = FALSE], random = dat[, find_random(x, flatten = TRUE), drop = FALSE] ) }, error = function(x) { stats::model.frame(x) } ) .prepare_get_data(x, stats::na.omit(mf)) } #' @export get_data.gmnl <- function(x, ...) { mf <- tryCatch( { x$mf }, error = function(x) { NULL } ) .prepare_get_data(x, mf) } #' @export get_data.gbm <- function(x, ...) { mf <- tryCatch( { get(.safe_deparse(x$call$data), envir = parent.frame())[, find_variables(x, flatten = TRUE), drop = FALSE] }, error = function(x) { stats::model.frame(x) } ) .get_data_from_modelframe(x, mf, effects = "all") } #' @export get_data.tobit <- function(x, ...) { dat <- .get_data_from_env(x) ft <- find_variables(x, flatten = TRUE) remain <- intersect(ft, colnames(dat)) .prepare_get_data(x, stats::na.omit(dat[, remain, drop = FALSE])) } #' @export get_data.clmm2 <- function(x, ...) { mf <- tryCatch( { data_complete <- x$location data_scale <- x$scale if (!is.null(data_scale)) { remain <- setdiff(colnames(data_scale), colnames(data_complete)) if (length(remain)) data_complete <- cbind(data_complete, data_scale[, remain, drop = FALSE]) } data_complete <- cbind(data_complete, x$grFac) colnames(data_complete)[ncol(data_complete)] <- unlist(.find_random_effects(x, f = find_formula(x), split_nested = TRUE)) data_complete }, error = function(x) { NULL } ) .prepare_get_data(x, mf) } #' @export get_data.clm2 <- function(x, ...) { mf <- tryCatch( { data_complete <- x$location data_scale <- x$scale if (!is.null(data_scale)) { remain <- setdiff(colnames(data_scale), colnames(data_complete)) if (length(remain)) data_complete <- cbind(data_complete, data_scale[, remain, drop = FALSE]) } data_complete }, error = function(x) { NULL } ) .prepare_get_data(x, mf) } #' @export get_data.bracl <- function(x, ...) { mf <- stats::model.frame(x) suppressWarnings(.prepare_get_data(x, mf)) } #' @export get_data.rma <- function(x, ...) { mf <- tryCatch( { .get_data_from_env(x) }, error = function(x) { NULL } ) .prepare_get_data(x, stats::na.omit(mf)) } insight/R/get_parameters.R0000644000176200001440000011233013615254727015261 0ustar liggesusers#' @title Get model parameters #' @name get_parameters #' #' @description Returns the coefficients (or posterior samples for Bayesian #' models) from a model. #' #' @param iterations Number of posterior draws. #' @param progress Display progress. #' @param ... Currently not used. #' #' @inheritParams find_parameters #' @inheritParams find_predictors #' #' @return \itemize{ #' \item for non-Bayesian models and if \code{effects = "fixed"}, a data frame with two columns: the parameter names and the related point estimates #' \item if \code{effects = "random"}, a list of data frames with the random effects (as returned by \code{ranef()}), unless the random effects have the same simplified structure as fixed effects (e.g. for models from \pkg{MCMCglmm}) #' \item for Bayesian models, the posterior samples from the requested parameters as data frame #' \item for Anova (\code{aov()}) with error term, a list of parameters for the conditional and the random effects parameters #' \item for models with smooth terms or zero-inflation component, a data frame with three columns: the parameter names, the related point estimates and the component #' } #' #' @details In most cases when models either return different "effects" (fixed, #' random) or "components" (conditional, zero-inflated, ...), the arguments #' \code{effects} and \code{component} can be used. #' \cr \cr #' \code{get_parameters()} is comparable to \code{coef()}, however, the coefficients #' are returned as data frame (with columns for names and point estimates of #' coefficients). For Bayesian models, the posterior samples of parameters are #' returned. #' #' @examples #' data(mtcars) #' m <- lm(mpg ~ wt + cyl + vs, data = mtcars) #' get_parameters(m) #' @importFrom stats coef #' @export get_parameters <- function(x, ...) { UseMethod("get_parameters") } # Default models --------------------------------------------- #' @export get_parameters.default <- function(x, ...) { if (inherits(x, "list") && .obj_has_name(x, "gam")) { x <- x$gam class(x) <- c(class(x), c("glm", "lm")) return(get_parameters.gam(x, ...)) } tryCatch( { cf <- stats::coef(x) params <- data.frame( Parameter = names(cf), Estimate = unname(cf), stringsAsFactors = FALSE, row.names = NULL ) .remove_backticks_from_parameter_names(params) }, error = function(x) { print_color(sprintf("Parameters can't be retrieved for objects of class '%s'.\n", class(x)[1]), "red") NULL } ) } #' @export get_parameters.data.frame <- function(x, ...) { stop("A data frame is no valid object for this function") } # Survival and censored models --------------------------------------------- #' @export get_parameters.flexsurvreg <- function(x, ...) { cf <- stats::coef(x) params <- data.frame( Parameter = names(cf), Estimate = unname(cf), stringsAsFactors = FALSE, row.names = NULL ) .remove_backticks_from_parameter_names(params) } #' @export get_parameters.aareg <- function(x, ...) { sc <- summary(x) params <- data.frame( Parameter = rownames(sc$table), Estimate = unname(sc$table[, 2]), stringsAsFactors = FALSE, row.names = NULL ) .remove_backticks_from_parameter_names(params) } #' @export get_parameters.crq <- function(x, ...) { sc <- summary(x) if (all(lapply(sc, is.list))) { list_sc <- lapply(sc, function(i) { .x <- as.data.frame(i) .x$Parameter <- rownames(.x) .x }) out <- do.call(rbind, list_sc) params <- data.frame( Parameter = out$Parameter, Estimate = out$coefficients.Value, Component = sprintf("tau (%g)", out$tau), stringsAsFactors = FALSE, row.names = NULL ) } else { params <- data.frame( Parameter = names(sc$coefficients[, 1]), Estimate = unname(sc$coefficients[, 1]), stringsAsFactors = FALSE, row.names = NULL ) } .remove_backticks_from_parameter_names(params) } #' @export get_parameters.crqs <- get_parameters.crq #' @importFrom stats setNames #' @rdname get_parameters #' @export get_parameters.rqss <- function(x, component = c("all", "conditional", "smooth_terms"), ...) { component <- match.arg(component) sc <- summary(x) smooth_terms <- sc$qsstab[, 3] names(smooth_terms) <- rownames(sc$qsstab) .return_smooth_parms( conditional = stats::setNames(sc$coef[, 1], rownames(sc$coef)), smooth_terms = smooth_terms, component = component ) } #' @importFrom stats setNames #' @rdname get_parameters #' @export get_parameters.cgam <- function(x, component = c("all", "conditional", "smooth_terms"), ...) { component <- match.arg(component) sc <- summary(x) estimates <- sc$coefficients smooth_terms <- sc$coefficients2 if (!is.null(smooth_terms)) smooth_terms <- stats::setNames(smooth_terms[, 1], rownames(smooth_terms)) .return_smooth_parms( conditional = stats::setNames(estimates[, 1], rownames(estimates)), smooth_terms = smooth_terms, component = component ) } # Special models --------------------------------------------- #' @export get_parameters.lrm <- function(x, ...) { tryCatch( { cf <- stats::coef(x) params <- data.frame( Parameter = names(cf), Estimate = unname(cf), stringsAsFactors = FALSE, row.names = NULL ) .remove_backticks_from_parameter_names(params) }, error = function(x) { NULL } ) } #' @export get_parameters.multinom <- function(x, ...) { params <- stats::coef(x) if (is.matrix(params)) { out <- data.frame() for (i in 1:nrow(params)) { out <- rbind(out, data.frame( Parameter = colnames(params), Estimate = unname(params[i, ]), Response = rownames(params)[i], stringsAsFactors = FALSE, row.names = NULL )) } } else { out <- data.frame( Parameter = names(params), Estimate = unname(params), stringsAsFactors = FALSE, row.names = NULL ) } .remove_backticks_from_parameter_names(out) } #' @export get_parameters.brmultinom <- get_parameters.multinom #' @export get_parameters.glmx <- function(x, component = c("all", "conditional", "extra"), ...) { component <- match.arg(component) cf <- stats::coef(summary(x)) params <- rbind( data.frame( Parameter = names(cf$glm[, 1]), Estimate = unname(cf$glm[, 1]), Component = "conditional", stringsAsFactors = FALSE, row.names = NULL ), data.frame( Parameter = rownames(cf$extra), Estimate = cf$extra[, 1], Component = "extra", stringsAsFactors = FALSE, row.names = NULL ) ) if (component != "all") { params <- params[params$Component == component, ] } .remove_backticks_from_parameter_names(params) } #' @export get_parameters.mlm <- function(x, ...) { cs <- stats::coef(summary(x)) out <- lapply(names(cs), function(i) { params <- data.frame( Parameter = rownames(cs[[i]]), Estimate = cs[[i]][, 1], Response = gsub("^Response (.*)", "\\1", i), stringsAsFactors = FALSE, row.names = NULL ) .remove_backticks_from_parameter_names(params) }) do.call(rbind, out) } #' @export get_parameters.gbm <- function(x, ...) { s <- summary(x, plotit = FALSE) params <- data.frame( Parameter = as.character(s$var), Estimate = s$rel.inf, stringsAsFactors = FALSE, row.names = NULL ) .remove_backticks_from_parameter_names(params) } #' @rdname get_parameters #' @export get_parameters.betareg <- function(x, component = c("all", "conditional", "precision"), ...) { component <- match.arg(component) cf <- stats::coef(x) params <- data.frame( Parameter = names(cf), Estimate = unname(cf), Component = c(rep("conditional", length(x$coefficients$mean)), rep("precision", length(x$coefficients$precision))), stringsAsFactors = FALSE, row.names = NULL ) if (component != "all") { params <- params[params$Component == component, ] } .remove_backticks_from_parameter_names(params) } #' @rdname get_parameters #' @export get_parameters.DirichletRegModel <- function(x, component = c("all", "conditional", "precision"), ...) { component <- match.arg(component) cf <- stats::coef(x) if (x$parametrization == "common") { component <- "all" n_comp <- lapply(cf, length) pattern <- paste0("(", paste(x$varnames, collapse = "|"), ")\\.(.*)") p_names <- gsub(pattern, "\\2", names(unlist(cf))) params <- data.frame( Parameter = p_names, Estimate = unname(unlist(cf)), Response = rep(names(n_comp), sapply(n_comp, function(i) i)), stringsAsFactors = FALSE, row.names = NULL ) } else { out1 <- .gather(data.frame(do.call(cbind, cf$beta)), names_to = "Response", values_to = "Estimate") out2 <- .gather(data.frame(do.call(cbind, cf$gamma)), names_to = "Component", values_to = "Estimate") out1$Component <- "conditional" out2$Component <- "precision" out2$Response <- NA params <- merge(out1, out2, all = TRUE, sort = FALSE) params$Parameter <- gsub("(.*)\\.(.*)\\.(.*)", "\\3", names(unlist(cf))) params <- params[c("Parameter", "Estimate", "Component", "Response")] } if (component != "all") { params <- params[params$Component == component, ] } .remove_backticks_from_parameter_names(params) } #' @export get_parameters.BBreg <- function(x, ...) { pars <- summary(x)$coefficients params <- data.frame( Parameter = rownames(pars), Estimate = pars[, "Estimate"], stringsAsFactors = FALSE, row.names = NULL ) .remove_backticks_from_parameter_names(params) } #' @export get_parameters.rma <- function(x, ...) { tryCatch( { cf <- stats::coef(x) params <- data.frame( Parameter = names(cf), Estimate = unname(cf), stringsAsFactors = FALSE, row.names = NULL ) params$Parameter[grepl("intrcpt", params$Parameter)] <- "(Intercept)" .remove_backticks_from_parameter_names(params) }, error = function(x) { NULL } ) } # SEM models --------------------------------------------- #' @export get_parameters.blavaan <- function(x, ...) { if (!requireNamespace("lavaan", quietly = TRUE)) { stop("Package 'lavaan' required for this function to work. Please install it.") } if (!requireNamespace("blavaan", quietly = TRUE)) { stop("Package 'blavaan' required for this function to work. Please install it.") } draws <- blavaan::blavInspect(x, "draws") posteriors <- as.data.frame(as.matrix(draws)) names(posteriors) <- names(lavaan::coef(x)) posteriors } #' @export get_parameters.lavaan <- function(x, ...) { if (!requireNamespace("lavaan", quietly = TRUE)) { stop("Package 'lavaan' required for this function to work. Please install it.") } params <- lavaan::parameterEstimates(x) params$parameter <- paste0(params$lhs, params$op, params$rhs) params$comp <- NA params$comp[params$op == "~"] <- "regression" params$comp[params$op == "=~"] <- "latent" params$comp[params$op == "~~"] <- "residual" params$comp[params$op == "~1"] <- "intercept" params <- data.frame( Parameter = params$parameter, Estimate = params$est, Component = params$comp, stringsAsFactors = FALSE ) .remove_backticks_from_parameter_names(params) } # Ordinal models --------------------------------------------- #' @export get_parameters.polr <- function(x, ...) { pars <- c(sprintf("Intercept: %s", names(x$zeta)), names(x$coefficients)) params <- data.frame( Parameter = pars, Estimate = c(unname(x$zeta), unname(x$coefficients)), stringsAsFactors = FALSE, row.names = NULL ) .remove_backticks_from_parameter_names(params) } #' @export get_parameters.bracl <- function(x, ...) { pars <- stats::coef(x) params <- data.frame( Parameter = names(pars), Estimate = unname(pars), Response = gsub("(.*):(.*)", "\\1", names(pars)), stringsAsFactors = FALSE, row.names = NULL ) .remove_backticks_from_parameter_names(params) } #' @rdname get_parameters #' @export get_parameters.clm2 <- function(x, component = c("all", "conditional", "scale"), ...) { component <- match.arg(component) cf <- stats::coef(summary(x)) n_intercepts <- length(x$xi) n_location <- length(x$beta) n_scale <- length(x$zeta) params <- data.frame( Parameter = rownames(cf), Estimate = unname(cf[, "Estimate"]), Component = c(rep("conditional", times = n_intercepts + n_location), rep("scale", times = n_scale)), stringsAsFactors = FALSE, row.names = NULL ) if (component != "all") { params <- params[params$Component == component, ] } .remove_backticks_from_parameter_names(params) } # Mixed models --------------------------------------------- #' @export get_parameters.clmm2 <- get_parameters.clm2 #' @rdname get_parameters #' @export get_parameters.coxme <- function(x, effects = c("fixed", "random"), ...) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("To use this function, please install package 'lme4'.") } effects <- match.arg(effects) if (effects == "fixed") { l <- list(conditional = lme4::fixef(x)) } else { l <- .compact_list(list( conditional = lme4::fixef(x), random = lme4::ranef(x) )) } fixed <- data.frame( Parameter = names(l$conditional), Estimate = unname(l$conditional), stringsAsFactors = FALSE ) if (effects == "fixed") { .remove_backticks_from_parameter_names(fixed) } else { l$random } } #' @export get_parameters.wbm <- function(x, effects = c("fixed", "random"), ...) { effects <- match.arg(effects) if (effects == "fixed") { s <- summary(x) terms <- c( rownames(s$within_table), rownames(s$between_table), rownames(s$ints_table) ) wt <- s$within_table bt <- s$between_table it <- s$ints_table if (!is.null(wt)) { wt <- data.frame(params = wt, component = "within", stringsAsFactors = FALSE) } if (!is.null(bt)) { bt <- data.frame(params = bt, component = "between", stringsAsFactors = FALSE) } if (!is.null(it)) { it <- data.frame(params = it, component = "interactions", stringsAsFactors = FALSE) } params <- rbind(wt, bt, it) out <- data.frame( Parameter = terms, Estimate = params[[1]], Component = params[["component"]], stringsAsFactors = FALSE ) .remove_backticks_from_parameter_names(out) } else { if (!requireNamespace("lme4", quietly = TRUE)) { stop("To use this function, please install package 'lme4'.") } lme4::ranef(x) } } #' @export get_parameters.wbgee <- function(x, ...) { get_parameters.wbm(x, effects = "fixed") } #' @export get_parameters.nlmerMod <- function(x, effects = c("fixed", "random"), ...) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("To use this function, please install package 'lme4'.") } effects <- match.arg(effects) startvectors <- .get_startvector_from_env(x) fx <- lme4::fixef(x) if (effects == "fixed") { l <- .compact_list(list( conditional = fx[setdiff(names(fx), startvectors)], nonlinear = fx[startvectors] )) } else { l <- .compact_list(list( conditional = fx[setdiff(names(fx), startvectors)], nonlinear = fx[startvectors], random = lapply(lme4::ranef(x), colnames) )) } fixed <- data.frame( Parameter = c( names(l$conditional), names(l$nonlinear) ), Estimate = c(unname(l$conditional), unname(l$nonlinear)), Component = c( rep("fixed", length(l$conditional)), rep("nonlinear", length(l$nonlinear)) ), stringsAsFactors = FALSE ) if (effects == "fixed") { .remove_backticks_from_parameter_names(fixed) } else { l$random } } #' @rdname get_parameters #' @export get_parameters.merMod <- function(x, effects = c("fixed", "random"), ...) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("To use this function, please install package 'lme4'.") } effects <- match.arg(effects) if (effects == "fixed") { l <- list(conditional = lme4::fixef(x)) } else { l <- .compact_list(list( conditional = lme4::fixef(x), random = lme4::ranef(x) )) } fixed <- data.frame( Parameter = names(l$conditional), Estimate = unname(l$conditional), stringsAsFactors = FALSE ) if (effects == "fixed") { .remove_backticks_from_parameter_names(fixed) } else { l$random } } #' @export get_parameters.rlmerMod <- get_parameters.merMod #' @export get_parameters.glmmadmb <- get_parameters.merMod #' @rdname get_parameters #' @export get_parameters.lme <- get_parameters.merMod #' @export get_parameters.cpglmm <- function(x, effects = c("fixed", "random"), ...) { if (!requireNamespace("cplm", quietly = TRUE)) { stop("To use this function, please install package 'cplm'.") } effects <- match.arg(effects) if (effects == "fixed") { l <- list(conditional = cplm::fixef(x)) } else { l <- .compact_list(list( conditional = cplm::fixef(x), random = cplm::ranef(x) )) } fixed <- data.frame( Parameter = names(l$conditional), Estimate = unname(l$conditional), stringsAsFactors = FALSE ) if (effects == "fixed") { .remove_backticks_from_parameter_names(fixed) } else { l$random } } #' @rdname get_parameters #' @export get_parameters.mixed <- function(x, effects = c("fixed", "random"), ...) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("To use this function, please install package 'lme4'.") } effects <- match.arg(effects) if (effects == "fixed") { l <- list(conditional = lme4::fixef(x$full_model)) } else { l <- .compact_list(list( conditional = lme4::fixef(x$full_model), random = lme4::ranef(x$full_model) )) } fixed <- data.frame( Parameter = names(l$conditional), Estimate = unname(l$conditional), stringsAsFactors = FALSE ) if (effects == "fixed") { .remove_backticks_from_parameter_names(fixed) } else { l$random } } #' @rdname get_parameters #' @export get_parameters.MixMod <- function(x, effects = c("fixed", "random"), component = c("all", "conditional", "zi", "zero_inflated", "dispersion"), ...) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("To use this function, please install package 'lme4'.") } effects <- match.arg(effects) component <- match.arg(component) has_zeroinf <- !is.null(find_formula(x)[["zero_inflated"]]) if (component %in% c("zi", "zero_inflated") && !has_zeroinf) { stop("Model has no zero-inflation component.", call. = FALSE) } re.names <- dimnames(lme4::ranef(x))[[2]] re <- lme4::ranef(x) if (has_zeroinf) { z_inflated <- lme4::fixef(x, sub_model = "zero_part") z_inflated_random <- re[grepl("^zi_", re.names, perl = TRUE)] } else { z_inflated <- NULL z_inflated_random <- NULL component <- "conditional" } l <- .compact_list(list( conditional = lme4::fixef(x, sub_model = "main"), random = re[grepl("^(?!zi_)", re.names, perl = TRUE)], zero_inflated = z_inflated, zero_inflated_random = z_inflated_random )) fixed <- data.frame( Parameter = names(l$conditional), Estimate = unname(l$conditional), Component = "conditional", stringsAsFactors = FALSE ) if (has_zeroinf) { fixedzi <- data.frame( Parameter = names(l$zero_inflated), Estimate = unname(l$zero_inflated), Component = "zero_inflated", stringsAsFactors = FALSE ) } else { fixedzi <- NULL } if (effects == "fixed") { params <- switch( component, all = rbind(fixed, fixedzi), conditional = fixed, zi = , zero_inflated = fixedzi ) .remove_backticks_from_parameter_names(params) } else if (effects == "random") { switch( component, all = .compact_list(list(random = l$random, zero_inflated_random = l$zero_inflated_random)), conditional = list(random = l$random), zi = , zero_inflated = list(zero_inflated_random = l$zero_inflated_random) ) } } #' @rdname get_parameters #' @export get_parameters.glmmTMB <- function(x, effects = c("fixed", "random"), component = c("all", "conditional", "zi", "zero_inflated", "dispersion"), ...) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("To use this function, please install package 'lme4'.") } effects <- match.arg(effects) component <- match.arg(component) if (effects == "fixed") { l <- .compact_list(list( conditional = lme4::fixef(x)$cond, zero_inflated = lme4::fixef(x)$zi, dispersion = lme4::fixef(x)$disp )) } else { l <- .compact_list(list( conditional = lme4::fixef(x)$cond, random = lme4::ranef(x)$cond, zero_inflated = lme4::fixef(x)$zi, zero_inflated_random = lme4::ranef(x)$zi, dispersion = lme4::fixef(x)$disp )) } fixed <- data.frame( Parameter = names(l$conditional), Estimate = unname(l$conditional), Component = "conditional", stringsAsFactors = FALSE ) if (.obj_has_name(l, "zero_inflated")) { fixedzi <- data.frame( Parameter = names(l$zero_inflated), Estimate = unname(l$zero_inflated), Component = "zero_inflated", stringsAsFactors = FALSE ) } else { fixedzi <- NULL } if (effects == "fixed") { out <- switch( component, all = rbind(fixed, fixedzi), conditional = fixed, zi = , zero_inflated = fixedzi ) .remove_backticks_from_parameter_names(out) } else if (effects == "random") { switch( component, all = .compact_list(list(random = l$random, zero_inflated_random = l$zero_inflated_random)), conditional = l$random, zi = , zero_inflated = l$zero_inflated_random ) } } #' @export get_parameters.mixor <- function(x, effects = c("all", "fixed", "random"), ...) { coefs <- stats::coef(x) effects <- match.arg(effects) params <- find_parameters(x, effects = "fixed", flatten = TRUE) fixed <- data.frame( Parameter = params, Estimate = unname(coefs[params]), Effects = "fixed", stringsAsFactors = FALSE ) if (effects != "fixed") { params <- find_parameters(x, effects = "random", flatten = TRUE) random <- data.frame( Parameter = params, Estimate = unname(coefs[params]), Effects = "random", stringsAsFactors = FALSE ) } else { random <- NULL } switch( effects, "all" = rbind(fixed, random), "fixed" = fixed, "random" = random ) } #' @rdname get_parameters #' @export get_parameters.BBmm <- function(x, effects = c("fixed", "random"), ...) { effects <- match.arg(effects) l <- .compact_list(list( conditional = x$fixed.coef, random = x$random.coef )) fixed <- data.frame( Parameter = rownames(l$conditional), Estimate = l$conditional, stringsAsFactors = FALSE, row.names = NULL ) if (effects == "fixed") { .remove_backticks_from_parameter_names(fixed) } else { l$random } } #' @rdname get_parameters #' @export get_parameters.glimML <- function(x, effects = c("fixed", "random", "all"), ...) { effects <- match.arg(effects) l <- .compact_list(list( conditional = x@fixed.param, random = x@random.param )) fixed <- data.frame( Parameter = names(l$conditional), Estimate = l$conditional, stringsAsFactors = FALSE, row.names = NULL ) fixed <- .remove_backticks_from_parameter_names(fixed) random <- data.frame( Parameter = names(l$random), Estimate = l$random, stringsAsFactors = FALSE, row.names = NULL ) random <- .remove_backticks_from_parameter_names(random) all <- rbind( cbind(fixed, data.frame(Effects = "fixed", stringsAsFactors = FALSE)), cbind(random, data.frame(Effects = "random", stringsAsFactors = FALSE)) ) if (effects == "fixed") { fixed } else if (effects == "random") { random } else { all } } # GAM models --------------------------------------------- #' @rdname get_parameters #' @export get_parameters.gamm <- function(x, component = c("all", "conditional", "smooth_terms"), ...) { x <- x$gam class(x) <- c(class(x), c("glm", "lm")) get_parameters.gam(x, component, ...) } #' @rdname get_parameters #' @export get_parameters.Gam <- function(x, component = c("all", "conditional", "smooth_terms"), ...) { component <- match.arg(component) pars <- stats::coef(x) .return_smooth_parms( conditional = pars[.grep_non_smoothers(names(pars))], smooth_terms = pars[.grep_smoothers(names(pars))], component = component ) } #' @rdname get_parameters #' @export get_parameters.gam <- function(x, component = c("all", "conditional", "smooth_terms"), ...) { component <- match.arg(component) pars <- stats::coef(x) st <- summary(x)$s.table smooth_terms <- st[, 1] names(smooth_terms) <- row.names(st) .return_smooth_parms( conditional = pars[.grep_non_smoothers(names(pars))], smooth_terms = smooth_terms, component = component ) } #' @rdname get_parameters #' @export get_parameters.vgam <- function(x, component = c("all", "conditional", "smooth_terms"), ...) { component <- match.arg(component) pars <- stats::coef(x) .return_smooth_parms( conditional = pars[.grep_non_smoothers(names(pars))], smooth_terms = pars[.grep_smoothers(names(pars))], component = component ) } #' @importFrom stats na.omit #' @export get_parameters.gamlss <- function(x, ...) { pars <- lapply(x$parameters, function(i) { stats::na.omit(stats::coef(x, what = i)) }) names(pars) <- x$parameters if ("mu" %in% names(pars)) names(pars)[1] <- "conditional" do.call(rbind, lapply(names(pars), function(i) { params <- data.frame( Parameter = names(pars[[i]]), Estimate = pars[[i]], Component = i, stringsAsFactors = FALSE, row.names = NULL ) .remove_backticks_from_parameter_names(params) })) # data.frame( # Parameter = c(names(pars$conditional), names(pars$sigma), names(pars$nu), names(pars$tau)), # Estimate = c(unname(pars$conditional), unname(pars$sigma), unname(pars$nu), unname(pars$tau)), # Component = c( # rep("conditional", length(pars$conditional)), # rep("sigma", length(pars$sigma)), # rep("nu", length(pars$nu)), # rep("tau", length(pars$tau)) # ), # stringsAsFactors = FALSE, # row.names = NULL # ) } # Zero-Inflated models ------------------------------------- #' @rdname get_parameters #' @export get_parameters.zeroinfl <- function(x, component = c("all", "conditional", "zi", "zero_inflated"), ...) { component <- match.arg(component) .return_zeroinf_parms(x, component) } #' @export get_parameters.hurdle <- get_parameters.zeroinfl #' @export get_parameters.zerotrunc <- get_parameters.default # Standard models -------------------------------------------------- #' @export get_parameters.aov <- function(x, ...) { cf <- stats::coef(x) params <- data.frame( Parameter = names(cf), Estimate = unname(cf), stringsAsFactors = FALSE, row.names = NULL ) .remove_backticks_from_parameter_names(params) } #' @rdname get_parameters #' @export get_parameters.aovlist <- function(x, effects = c("fixed", "random", "all"), ...) { effects <- match.arg(effects) l <- lapply(stats::coef(x), function(i) { params <- data.frame( Parameter = names(i), Estimate = unname(i), stringsAsFactors = FALSE ) .remove_backticks_from_parameter_names(params) }) l <- list(rbind(l[[1]], l[[2]]), l[[3]]) names(l) <- c("conditional", "random") all <- rbind( cbind(l$conditional, data.frame(Effects = "fixed", stringsAsFactors = FALSE)), cbind(l$random, data.frame(Effects = "random", stringsAsFactors = FALSE)) ) if (effects == "fixed") { l$conditional } else if (effects == "random") { l$random } else { all } } # Bayesian models ------------------------------------- #' @rdname get_parameters #' @export get_parameters.MCMCglmm <- function(x, effects = c("fixed", "random", "all"), ...) { effects <- match.arg(effects) sc <- summary(x) l <- .compact_list(list( conditional = sc$solutions[, 1], random = sc$Gcovariances[, 1] )) names(l$conditional) <- rownames(sc$solutions) names(l$random) <- rownames(sc$Gcovariances) fixed <- data.frame( Parameter = names(l$conditional), Estimate = unname(l$conditional), stringsAsFactors = FALSE ) fixed <- .remove_backticks_from_parameter_names(fixed) random <- data.frame( Parameter = names(l$random), Estimate = unname(l$random), stringsAsFactors = FALSE ) random <- .remove_backticks_from_parameter_names(random) all <- rbind( cbind(fixed, data.frame(Effects = "fixed", stringsAsFactors = FALSE)), cbind(random, data.frame(Effects = "random", stringsAsFactors = FALSE)) ) if (effects == "fixed") { fixed } else if (effects == "random") { random } else { all } } #' @rdname get_parameters #' @export get_parameters.BFBayesFactor <- function(x, effects = c("all", "fixed", "random"), component = c("all", "extra"), iterations = 4000, progress = FALSE, ...) { if (!requireNamespace("BayesFactor", quietly = TRUE)) { stop("This function requires package `BayesFactor` to work. Please install it.") } effects <- match.arg(effects) component <- match.arg(component) bf_type <- .classify_BFBayesFactor(x) params <- find_parameters(x, effects = effects, component = component, flatten = TRUE) if (bf_type %in% c("correlation", "ttest", "meta", "linear")) { posteriors <- as.data.frame(suppressMessages( BayesFactor::posterior(x, iterations = iterations, progress = progress, index = 1, ...) )) switch( bf_type, "correlation" = data.frame("rho" = as.numeric(posteriors$rho)), "ttest" = data.frame("Difference" = as.numeric(posteriors[, 2])), "meta" = data.frame("Effect" = as.numeric(posteriors$delta)), "linear" = .get_bf_posteriors(posteriors, params), NULL ) } else { NULL } } #' @rdname get_parameters #' @export get_parameters.stanmvreg <- function(x, effects = c("fixed", "random", "all"), parameters = NULL, ...) { effects <- match.arg(effects) elements <- .get_elements(effects, "all") parms <- find_parameters(x, flatten = FALSE, parameters = parameters) for (i in names(parms)) { parms[[i]]$conditional <- sprintf("%s|%s", i, parms[[i]]$conditional) find_bracket <- regexpr(pattern = "\\[", parms[[i]]$random) parms[[i]]$random <- paste0( substr(parms[[i]]$random, start = 1, stop = find_bracket), i, "|", substr(parms[[i]]$random, start = find_bracket + 1, stop = 1000000L) ) parms[[i]]$sigma <- NULL } as.data.frame(x)[unlist(lapply(.compact_list(parms), function(i) i[elements]))] } #' @rdname get_parameters #' @export get_parameters.brmsfit <- function(x, effects = c("fixed", "random", "all"), component = c("all", "conditional", "zi", "zero_inflated", "dispersion", "simplex", "sigma", "smooth_terms"), parameters = NULL, ...) { effects <- match.arg(effects) component <- match.arg(component) if (is_multivariate(x)) { parms <- find_parameters(x, flatten = FALSE, parameters = parameters) elements <- .get_elements(effects, component) ## TODO remove "optional = FALSE" in a future update as.data.frame(x, optional = FALSE)[unlist(lapply(parms, function(i) i[elements]))] } else { ## TODO remove "optional = FALSE" in a future update as.data.frame(x, optional = FALSE)[.get_parms_data(x, effects, component, parameters)] } } #' @rdname get_parameters #' @export get_parameters.stanreg <- function(x, effects = c("fixed", "random", "all"), parameters = NULL, ...) { effects <- match.arg(effects) as.data.frame(x)[.get_parms_data(x, effects, "all", parameters)] } #' @importFrom stats coef #' @rdname find_parameters #' @export get_parameters.bayesx <- function(x, component = c("all", "conditional", "smooth_terms"), flatten = FALSE, parameters = NULL, ...) { component <- match.arg(component) smooth_terms <- find_parameters(x, component = "smooth_terms", flatten = TRUE) fixed_dat <- attr(x$fixed.effects, "sample") smooth_dat <- do.call(cbind, lapply(smooth_terms, function(i) { dat <- data.frame(x$effects[[i]]$Mean) colnames(dat) <- i dat })) switch( component, "all" = cbind(fixed_dat, smooth_dat), "conditional" = fixed_dat, "smooth_terms" = smooth_dat ) } # simulations --------------------------------- #' @rdname get_parameters #' @export get_parameters.sim.merMod <- function(x, effects = c("fixed", "random", "all"), parameters = NULL, ...) { effects <- match.arg(effects) fe <- re <- NULL if (effects %in% c("fixed", "all")) fe <- .get_armsim_fixef_parms(x) if (effects %in% c("random", "all")) re <- .get_armsim_ranef_parms(x) dat <- do.call(cbind, .compact_list(list(fe, re))) as.data.frame(dat)[.get_parms_data(x, effects, "all", parameters)] } #' @export get_parameters.sim <- function(x, parameters = NULL, ...) { dat <- .get_armsim_fixef_parms(x) as.data.frame(dat)[.get_parms_data(x, "all", "all", parameters)] } #' @export get_parameters.mcmc <- function(x, parameters = NULL, ...) { as.data.frame(x)[.get_parms_data(x, "all", "all", parameters)] } # utility functions --------------------------------- .get_parms_data <- function(x, effects, component, parameters = NULL) { elements <- .get_elements(effects, component) unlist(find_parameters(x, flatten = FALSE, parameters = parameters)[elements]) } .return_zeroinf_parms <- function(x, component) { cf <- stats::coef(x) conditional <- grepl("^count_", names(cf), perl = TRUE) zero_inflated <- grepl("^zero_", names(cf), perl = TRUE) cond <- data.frame( Parameter = names(cf)[conditional], Estimate = unname(cf)[conditional], Component = "conditional", stringsAsFactors = FALSE, row.names = NULL ) zi <- data.frame( Parameter = names(cf)[zero_inflated], Estimate = unname(cf)[zero_inflated], Component = "zero_inflated", stringsAsFactors = FALSE, row.names = NULL ) pars <- switch( component, all = rbind(cond, zi), conditional = cond, zi = , zero_inflated = zi ) if (component != "all") { pars <- .remove_column(pars, "Component") } .remove_backticks_from_parameter_names(pars) } .return_smooth_parms <- function(conditional, smooth_terms, component) { cond <- data.frame( Parameter = names(conditional), Estimate = conditional, Component = "conditional", stringsAsFactors = FALSE, row.names = NULL ) if (!is.null(smooth_terms)) { smooth <- data.frame( Parameter = names(smooth_terms), Estimate = smooth_terms, Component = "smooth_terms", stringsAsFactors = FALSE, row.names = NULL ) } else { smooth <- NULL } pars <- switch( component, all = rbind(cond, smooth), conditional = cond, smooth_terms = smooth ) if (component != "all") { pars <- .remove_column(pars, "Component") } .remove_backticks_from_parameter_names(pars) } #' @importFrom methods slot slotNames .get_armsim_fixef_parms <- function(x) { sn <- methods::slotNames(x) as.data.frame(methods::slot(x, sn[1])) } #' @importFrom methods .hasSlot .get_armsim_ranef_parms <- function(x) { dat <- NULL if (methods::.hasSlot(x, "ranef")) { re <- x@ranef dat <- data.frame() for (i in 1:length(re)) { dn <- dimnames(re[[i]])[[2]] cn <- dimnames(re[[i]])[[3]] l <- lapply(1:length(dn), function(j) { d <- as.data.frame(re[[i]][, j, ]) colnames(d) <- sprintf("%s.%s", cn, dn[j]) d }) if (ncol(dat) == 0) { dat <- do.call(cbind, l) } else { dat <- cbind(dat, do.call(cbind, l)) } } } dat } .get_bf_posteriors <- function(posteriors, params) { cn <- intersect(colnames(posteriors), params) posteriors[, cn, drop = FALSE] } insight/R/colour_tools.R0000644000176200001440000000515013525034155014772 0ustar liggesusers.rstudio_with_ansi_support <- function() { if (Sys.getenv("RSTUDIO", "") == "") { return(FALSE) } if ((cols <- Sys.getenv("RSTUDIO_CONSOLE_COLOR", "")) != "" && !is.na(as.numeric(cols))) { return(TRUE) } requireNamespace("rstudioapi", quietly = TRUE) && rstudioapi::isAvailable() && rstudioapi::hasFun("getConsoleHasColor") } .supports_color <- function() { enabled <- getOption("crayon.enabled") if (!is.null(enabled)) { return(isTRUE(enabled)) } if (.rstudio_with_ansi_support() && sink.number() == 0) { return(TRUE) } if (!isatty(stdout())) { return(FALSE) } if (Sys.info()["sysname"] == "windows") { if (Sys.getenv("ConEmuANSI") == "ON") { return(TRUE) } if (Sys.getenv("CMDER_ROOT") != "") { return(TRUE) } return(FALSE) } if ("COLORTERM" %in% names(Sys.getenv())) { return(TRUE) } if (Sys.getenv("TERM") == "dumb") { return(FALSE) } grepl("^screen|^xterm|^vt100|color|ansi|cygwin|linux", Sys.getenv("TERM"), ignore.case = TRUE, perl = TRUE ) } .blue <- function(x) { if (.supports_color()) { x[!is.na(x)] <- paste0("\033[34m", x[!is.na(x)], "\033[39m") } x } .bold <- function(x) { if (.supports_color()) { x[!is.na(x)] <- paste0("\033[1m", x[!is.na(x)], "\033[22m") } x } .italic <- function(x) { if (.supports_color()) { x[!is.na(x)] <- paste0("\033[3m", x[!is.na(x)], "\033[23m") } x } .red <- function(x) { if (.supports_color()) { x[!is.na(x)] <- paste0("\033[31m", x[!is.na(x)], "\033[39m") } x } .green <- function(x) { if (.supports_color()) { x[!is.na(x)] <- paste0("\033[32m", x[!is.na(x)], "\033[39m") } x } .yellow <- function(x) { if (.supports_color()) { x[!is.na(x)] <- paste0("\033[33m", x[!is.na(x)], "\033[39m") } x } .violet <- function(x) { if (.supports_color()) { x[!is.na(x)] <- paste0("\033[35m", x[!is.na(x)], "\033[39m") } x } .cyan <- function(x) { if (.supports_color()) { x[!is.na(x)] <- paste0("\033[36m", x[!is.na(x)], "\033[39m") } x } .grey <- function(x) { if (.supports_color()) { x[!is.na(x)] <- paste0("\033[90m", x[!is.na(x)], "\033[39m") } x } .colour <- function(colour = "red", x) { switch( colour, red = .red(x), yellow = .yellow(x), green = .green(x), blue = .blue(x), violet = .violet(x), cyan = .cyan(x), grey = .grey(x), bold = .bold(x), italic = .italic(x), warning(paste0("`color` ", colour, " not yet supported.")) ) } insight/R/get_statistic.R0000644000176200001440000005661313613634107015130 0ustar liggesusers#' @title Get statistic associated with estimates #' @description Returns the statistic (\emph{t}, \code{z}, ...) for model estimates. #' In most cases, this is the related column from \code{coef(summary())}. #' @name get_statistic #' #' @param x A model. #' @param column_index For model objects that have no defined \code{get_statistic()} #' method yet, the default method is called. This method tries to extract the #' statistic column from \code{coef(summary())}, where the index of the column #' that is being pulled is \code{column_index}. Defaults to 3, which is the #' default statistic column for most models' summary-output. #' @param component Should all parameters, parameters for the conditional model, #' or for the zero-inflated part of the model be returned? Applies to models #' with zero-inflated component. \code{component} may be one of #' \code{"conditional"}, \code{"zi"}, \code{"zero-inflated"} or \code{"all"} #' (default). For models with smooth terms, \code{component = "smooth_terms"} #' is also possible. May be abbreviated. Note that the \emph{conditional} #' component is also called \emph{count} or \emph{mean} component, depending #' on the model. #' @param robust Logical, if \code{TRUE}, test statistic based on robust standard #' errors is returned. #' @param ... Currently not used. #' #' @return A data frame with the model's parameter names and the related test statistic. #' #' @examples #' data(mtcars) #' m <- lm(mpg ~ wt + cyl + vs, data = mtcars) #' get_statistic(m) #' @export get_statistic <- function(x, ...) { UseMethod("get_statistic") } # Default models ---------------------------------------------------------- #' @rdname get_statistic #' @export get_statistic.default <- function(x, column_index = 3, ...) { cs <- stats::coef(summary(x)) out <- data.frame( Parameter = rownames(cs), Statistic = as.vector(cs[, column_index]), stringsAsFactors = FALSE, row.names = NULL ) out <- .remove_backticks_from_parameter_names(out) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.mlm <- function(x, ...) { cs <- stats::coef(summary(x)) out <- lapply(names(cs), function(i) { params <- cs[[i]] data.frame( Parameter = rownames(params), Statistic = as.vector(params[, 3]), Response = gsub("^Response (.*)", "\\1", i), stringsAsFactors = FALSE, row.names = NULL ) }) out <- .remove_backticks_from_parameter_names(do.call(rbind, out)) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.lme <- function(x, ...) { get_statistic.default(x, column_index = 4) } #' @export get_statistic.plm <- get_statistic.default #' @export get_statistic.maxLik <- get_statistic.default #' @export get_statistic.glmmadmb <- get_statistic.default #' @export get_statistic.lm_robust <- get_statistic.default #' @export get_statistic.geeglm <- get_statistic.default #' @export get_statistic.truncreg <- get_statistic.default #' @export get_statistic.tobit <- get_statistic.default #' @export get_statistic.censReg <- get_statistic.default #' @export get_statistic.negbin <- get_statistic.default #' @export get_statistic.feis <- get_statistic.default # Models with zero-inflation component -------------------------------------- #' @importFrom stats coef #' @rdname get_statistic #' @export get_statistic.glmmTMB <- function(x, component = c("all", "conditional", "zi", "zero_inflated"), ...) { component <- match.arg(component) cs <- .compact_list(stats::coef(summary(x))) out <- lapply(names(cs), function(i) { data.frame( Parameter = find_parameters(x, effects = "fixed", component = i, flatten = TRUE), Statistic = as.vector(cs[[i]][, 3]), Component = i, stringsAsFactors = FALSE, row.names = NULL ) }) stat <- do.call(rbind, out) stat$Component <- .rename_values(stat$Component, "cond", "conditional") stat$Component <- .rename_values(stat$Component, "zi", "zero_inflated") stat <- .filter_component(stat, component) stat <- .remove_backticks_from_parameter_names(stat) attr(stat, "statistic") <- find_statistic(x) stat } #' @export get_statistic.zeroinfl <- function(x, component = c("all", "conditional", "zi", "zero_inflated"), ...) { component <- match.arg(component) cs <- .compact_list(stats::coef(summary(x))) out <- lapply(names(cs), function(i) { comp <- ifelse(i == "count", "conditional", "zi") data.frame( Parameter = find_parameters(x, effects = "fixed", component = comp, flatten = TRUE), Statistic = as.vector(cs[[i]][, 3]), Component = comp, stringsAsFactors = FALSE, row.names = NULL ) }) stat <- do.call(rbind, out) stat$Component <- .rename_values(stat$Component, "cond", "conditional") stat$Component <- .rename_values(stat$Component, "zi", "zero_inflated") stat <- .filter_component(stat, component) stat <- .remove_backticks_from_parameter_names(stat) attr(stat, "statistic") <- find_statistic(x) stat } #' @export get_statistic.hurdle <- get_statistic.zeroinfl #' @export get_statistic.zerocount <- get_statistic.zeroinfl #' @export get_statistic.MixMod <- function(x, component = c("all", "conditional", "zi", "zero_inflated"), ...) { component <- match.arg(component) s <- summary(x) cs <- list(s$coef_table, s$coef_table_zi) names(cs) <- c("conditional", "zero_inflated") cs <- .compact_list(cs) out <- lapply(names(cs), function(i) { data.frame( Parameter = find_parameters(x, effects = "fixed", component = i, flatten = TRUE), Statistic = as.vector(cs[[i]][, 3]), Component = i, stringsAsFactors = FALSE, row.names = NULL ) }) stat <- .filter_component(do.call(rbind, out), component) stat <- .remove_backticks_from_parameter_names(stat) attr(stat, "statistic") <- find_statistic(x) stat } # gam models -------------------------------------------------------------- #' @importFrom stats na.omit #' @export get_statistic.Gam <- function(x, ...) { p.aov <- stats::na.omit(summary(x)$parametric.anova) out <- data.frame( Parameter = rownames(p.aov), Statistic = as.vector(p.aov[, 4]), stringsAsFactors = FALSE, row.names = NULL ) out <- .remove_backticks_from_parameter_names(out) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.gam <- function(x, ...) { cs <- summary(x)$p.table cs.smooth <- summary(x)$s.table out <- data.frame( Parameter = c(rownames(cs), rownames(cs.smooth)), Statistic = c(as.vector(cs[, 3]), as.vector(cs.smooth[, 3])), Component = c(rep("conditional", nrow(cs)), rep("smooth_terms", nrow(cs.smooth))), stringsAsFactors = FALSE, row.names = NULL ) out <- .remove_backticks_from_parameter_names(out) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.gamm <- function(x, ...) { x <- x$gam class(x) <- c("gam", "lm", "glm") get_statistic.gam(x, ...) } #' @export get_statistic.list <- function(x, ...) { if ("gam" %in% names(x)) { x <- x$gam class(x) <- c("gam", "lm", "glm") get_statistic.gam(x, ...) } } #' @importFrom utils capture.output #' @export get_statistic.gamlss <- function(x, ...) { parms <- get_parameters(x) utils::capture.output(cs <- summary(x)) out <- data.frame( Parameter = parms$Parameter, Statistic = as.vector(cs[, 3]), Component = parms$Component, stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.vglm <- function(x, ...) { if (!requireNamespace("VGAM", quietly = TRUE)) { stop("Package 'VGAM' needed for this function to work. Please install it.") } cs <- VGAM::coef(VGAM::summary(x)) out <- data.frame( Parameter = rownames(cs), Statistic = as.vector(cs[, 3]), stringsAsFactors = FALSE, row.names = NULL ) out <- .remove_backticks_from_parameter_names(out) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.vgam <- function(x, ...) { params <- get_parameters(x) out <- data.frame( Parameter = params$Parameter, Statistic = as.vector(params$Estimate / sqrt(diag(get_varcov(x)))), Component = params$Component, stringsAsFactors = FALSE, row.names = NULL ) out <- .remove_backticks_from_parameter_names(out) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.cgam <- function(x, component = c("all", "conditional", "smooth_terms"), ...) { component <- match.arg(component) sc <- summary(x) stat <- as.vector(sc$coefficients[, 3]) if (!is.null(sc$coefficients2)) stat <- c(stat, rep(NA, nrow(sc$coefficients2))) params <- get_parameters(x, component = "all") out <- data.frame( Parameter = params$Parameter, Statistic = stat, Component = params$Component, stringsAsFactors = FALSE, row.names = NULL ) if (component != "all") { out <- out[out$Component == component, ] } attr(out, "statistic") <- find_statistic(x) out } # Survival models ------------------------------------------ #' @export get_statistic.coxph <- function(x, ...) { get_statistic.default(x, column_index = 4) } #' @importFrom stats vcov #' @export get_statistic.coxme <- function(x, ...) { beta <- x$coefficients out <- NULL if (length(beta) > 0) { out <- data.frame( Parameter = names(beta), Statistic = as.vector(beta / sqrt(diag(stats::vcov(x)))), stringsAsFactors = FALSE, row.names = NULL ) out <- .remove_backticks_from_parameter_names(out) attr(out, "statistic") <- find_statistic(x) } out } #' @export get_statistic.survreg <- function(x, ...) { parms <- get_parameters(x) s <- summary(x) out <- data.frame( Parameter = parms$Parameter, Statistic = s$table[, 3], stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.flexsurvreg <- function(x, ...) { parms <- get_parameters(x) se <- x$res[, "se"] out <- data.frame( Parameter = parms$Parameter, Statistic = parms$Estimate / se, stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.aareg <- function(x, ...) { sc <- summary(x) parms <- get_parameters(x) out <- data.frame( Parameter = parms$Parameter, Statistic = unname(sc$test.statistic), stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } # Ordinal models -------------------------------------------------- #' @rdname get_statistic #' @export get_statistic.clm2 <- function(x, component = c("all", "conditional", "scale"), ...) { component <- match.arg(component) stats <- stats::coef(summary(x)) n_intercepts <- length(x$xi) n_location <- length(x$beta) n_scale <- length(x$zeta) out <- data.frame( Parameter = rownames(stats), Statistic = unname(stats[, "z value"]), Component = c(rep("conditional", times = n_intercepts + n_location), rep("scale", times = n_scale)), stringsAsFactors = FALSE, row.names = NULL ) if (component != "all") { out <- out[out$Component == component, ] } attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.clmm2 <- get_statistic.clm2 #' @export get_statistic.mixor <- function(x, effects = c("all", "fixed", "random"), ...) { stats <- x$Model[, "z value"] effects <- match.arg(effects) parms <- get_parameters(x, effects = effects) out <- data.frame( Parameter = parms$Parameter, Statistic = stats[parms$Parameter], Effects = parms$Effects, stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.multinom <- function(x, ...) { parms <- get_parameters(x) stderr <- summary(x)$standard.errors if (is.matrix(stderr)) { se <- c() for (i in 1:nrow(stderr)) { se <- c(se, as.vector(stderr[i, ])) } } else { se <- as.vector(stderr) } out <- data.frame( Parameter = parms$Parameter, Statistic = parms$Estimate / se, stringsAsFactors = FALSE, row.names = NULL ) if ("Response" %in% colnames(parms)) { out$Response <- parms$Response } attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.brmultinom <- get_statistic.multinom #' @export get_statistic.bracl <- function(x, ...) { parms <- get_parameters(x) out <- data.frame( Parameter = parms$Parameter, Statistic = stats::coef(summary(x))[, "z value"], Response = parms$Response, stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } # Other models ------------------------------------------------------- #' @export get_statistic.wbm <- function(x, ...) { s <- summary(x) statistic_column <- if ("t val." %in% c( colnames(s$within_table), colnames(s$between_table), colnames(s$ints_table) )) { "t val." } else { "z val." } stat <- c( s$within_table[, statistic_column], s$between_table[, statistic_column], s$ints_table[, statistic_column] ) params <- get_parameters(x) out <- data.frame( Parameter = params$Parameter, Statistic = as.vector(stat), Component = params$Component, stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.wbgee <- get_statistic.wbm #' @export get_statistic.cpglmm <- function(x, ...) { if (!requireNamespace("cplm", quietly = TRUE)) { stop("To use this function, please install package 'cplm'.") } stats <- cplm::summary(x)$coefs params <- get_parameters(x) out <- data.frame( Parameter = params$Parameter, Statistic = as.vector(stats[, "t value"]), stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } #' @importFrom utils capture.output #' @export get_statistic.cpglm <- function(x, ...) { if (!requireNamespace("cplm", quietly = TRUE)) { stop("To use this function, please install package 'cplm'.") } junk <- utils::capture.output(stats <- cplm::summary(x)$coefficients) params <- get_parameters(x) out <- data.frame( Parameter = params$Parameter, Statistic = as.vector(stats[, "t value"]), stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.MANOVA <- function(x, ...) { stats <- as.data.frame(x$WTS) out <- data.frame( Parameter = rownames(stats), Statistic = as.vector(stats[[1]]), stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.RM <- get_statistic.MANOVA #' @export get_statistic.rq <- function(x, ...) { stat <- tryCatch( { cs <- stats::coef(summary(x)) cs[, "t value"] }, error = function(e) { cs <- stats::coef(summary(x, covariance = TRUE)) cs[, "t value"] } ) params <- get_parameters(x) out <- data.frame( Parameter = params$Parameter, Statistic = stat, stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.crq <- get_statistic.rq #' @export get_statistic.nlrq <- get_statistic.rq #' @export get_statistic.rqss <- function(x, component = c("all", "conditional", "smooth_terms"), ...) { component <- match.arg(component) cs <- summary(x) stat <- c(as.vector(cs$coef[, "t value"]), as.vector(cs$qsstab[, "F value"])) params <- get_parameters(x) out <- data.frame( Parameter = params$Parameter, Statistic = unname(stat), Component = params$Component, stringsAsFactors = FALSE, row.names = NULL ) if (component != "all") { out <- out[out$Component == component, ] } attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.bigglm <- function(x, ...) { parms <- get_parameters(x) cs <- summary(x)$mat se <- as.vector(cs[, 4]) out <- data.frame( Parameter = parms$Parameter, Statistic = parms$Estimate / se, stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.biglm <- function(x, ...) { parms <- get_parameters(x) cs <- summary(x)$mat se <- as.vector(cs[, 4]) out <- data.frame( Parameter = parms$Parameter, Statistic = parms$Estimate / se, stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.LORgee <- function(x, ...) { out <- get_statistic.default(x) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.crch <- function(x, ...) { cs <- do.call(rbind, stats::coef(summary(x), model = "full")) params <- get_parameters(x) out <- data.frame( Parameter = params$Parameter, Statistic = as.vector(cs[, 3]), stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.fixest <- function(x, ...) { cs <- summary(x)$coeftable params <- get_parameters(x) out <- data.frame( Parameter = params$Parameter, Statistic = as.vector(cs[, 3]), stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.glmx <- function(x, component = c("all", "conditional", "extra"), ...) { component <- match.arg(component) cf <- stats::coef(summary(x)) parms <- get_parameters(x) out <- rbind( data.frame( Parameter = parms$Parameter[parms$Component == "conditional"], Statistic = unname(cf$glm[, 3]), Component = "conditional", stringsAsFactors = FALSE, row.names = NULL ), data.frame( Parameter = parms$Parameter[parms$Component == "extra"], Statistic = cf$extra[, 3], Component = "extra", stringsAsFactors = FALSE, row.names = NULL ) ) if (component != "all") { out <- out[out$Component == component, ] } attr(out, "statistic") <- find_statistic(x) out } #' @rdname get_statistic #' @importFrom stats coef #' @export get_statistic.gee <- function(x, robust = FALSE, ...) { parms <- get_parameters(x) cs <- stats::coef(summary(x)) if (isTRUE(robust)) { stats <- as.vector(cs[, "Robust z"]) } else { stats <- as.vector(cs[, "Naive z"]) } out <- data.frame( Parameter = parms$Parameter, Statistic = stats, stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.complmrob <- function(x, ...) { parms <- get_parameters(x) stat <- summary(x)$stats out <- data.frame( Parameter = parms$Parameter, Statistic = as.vector(stat[, "t value"]), stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } #' @importFrom stats qchisq #' @importFrom utils capture.output #' @export get_statistic.logistf <- function(x, ...) { parms <- get_parameters(x) utils::capture.output(s <- summary(x)) out <- data.frame( Parameter = parms$Parameter, Statistic = as.vector(stats::qchisq(1 - s$prob, df = 1)), stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } #' @importFrom stats vcov #' @export get_statistic.svyglm.nb <- function(x, ...) { if (!isNamespaceLoaded("survey")) { requireNamespace("survey", quietly = TRUE) } parms <- get_parameters(x) se <- sqrt(diag(stats::vcov(x, stderr = "robust"))) out <- data.frame( Parameter = parms$Parameter, Statistic = parms$Estimate / se, stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.svyglm.zip <- get_statistic.svyglm.nb #' @rdname get_statistic #' @importFrom stats coef #' @export get_statistic.betareg <- function(x, component = c("all", "conditional", "precision"), ...) { component <- match.arg(component) parms <- get_parameters(x) cs <- do.call(rbind, stats::coef(summary(x))) se <- as.vector(cs[, 2]) out <- data.frame( Parameter = parms$Parameter, Statistic = parms$Estimate / se, Component = parms$Component, stringsAsFactors = FALSE, row.names = NULL ) if (component != "all") { out <- out[out$Component == component, ] } attr(out, "statistic") <- find_statistic(x) out } #' @rdname get_statistic #' @importFrom stats coef #' @importFrom utils capture.output #' @export get_statistic.DirichletRegModel <- function(x, component = c("all", "conditional", "precision"), ...) { component <- match.arg(component) parms <- get_parameters(x) junk <- utils::capture.output(cs <- summary(x)$coef.mat) out <- data.frame( Parameter = parms$Parameter, Statistic = unname(cs[, "z value"]), Response = parms$Response, stringsAsFactors = FALSE, row.names = NULL ) if (!is.null(parms$Component)) { out$Component <- parms$Component } else { component <- "all" } if (component != "all") { out <- out[out$Component == component, ] } attr(out, "statistic") <- find_statistic(x) out } #' @importFrom methods slot #' @export get_statistic.glimML <- function(x, ...) { if (!requireNamespace("aod", quietly = TRUE)) { stop("Package 'aod' required for this function to work. Please install it.") } parms <- get_parameters(x) s <- methods::slot(aod::summary(x), "Coef") out <- data.frame( Parameter = parms$Parameter, Statistic = s[, 3], stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } #' @importFrom stats coef vcov #' @export get_statistic.lrm <- function(x, ...) { parms <- get_parameters(x) stat <- stats::coef(x) / sqrt(diag(stats::vcov(x))) out <- data.frame( Parameter = parms$Parameter, Statistic = as.vector(stat), stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } #' @export get_statistic.ols <- get_statistic.lrm #' @export get_statistic.rms <- get_statistic.lrm #' @export get_statistic.psm <- get_statistic.lrm #' @export get_statistic.rma <- function(x, ...) { parms <- get_parameters(x) stat <- x$zval out <- data.frame( Parameter = parms$Parameter, Statistic = as.vector(stat), stringsAsFactors = FALSE, row.names = NULL ) attr(out, "statistic") <- find_statistic(x) out } insight/R/all_equal_models.R0000644000176200001440000000446513527040073015557 0ustar liggesusers#' @title Checks if all objects are models of same class #' @name all_models_equal #' #' @description Small helper that checks if all objects are \emph{supported} #' (regression) model objects and of same class. #' #' @param ... A list of objects. #' @inheritParams get_variance #' #' @return A logical, \code{TRUE} if \code{x} are all supported model objects #' of same class. #' #' @examples #' library(lme4) #' data(mtcars) #' data(sleepstudy) #' #' m1 <- lm(mpg ~ wt + cyl + vs, data = mtcars) #' m2 <- lm(mpg ~ wt + cyl, data = mtcars) #' m3 <- lmer(Reaction ~ Days + (1 | Subject), data = sleepstudy) #' m4 <- glm(formula = vs ~ wt, family = binomial(), data = mtcars) #' #' all_models_same_class(m1, m2) #' all_models_same_class(m1, m2, m3) #' all_models_same_class(m1, m4, m2, m3, verbose = TRUE) #' all_models_same_class(m1, m4, mtcars, m2, m3, verbose = TRUE) #' @export all_models_equal <- function(..., verbose = FALSE) { objects <- list(...) object_names <- match.call(expand.dots = FALSE)$`...` all_supported <- vapply(objects, is_model_supported, FUN.VALUE = logical(1)) all_classes <- sapply(objects, class) if (is.matrix(all_classes)) { all_classes <- as.vector(all_classes[1, ]) } else if (is.list(all_classes)) { all_classes <- sapply(all_classes, function(i) i[1]) } all_equal <- all(vapply(all_classes[-1], function(i) identical(i, all_classes[1]), FUN.VALUE = logical(1))) if (!all(all_supported) && verbose) { differ <- which(!all_supported) m1 <- "Following objects are no (supported) models:" m2 <- paste0(sprintf("%s", object_names[differ]), collapse = ", ") message(paste(m1, m2, collapse = " ")) } if (!all(all_equal) && verbose) { differ <- which(!duplicated(all_classes)) m1 <- sprintf( "Following objects are not identical with %s (of class \"%s\"):", object_names[1], all_classes[[1]] ) m2 <- paste0( sprintf( "%s (\"%s\")", object_names[differ[-1]], sapply(all_classes[differ[-1]], function(x) as.vector(x[[1]])) ), collapse = ", " ) message(paste(m1, m2, collapse = " ")) } all(all_supported) && all(all_equal) } #' @rdname all_models_equal #' @export all_models_same_class <- all_models_equal insight/R/find_algorithm.R0000644000176200001440000001337513600224571015242 0ustar liggesusers#' @title Find sampling algorithm and optimizers #' @name find_algorithm #' #' @description Returns information on the sampling or estimation algorithm #' as well as optimization functions, or for Bayesian model information on #' chains, iterations and warmup-samples. #' #' @inheritParams find_parameters #' #' @return A list with elements depending on the model. #' \cr #' For frequentist models: #' \itemize{ #' \item \code{algorithm}, for instance \code{"OLS"} or \code{"ML"} #' \item \code{optimizer}, name of optimizing function, only applies to specific models (like \code{gam}) #' } #' For frequentist mixed models: #' \itemize{ #' \item \code{algorithm}, for instance \code{"REML"} or \code{"ML"} #' \item \code{optimizer}, name of optimizing function #' } #' For Bayesian models: #' \itemize{ #' \item \code{algorithm}, the algorithm #' \item \code{chains}, number of chains #' \item \code{iterations}, number of iterations per chain #' \item \code{warmup}, number of warmups per chain #' } #' #' #' @examples #' library(lme4) #' data(sleepstudy) #' m <- lmer(Reaction ~ Days + (1 | Subject), data = sleepstudy) #' find_algorithm(m) #' \dontrun{ #' library(rstanarm) #' m <- stan_lmer(Reaction ~ Days + (1 | Subject), data = sleepstudy) #' find_algorithm(m) #' } #' #' @export find_algorithm <- function(x, ...) { UseMethod("find_algorithm") } #' @export find_algorithm.default <- function(x, ...) { warning(sprintf("Objects of class `%s` are not supported.", class(x)[1])) NULL } #' @export find_algorithm.Gam <- function(x, ...) { list("algorithm" = "IWLS") } #' @export find_algorithm.lmRob <- function(x, ...) { list("algorithm" = x$robust.control$final.alg) } #' @export find_algorithm.lmrob <- function(x, ...) { list("algorithm" = x$control$method) } #' @export find_algorithm.glmrob <- function(x, ...) { list("algorithm" = x$method) } #' @export find_algorithm.logistf <- function(x, ...) { list("algorithm" = x$method) } #' @export find_algorithm.bigglm <- function(x, ...) { list("algorithm" = "ML") } #' @export find_algorithm.BBreg <- function(x, ...) { list("algorithm" = "ML") } #' @export find_algorithm.glimML <- function(x, ...) { list("algorithm" = "ML") } #' @export find_algorithm.BBmm <- function(x, ...) { method <- parse(text = .safe_deparse(x$call))[[1]]$method if (is.null(method)) method <- "BB-NR" list(algorithm = "extended likelihood", optimizer = method) } #' @export find_algorithm.biglm <- function(x, ...) { list("algorithm" = "OLS") } #' @export find_algorithm.gamlss <- function(x, ...) { list("algorithm" = as.character(x$method)[1]) } #' @export find_algorithm.gam <- function(x, ...) { list( "algorithm" = x$method, "optimizer" = x$optimizer ) } #' @export find_algorithm.lm <- function(x, ...) { list("algorithm" = "OLS") } #' @export find_algorithm.speedlm <- function(x, ...) { list("algorithm" = x$method) } #' @export find_algorithm.blavaan <- function(x, ...) { if (!requireNamespace("blavaan", quietly = TRUE)) { stop("Package 'blavaan' required for this function to work. Please install it.") } list( "chains" = blavaan::blavInspect(x, "n.chains"), "sample" = x@external$sample, "warmup" = x@external$burnin ) } #' @export find_algorithm.speedglm <- function(x, ...) { list("algorithm" = x$method) } #' @export find_algorithm.rq <- function(x, ...) { list("algorithm" = x$method) } #' @export find_algorithm.bayesx <- function(x, ...) { list( "algorithm" = x$method, "iterations" = x$iterations, "warmup" = x$burnin ) } #' @export find_algorithm.crq <- function(x, ...) { list("algorithm" = x$method) } #' @export find_algorithm.rqss <- function(x, ...) { list("algorithm" = x$method) } #' @export find_algorithm.glm <- function(x, ...) { list("algorithm" = "ML") } #' @export find_algorithm.LORgee <- function(x, ...) { list("algorithm" = "Fisher's scoring ML") } #' @export find_algorithm.merMod <- function(x, ...) { algorithm <- ifelse(as.logical(x@devcomp$dims[["REML"]]), "REML", "ML") list( "algorithm" = algorithm, "optimizer" = as.character(x@optinfo$optimizer) ) } #' @export find_algorithm.rlmerMod <- find_algorithm.merMod #' @export find_algorithm.mixed <- function(x, ...) { x <- x$full_model algorithm <- ifelse(as.logical(x@devcomp$dims[["REML"]]), "REML", "ML") list( "algorithm" = algorithm, "optimizer" = as.character(x@optinfo$optimizer) ) } #' @export find_algorithm.lme <- function(x, ...) { optimizer <- "nlminb" if (!is.null(x$call$control) && "optim" %in% as.character(x$call$control)) { optimizer <- "optim" } list( "algorithm" = x$method, "optimizer" = optimizer ) } #' @export find_algorithm.MixMod <- function(x, ...) { list( ## TODO fix me "algorithm" = "quasi-Newton", "optimizer" = x$control$optimizer ) } #' @export find_algorithm.glmmTMB <- function(x, ...) { algorithm <- ifelse(x$modelInfo$REML, "REML", "ML") list( "algorithm" = algorithm, "optimizer" = "nlminb" ) } #' @export find_algorithm.stanreg <- function(x, ...) { info <- x$stanfit@sim list( "algorithm" = x$algorithm, "chains" = info$chains, "iterations" = info$iter, "warmup" = info$warmup ) } #' @export find_algorithm.brmsfit <- function(x, ...) { info <- x$fit@sim list( "algorithm" = x$algorithm, "chains" = info$chains, "iterations" = info$iter, "warmup" = info$warmup ) } insight/R/is_model_supported.R0000644000176200001440000000522013614067316016151 0ustar liggesusers#' @title Checks if an object is a regression model object supported in #' \pkg{insight} package. #' @name is_model_supported #' #' @description Small helper that checks if a model is a \emph{supported} #' (regression) model object. \code{supported_models()} prints a list #' of currently supported model classes. #' #' @inheritParams is_model #' #' @return A logical, \code{TRUE} if \code{x} is a (supported) model object. #' #' @details This function returns \code{TRUE} if \code{x} is a model object #' that works with the package's functions. A list of supported models can #' also be found here: \url{https://github.com/easystats/insight}. #' #' @examples #' data(mtcars) #' m <- lm(mpg ~ wt + cyl + vs, data = mtcars) #' #' is_model_supported(m) #' is_model_supported(mtcars) #' @export is_model_supported <- function(x) { inherits(x, .supported_models_list()) } #' @rdname is_model_supported #' @export supported_models <- function() { sort(.supported_models_list()) } .supported_models_list <- function() { c( "aareg", "aov", "aovlist", "bamlss", "bamlss.frame", "bayesx", "BBmm", "BBreg", "betareg", "BFBayesFactor", "biglm", "bigglm", "blavaan", "bracl", "brglm", "brmsfit", "brmultinom", "censReg", "cgam", "cgamm", "cglm", "clm", "clm2", "clmm", "clmm2", "complmrob", "coxme", "coxph", "cpglm", "cpglmm", "crch", "crq", "crqs", "DirichletRegModel", "feis", "felm", "feglm", "fixest", "flexsurvreg", "gam", "Gam", "gamlss", "gamm", "gamm4", "gbm", "gee", "geeglm", "glimML", "glm", "glmmadmb", "glmmPQL", "glmmTMB", "glmrob", "glmRob", "glmx", "gls", "gmnl", "htest", "hurdle", "iv_robust", "ivreg", "lavaan", "lm", "lm_robust", "lme", "lmrob", "lmRob", "logistf", "LORgee", "lrm", "MANOVA", "maxLik", "mcmc", "MCMCglmm", "merMod", "mixed", "mixor", "MixMod", "mlm", "mclogit", "mlogit", "mmlogit", "multinom", "ols", "plm", "polr", "psm", "rlm", "rlmerMod", "RM", "rma", "rma.uni", "rq", "rqss", "speedlm", "speedglm", "stanmvreg", "stanreg", "survfit", "survreg", "svyglm", "svyolr", "tobit", "truncreg", "vgam", "vglm", "wbm", "wblm", "wbgee", "zeroinfl", "zerotrunc" ) } insight/R/find_weights.R0000644000176200001440000000314713555323465014735 0ustar liggesusers#' @title Find names of model weights #' @name find_weights #' #' @description Returns the name of the variable that describes the weights of a model. #' #' @param x A fitted model. #' @param ... Currently not used. #' #' @return The name of the weighting variable as character vector, or \code{NULL} #' if no weights were specified. #' #' @examples #' data(mtcars) #' mtcars$weight <- rnorm(nrow(mtcars), 1, .3) #' m <- lm(mpg ~ wt + cyl + vs, data = mtcars, weights = weight) #' find_weights(m) #' @export find_weights <- function(x, ...) { UseMethod("find_weights") } #' @export find_weights.default <- function(x, ...) { tryCatch( { w <- .safe_deparse(parse(text = .safe_deparse(x$call))[[1]]$weights) # edge case, users use "eval(parse())" to parse weight variables if (grepl("^eval\\(parse\\(", w)) { w <- eval(parse(text = .trim(gsub("eval\\(parse\\((.*)=(.*)\\)\\)", "\\2", w)))) } if (.is_empty_object(w) || w == "NULL") w <- NULL w }, error = function(e) { NULL } ) } #' @export find_weights.brmsfit <- function(x, ...) { f <- find_formula(x) if (is_multivariate(f)) { resp <- unlist(lapply(f, function(i) .safe_deparse(i$conditional[[2L]]))) } else { resp <- .safe_deparse(f$conditional[[2L]]) } resp <- .compact_character(unname(sapply(resp, function(i) { if (grepl("(.*)\\|(\\s+)weights\\((.*)\\)", i)) { i } else { "" } }))) w <- .trim(sub("(.*)\\|(\\s+)weights\\((.*)\\)", "\\3", resp)) if (.is_empty_object(w)) w <- NULL w } insight/R/clean_names.R0000644000176200001440000001227413613634107014522 0ustar liggesusers#' @title Get clean names of model terms #' @name clean_names #' #' @description This function "cleans" names of model terms (or a character #' vector with such names) by removing patterns like \code{log()} or #' \code{as.factor()} etc. #' #' @param x A fitted model, or a character vector. #' #' @return The "cleaned" variable names as character vector, i.e. pattern #' like \code{s()} for splines or \code{log()} are removed from #' the model terms. #' #' @note Typically, this method is intended to work on character vectors, #' in order to remove patterns that obscure the variable names. For #' convenience reasons it is also possible to call \code{clean_names()} #' also on a model object. If \code{x} is a regression model, this #' function is (almost) equal to calling \code{find_variables()}. The #' main difference is that \code{clean_names()} always returns a character #' vector, while \code{find_variables()} returns a list of character #' vectors, unless \code{flatten = TRUE}. See 'Examples'. #' #' @examples #' # example from ?stats::glm #' counts <- c(18, 17, 15, 20, 10, 20, 25, 13, 12) #' outcome <- c(gl(3, 1, 9)) #' treatment <- gl(3, 3) #' m <- glm(counts ~ log(outcome) + as.factor(treatment), family = poisson()) #' clean_names(m) #' #' # difference "clean_names()" and "find_variables()" #' library(lme4) #' m <- glmer( #' cbind(incidence, size - incidence) ~ period + (1 | herd), #' data = cbpp, #' family = binomial #' ) #' #' clean_names(m) #' find_variables(m) #' find_variables(m, flatten = TRUE) #' @export clean_names <- function(x) { UseMethod("clean_names") } #' @export clean_names.default <- function(x) { cleaned <- unname(find_variables(x, flatten = TRUE)) .remove_values(cleaned, c("1", "0")) } #' @export clean_names.character <- function(x) { .remove_pattern_from_names(x) } .remove_pattern_from_names <- function(x, ignore_asis = FALSE, ignore_lag = FALSE) { # return if x is empty if (.is_empty_string(x)) { return("") } # for gam-smoothers/loess, remove s()- and lo()-function in column name # for survival, remove strata(), and so on... pattern <- c( "as.factor", "as.numeric", "factor", "offset", "log1p", "log10", "log2", "log-log", "scale-log", "log", "lag", "diff", "lspline", "pspline", "poly", "catg", "asis", "matrx", "pol", "strata", "strat", "scale", "scored", "interaction", "sqrt", "lsp", "rcs", "pb", "lo", "bs", "ns", "t2", "te", "ti", "tt", # need to be fixed first "mmc", "mm", "mi", "mo", "gp", "s", "I" ) # sometimes needed for panelr models, where we need to preserve "lag()" if (ignore_lag) { lag_pattern <- which(pattern == "lag") if (length(lag_pattern)) pattern <- pattern[-lag_pattern] } # do we have a "log()" pattern here? if yes, get capture region # which matches the "cleaned" variable name cleaned <- sapply(1:length(x), function(i) { for (j in 1:length(pattern)) { # remove possible namespace x[i] <- sub("(.*)::(.*)", "\\2", x[i]) if (pattern[j] == "offset") { x[i] <- .trim(unique(sub("^offset\\(([^-+ )]*).*", "\\1", x[i]))) } else if (pattern[j] == "I") { if (!ignore_asis) x[i] <- .trim(unique(sub("I\\(((\\w|\\.)*).*", "\\1", x[i]))) } else if (pattern[j] == "asis") { if (!ignore_asis) x[i] <- .trim(unique(sub("asis\\(((\\w|\\.)*).*", "\\1", x[i]))) } else if (pattern[j] == "log-log") { x[i] <- .trim(unique(sub("^log\\(log\\(((\\w|\\.)*).*", "\\1", x[i]))) } else if (pattern[j] == "scale-log") { x[i] <- .trim(unique(sub("^scale\\(log\\(((\\w|\\.)*).*", "\\1", x[i]))) x[i] <- .trim(unique(sub("^scale\\(log1p\\(((\\w|\\.)*).*", "\\1", x[i]))) x[i] <- .trim(unique(sub("^scale\\(log2\\(((\\w|\\.)*).*", "\\1", x[i]))) x[i] <- .trim(unique(sub("^scale\\(log10\\(((\\w|\\.)*).*", "\\1", x[i]))) } else if (pattern[j] %in% c("mmc", "mm")) { ## TODO multimembership-models need to be fixed p <- paste0("^", pattern[j], "\\((.*)\\).*") g <- .trim(sub(p, "\\1", x[i])) x[i] <- .trim(unlist(strsplit(g, ","))) } else { # p <- paste0("^", pattern[j], "\\(([^,/)]*).*") # this one should be more generic... p <- paste0("^", pattern[j], "\\(((\\w|\\.)*).*") x[i] <- unique(sub(p, "\\1", x[i])) } } # for coxme-models, remove random-effect things... .trim(sub("^(.*)\\|(.*)", "\\2", x[i])) }) # remove for random intercept only models .remove_values(cleaned, c("1", "0")) } ## TODO multimembership-models may also have weights, this does not work yet .clean_brms_mm <- function(x) { # only clean for mm() / mmc() functions, else return x if (!grepl("^(mmc|mm)\\(", x)) { return(x) } # extract terms from mm() / mmc() functions, i.e. get # multimembership-terms unname(.compact_character(unlist(sapply(c("mmc", "mm"), function(j) { if (grepl(paste0("^", j, "\\("), x = x)) { p <- paste0("^", j, "\\((.*)\\).*") g <- .trim(sub(p, "\\1", x)) .trim(unlist(strsplit(g, ","))) } else { "" } }, simplify = FALSE)))) } insight/R/n_obs.R0000644000176200001440000001133713614067316013357 0ustar liggesusers#' @title Get number of observations from a model #' @name n_obs #' #' @description This method returns the number of observation that were used #' to fit the model, as numeric value. #' #' @param weighted For survey designs, returns the weighted sample size. #' @inheritParams find_predictors #' @inheritParams get_response #' @inheritParams find_formula #' #' @return The number of observations used to fit the model, or \code{NULL} if #' this information is not available. #' #' @examples #' data(mtcars) #' m <- lm(mpg ~ wt + cyl + vs, data = mtcars) #' n_obs(m) #' @importFrom stats model.frame nobs #' @export n_obs <- function(x, ...) { UseMethod("n_obs") } #' @export n_obs.default <- function(x, ...) { if (inherits(x, "list") && .obj_has_name(x, "gam")) { x <- x$gam class(x) <- c(class(x), c("glm", "lm")) } tryCatch( { stats::nobs(x) }, error = function(x) { NULL } ) } #' @export n_obs.censReg <- n_obs.default #' @rdname n_obs #' @export n_obs.svyolr <- function(x, weighted = FALSE, ...) { if (weighted) { stats::nobs(x) } else { nrow(stats::model.frame(x)) } } #' @export n_obs.gamm <- function(x, ...) { x <- x$gam class(x) <- c(class(x), c("glm", "lm")) NextMethod() } #' @export n_obs.bayesx <- function(x, ...) { length(x$response) } #' @export n_obs.flexsurvreg <- function(x, ...) { x$N } #' @export n_obs.bamlss <- function(x, ...) { nrow(x$model.frame) } #' @export n_obs.lmRob <- function(x, ...) { length(x$fitted.values) } #' @export n_obs.LORgee <- function(x, ...) { x$nobs } #' @export n_obs.mcmc <- function(x, ...) { nrow(as.data.frame(x)) } #' @export n_obs.biglm <- function(x, ...) { x$n } #' @export n_obs.bigglm <- n_obs.biglm #' @export n_obs.rqss <- n_obs.biglm #' @export n_obs.hurdle <- n_obs.biglm #' @export n_obs.zerotrunc <- n_obs.biglm #' @export n_obs.zeroinfl <- n_obs.biglm #' @export n_obs.cgam <- function(x, ...) { nrow(get_data(x)) } #' @export n_obs.cglm <- n_obs.cgam #' @export n_obs.gbm <- function(x, ...) { length(x$fit) } #' @export n_obs.glimML <- function(x, ...) { nrow(x@data) } #' @export n_obs.glmRob <- function(x, ...) { length(x$fitted.values) } #' @export n_obs.gmnl <- function(x, ...) { x$logLik$nobs } #' @export n_obs.multinom <- function(x, ...) { nrow(x$fitted.values) } #' @export n_obs.cpglmm <- function(x, ...) { nrow(x@frame) } #' @export n_obs.cpglm <- function(x, ...) { nrow(x$model.frame) } #' @export n_obs.rq <- function(x, ...) { length(x$fitted.values) } #' @export n_obs.BBreg <- function(x, ...) { x$nObs } #' @export n_obs.BBmm <- n_obs.BBreg #' @export n_obs.crq <- function(x, ...) { n <- nrow(x$residuals) if (.is_empty_object(n)) { n <- nrow(x$fitted.values) } n } #' @export n_obs.crqs <- n_obs.crq #' @export n_obs.MANOVA <- function(x, ...) { nrow(x$input$data) } #' @export n_obs.RM <- n_obs.MANOVA #' @importFrom stats fitted #' @export n_obs.nlrq <- function(x, ...) { length(stats::fitted(x)) } #' @export n_obs.survfit <- function(x, ...) { length(x$n.event) } #' @export n_obs.survreg <- function(x, ...) { length(x$linear.predictors) } #' @export n_obs.aareg <- function(x, ...) { max(x$n) } #' @export n_obs.coxph <- n_obs.aareg #' @export n_obs.coxme <- n_obs.aareg #' @export n_obs.felm <- function(x, ...) { x$N } #' @export n_obs.feis <- function(x, ...) { length(x$fitted.values) } #' @export n_obs.fixest <- function(x, ...) { x$nobs } #' @export n_obs.feglm <- function(x, ...) { x$nobs["nobs"] } #' @export n_obs.complmrob <- n_obs.cgam #' @export n_obs.aovlist <- function(x, ...) { nrow(stats::model.frame(x)) } #' @rdname n_obs #' @export n_obs.stanmvreg <- function(x, select = NULL, ...) { n <- min(x$n_yobs) if (!is.null(select)) { if (select %in% names(x$n_yobs)) { n <- x$n_yobs[select] } else { print_color(sprintf("Could not find response '%s'. Model's response variables are named %s.\n", select, paste(names(x$n_yobs), collapse = ", ")), "red") cat("Returning smallest number of observations now.\n") n <- min(x$n_yobs) } } n } #' @export n_obs.mlogit <- function(x, ...) { nrow(x$model) } #' @export n_obs.maxLik <- n_obs.mlogit #' @export n_obs.wbm <- function(x, ...) { nrow(x@frame) } #' @export n_obs.wbgee <- function(x, ...) { stats::nobs(x) } insight/R/get_predictors.R0000644000176200001440000000156413552111346015267 0ustar liggesusers#' @title Get the data from model predictors #' @name get_predictors #' #' @description Returns the data from all predictor variables (fixed effects). #' #' @inheritParams find_predictors #' #' @return The data from all predictor variables, as data frame. #' #' @examples #' m <- lm(mpg ~ wt + cyl + vs, data = mtcars) #' head(get_predictors(m)) #' @export get_predictors <- function(x) { vars <- if (inherits(x, "wbm")) { unlist(.compact_list(find_terms(x, flatten = FALSE)[c("conditional", "instruments")])) } else { find_predictors(x, effects = "fixed", component = "all", flatten = TRUE) } dat <- get_data(x) dat <- dat[, intersect(vars, colnames(dat)), drop = FALSE] if (.is_empty_object(dat)) { print_color("Warning: Data frame is empty, probably you have an intercept-only model?\n", "red") return(NULL) } dat } insight/R/print_parameters.R0000644000176200001440000001620513524331052015624 0ustar liggesusers#' @title Prepare summary statistics of model parameters for printing #' @name print_parameters #' #' @description This function takes a data frame, typically a data frame with #' information on summaries of model parameters like \code{\link[bayestestR]{hdi}} #' or \code{\link[bayestestR]{equivalence_test}}, as input and splits this information #' into several parts, depending on the model. See details below. #' #' @param x A fitted model, or a data frame returned by \code{\link{clean_parameters}}. #' @param ... One or more objects (data frames), which contain information about #' the model parameters and related statistics (like confidence intervals, HDI, #' ROPE, ...). #' @param split_by \code{split_by} should be a character vector with one or #' more of the following elements: \code{"Effects"}, \code{"Component"}, #' \code{"Response"} and \code{"Group"}. These are the column names returned #' by \code{\link{clean_parameters}}, which is used to extract the information #' from which the group or component model parameters belong. If \code{NULL}, the #' merged data frame is returned. Else, the data frame is split into a list, #' split by the values from those columns defined in \code{split_by}. #' #' @return A data frame or a list of data frames (if \code{split_by} is not \code{NULL}). #' If a list is returned, the element names reflect the model components where the #' extracted information in the data frames belong to, e.g. \code{`random.zero_inflated.Intercept: persons`}. #' This is the data frame that contains the parameters for the random effects from #' group-level "persons" from the zero-inflated model component. #' #' @details This function prepares data frames that contain information #' about model parameters for clear printing. #' \cr \cr #' First, \code{x} is required, which should either be a model object or a #' prepared data frame as returned by \code{\link{clean_parameters}}. If #' \code{x} is a model, \code{clean_parameters()} is called on that model #' object to get information with which model components the parameters #' are associated. #' \cr \cr #' Then, \code{...} take one or more data frames that also contain information #' about parameters from the same model, but also have additional information #' provided by other methods. For instance, a data frame in \code{...} might #' be the result of \code{\link[bayestestR]{hdi}}, where we #' have a) a \code{Parameters} column and b) columns with the HDI values. #' \cr \cr #' Now we have a data frame with model parameters and information about the #' association to the different model components, a data frame with model #' parameters, and some summary statistics. \code{print_parameters()} #' then merges these data frames, so the statistic of interest (in our example: #' the HDI) is also associated with the different model components. The data #' frame is split into a list, so for a clear printing. Users can loop over this #' list and print each component for a better overview. Further, parameter #' names are "cleaned", if necessary, also for a cleaner print. See also 'Examples'. #' #' @examples #' \dontrun{ #' library(bayestestR) #' model <- download_model("brms_zi_2") #' x <- hdi(model, effects = "all", component = "all") #' #' # hdi() returns a data frame; here we use only the informaton on #' # parameter names and HDI values #' tmp <- as.data.frame(x)[, 1:4] #' tmp #' #' # Based on the "split_by" argument, we get a list of data frames that #' # is split into several parts that reflect the model components. #' print_parameters(model, tmp) #' #' # This is the standard print()-method for "bayestestR::hdi"-objects. #' # For printing methods, it is easy to print complex summary statistics #' # in a clean way to the console by splitting the information into #' # different model components. #' x #' } #' #' @importFrom stats na.omit #' @export print_parameters <- function(x, ..., split_by = c("Effects", "Component", "Group", "Response")) { obj <- list(...) cp <- if (!inherits(x, "clean_parameters")) { clean_parameters(x) } else { x } cn1 <- colnames(cp) obj <- lapply(obj, function(i) { # make sure we have a Parameter column if (!"Parameter" %in% colnames(i)) colnames(i)[1] <- "Parameter" # remove all other common columns that might produce duplicates cn2 <- colnames(i) dupes <- stats::na.omit(match(cn1, cn2)[-1]) if (length(dupes) > 0) i <- i[, -dupes, drop = FALSE] i }) # merge all objects together obj <- Reduce( function(x, y) merge(x, y, all.x = FALSE, by = "Parameter", sort = FALSE), c(list(cp), obj) ) # return merged data frame if no splitting requested if (.is_empty_object(split_by)) { return(obj) } # determine where to split data frames split_by <- split_by[split_by %in% colnames(obj)] f <- lapply(split_by, function(i) { if (i %in% colnames(obj)) obj[[i]] }) names(f) <- split_by # split into groups, remove empty elements out <- split(obj, f) out <- .compact_list(lapply(out, function(i) { if (nrow(i) > 0) i })) # remove trailing dots names(out) <- list_names <- gsub("(.*)\\.$", "\\1", names(out)) has_zeroinf <- any(grepl("zero_inflated", names(out), fixed = TRUE)) # create title attributes, and remove unnecessary columns from output out <- lapply(names(out), function(i) { # init title variables title1 <- title2 <- "" # get data frame element <- out[[i]] # split name at ".", so we have all components the data frame refers to (i.e. # fixed/random, conditional/zero-inflated, group-lvl or random slope etc.) # as character vector parts <- unlist(strsplit(i, ".", fixed = TRUE)) # iterate all parts of the component names, to create title attribute for (j in 1:length(parts)) { # Rename "fixed", "random" etc. into proper titles. Here we have the # "Main title" of a subcomponent (like "Random effects") if (parts[j] %in% c("fixed", "random") || (has_zeroinf && parts[j] %in% c("conditional", "zero_inflated"))) { tmp <- switch( parts[j], "fixed" = "Fixed effects", "random" = "Random effects", "conditional" = "(conditional)", "zero_inflated" = "(zero-inflated)" ) title1 <- paste0(title1, " ", tmp) } else if (!parts[j] %in% c("conditional", "zero_inflated")) { # here we have the "subtitles" of a subcomponent # (like "Intercept: Group-Level 1") title2 <- paste0(title2, " ", parts[j]) } } .effects <- unique(element$Effects) .component <- unique(element$Component) # we don't need "Effects" and "Random" column any more keep <- setdiff(colnames(element), c("Effects", "Component", "Cleaned_Parameter")) element <- element[, c("Cleaned_Parameter", keep)] # add attributes attr(element, "main_title") <- .trim(title1) attr(element, "sub_title") <- .trim(title2) attr(element, "Effects") <- .effects attr(element, "Component") <- .component element }) names(out) <- list_names out } insight/R/get_random.R0000644000176200001440000000173513502531610014364 0ustar liggesusers#' @title Get the data from random effects #' @name get_random #' #' @description Returns the data from all random effects terms. #' #' @inheritParams find_random #' #' @return The data from all random effects terms, as data frame. Or \code{NULL} #' if model has no random effects. #' #' @examples #' library(lme4) #' data(sleepstudy) #' # prepare some data... #' sleepstudy$mygrp <- sample(1:5, size = 180, replace = TRUE) #' sleepstudy$mysubgrp <- NA #' for (i in 1:5) { #' filter_group <- sleepstudy$mygrp == i #' sleepstudy$mysubgrp[filter_group] <- #' sample(1:30, size = sum(filter_group), replace = TRUE) #' } #' #' m <- lmer( #' Reaction ~ Days + (1 | mygrp / mysubgrp) + (1 | Subject), #' data = sleepstudy #' ) #' #' head(get_random(m)) #' @export get_random <- function(x) { if (.is_empty_object(find_random(x))) { warning("No random effects found in model.") return(NULL) } get_data(x, effects = "random") } insight/R/link_inverse.R0000644000176200001440000002623513614067316014752 0ustar liggesusers#' @title Get link-inverse function from model object #' @name link_inverse #' #' @description Returns the link-inverse function from a model object. #' #' @param what For \code{gamlss} models, indicates for which distribution #' parameter the link (inverse) function should be returned; for \code{betareg} #' or \code{DirichletRegModel}, can be \code{"mean"} or \code{"precision"}. #' @inheritParams find_predictors #' @inheritParams find_formula #' #' @return A function, describing the inverse-link function from a model-object. #' For multivariate-response models, a list of functions is returned. #' #' @examples #' # example from ?stats::glm #' counts <- c(18, 17, 15, 20, 10, 20, 25, 13, 12) #' outcome <- gl(3, 1, 9) #' treatment <- gl(3, 3) #' m <- glm(counts ~ outcome + treatment, family = poisson()) #' #' link_inverse(m)(.3) #' # same as #' exp(.3) #' @importFrom stats family make.link gaussian formula #' @export link_inverse <- function(x, ...) { UseMethod("link_inverse") } # Default method --------------------------------------- #' @export link_inverse.default <- function(x, ...) { if (inherits(x, "list") && .obj_has_name(x, "gam")) { x <- x$gam class(x) <- c(class(x), c("glm", "lm")) } if (inherits(x, "Zelig-relogit")) { stats::make.link(link = "logit")$linkinv } else { tryCatch( { stats::family(x)$linkinv }, error = function(x) { NULL } ) } } # GLM families --------------------------------------------------- #' @export link_inverse.glm <- function(x, ...) { tryCatch( { stats::family(x)$linkinv }, error = function(x) { NULL } ) } #' @export link_inverse.speedglm <- link_inverse.glm #' @export link_inverse.bigglm <- link_inverse.glm # Tobit Family --------------------------------- #' @export link_inverse.tobit <- function(x, ...) { .make_tobit_family(x)$linkinv } #' @export link_inverse.crch <- link_inverse.tobit #' @export link_inverse.survreg <- link_inverse.tobit #' @export link_inverse.psm <- link_inverse.tobit #' @export link_inverse.flexsurvreg <- function(x, ...) { dist <- parse(text = .safe_deparse(x$call))[[1]]$dist .make_tobit_family(x, dist)$linkinv } # Gaussian identity links --------------------------------- #' @export link_inverse.lm <- function(x, ...) { stats::gaussian(link = "identity")$linkinv } #' @export link_inverse.bayesx <- link_inverse.lm #' @export link_inverse.biglm <- link_inverse.lm #' @export link_inverse.aovlist <- link_inverse.lm #' @export link_inverse.ivreg <- link_inverse.lm #' @export link_inverse.iv_robust <- link_inverse.lm #' @export link_inverse.mixed <- link_inverse.lm #' @export link_inverse.lme <- link_inverse.lm #' @export link_inverse.rq <- link_inverse.lm #' @export link_inverse.rqss <- link_inverse.lm #' @export link_inverse.crq <- link_inverse.lm #' @export link_inverse.crqs <- link_inverse.lm #' @export link_inverse.censReg <- link_inverse.lm #' @export link_inverse.plm <- link_inverse.lm #' @export link_inverse.lm_robust <- link_inverse.lm #' @export link_inverse.truncreg <- link_inverse.lm #' @export link_inverse.felm <- link_inverse.lm #' @export link_inverse.feis <- link_inverse.lm #' @export link_inverse.gls <- link_inverse.lm #' @export link_inverse.lmRob <- link_inverse.lm #' @export link_inverse.MANOVA <- link_inverse.lm #' @export link_inverse.RM <- link_inverse.lm #' @export link_inverse.lmrob <- link_inverse.lm #' @export link_inverse.complmrob <- link_inverse.lm #' @export link_inverse.speedlm <- link_inverse.lm #' @rdname link_inverse #' @export link_inverse.betareg <- function(x, what = c("mean", "precision"), ...) { what <- match.arg(what) switch( what, "mean" = x$link$mean$linkinv, "precision" = x$link$precision$linkinv ) } #' @rdname link_inverse #' @export link_inverse.DirichletRegModel <- function(x, what = c("mean", "precision"), ...) { what <- match.arg(what) if (x$parametrization == "common") { stats::make.link("logit")$linkinv } else { switch( what, "mean" = stats::make.link("logit")$linkinv, "precision" = stats::make.link("log")$linkinv ) } } # Logit links ----------------------------------- #' @export link_inverse.gmnl <- function(x, ...) { stats::make.link("logit")$linkinv } #' @export link_inverse.mlogit <- link_inverse.gmnl #' @export link_inverse.BBreg <- link_inverse.gmnl #' @export link_inverse.BBmm <- link_inverse.gmnl #' @export link_inverse.coxph <- link_inverse.gmnl #' @export link_inverse.survfit <- link_inverse.gmnl #' @export link_inverse.coxme <- link_inverse.gmnl #' @export link_inverse.lrm <- link_inverse.gmnl #' @export link_inverse.logistf <- link_inverse.gmnl #' @export link_inverse.multinom <- link_inverse.gmnl # Log-links --------------------------------------- #' @export link_inverse.zeroinfl <- function(x, ...) { stats::make.link("log")$linkinv } #' @export link_inverse.hurdle <- link_inverse.zeroinfl #' @export link_inverse.zerotrunc <- link_inverse.zeroinfl # Ordinal models ----------------------------------- #' @export link_inverse.clm <- function(x, ...) { stats::make.link(.get_ordinal_link(x))$linkinv } #' @export link_inverse.clmm <- link_inverse.clm #' @export link_inverse.clm2 <- link_inverse.clm #' @export link_inverse.mixor <- link_inverse.clm # Other models ---------------------------- #' @export link_function.cglm <- function(x, ...) { link <- parse(text = .safe_deparse(x$call))[[1]]$link method <- parse(text = .safe_deparse(x$call))[[1]]$method if (!is.null(method) && method == "clm") { link <- "identiy" } stats::make.link(link = link)$linkinv } #' @export link_inverse.cpglmm <- function(x, ...) { f <- .get_cplm_family(x) f$linkinv } #' @export link_inverse.cpglm <- link_inverse.cpglmm #' @export link_inverse.fixest <- function(x, ...) { if (is.null(x$family)) { if (!is.null(x$method) && x$method == "feols") { stats::gaussian(link = "identity")$linkinv } } else if (inherits(x$family, "family")) { x$family$linkinv } else { link <- switch( x$family, "poisson" = , "negbin" = "log", "logit" = "logit", "gaussian" = "identity" ) stats::make.link(link)$linkinv } } #' @export link_inverse.feglm <- link_inverse.fixest #' @export link_inverse.glmx <- function(x, ...) { x$family$glm$linkinv } #' @export link_inverse.glmmadmb <- function(x, ...) { x$ilinkfun } #' @export link_inverse.polr <- function(x, ...) { link <- x$method if (link == "logistic") link <- "logit" stats::make.link(link)$linkinv } #' @export link_inverse.svyolr <- function(x, ...) { link <- x$method if (link == "logistic") link <- "logit" stats::make.link(link)$linkinv } #' @export link_inverse.LORgee <- function(x, ...) { if (grepl(pattern = "logit", x = x$link, fixed = TRUE)) { link <- "logit" } else if (grepl(pattern = "probit", x = x$link, fixed = TRUE)) { link <- "probit" } else if (grepl(pattern = "cauchit", x = x$link, fixed = TRUE)) { link <- "cauchit" } else if (grepl(pattern = "cloglog", x = x$link, fixed = TRUE)) { link <- "cloglog" } else { link <- "logit" } stats::make.link(link)$linkinv } #' @export link_inverse.glimML <- function(x, ...) { stats::make.link(x@link)$linkinv } #' @export link_inverse.glmmTMB <- function(x, ...) { ff <- stats::family(x) if ("linkinv" %in% names(ff)) { ff$linkinv } else if ("link" %in% names(ff) && is.character(ff$link)) { stats::make.link(ff$link)$linkinv } else { match.fun("exp") } } #' @export link_inverse.MCMCglmm <- function(x, ...) { NULL } #' @export link_inverse.gamm <- function(x, ...) { x <- x$gam class(x) <- c(class(x), c("glm", "lm")) NextMethod() } #' @export link_inverse.stanmvreg <- function(x, ...) { fam <- stats::family(x) lapply(fam, function(.x) .x$linkinv) } #' @export link_inverse.gbm <- function(x, ...) { switch( x$distribution$name, laplace = , tdist = , gaussian = stats::gaussian(link = "identity")$linkinv, poisson = stats::poisson(link = "log")$linkinv, huberized = , adaboost = , coxph = , bernoulli = stats::make.link("logit")$linkinv ) } #' @export link_inverse.brmsfit <- function(x, ...) { fam <- stats::family(x) if (is_multivariate(x)) { lapply(fam, .brms_link_inverse) } else { .brms_link_inverse(fam) } } #' @rdname link_inverse #' @export link_inverse.gamlss <- function(x, what = c("mu", "sigma", "nu", "tau"), ...) { what <- match.arg(what) faminfo <- get(x$family[1], asNamespace("gamlss"))() switch( what, "mu" = faminfo$mu.linkinv, "sigma" = faminfo$sigma.linkinv, "nu" = faminfo$nu.linkinv, "tau" = faminfo$tau.linkinv, faminfo$mu.linkinv ) } #' @export link_inverse.bamlss <- function(x, ...) { flink <- stats::family(x)$links[1] tryCatch( { stats::make.link(flink)$linkinv }, error = function(e) { print_colour("\nCould not find appropriate link-inverse-function.\n", "red") } ) } #' @export link_inverse.glmmPQL <- function(x, ...) { x$family$linkinv } #' @export link_inverse.MixMod <- link_inverse.glmmPQL #' @export link_inverse.cgam <- link_inverse.glmmPQL #' @export link_inverse.vgam <- function(x, ...) { x@family@linkinv } #' @export link_inverse.vglm <- link_inverse.vgam #' @export link_inverse.gam <- function(x, ...) { li <- tryCatch( { .gam_family(x)$linkinv }, error = function(x) { NULL } ) if (is.null(li)) { mi <- .gam_family(x) if (.obj_has_name(mi, "linfo")) { if (.obj_has_name(mi$linfo, "linkinv")) { li <- mi$linfo$linkinv } else { li <- mi$linfo[[1]]$linkinv } } } li } # helper -------------- .brms_link_inverse <- function(fam) { # do we have custom families? if (!is.null(fam$family) && (is.character(fam$family) && fam$family == "custom")) { il <- stats::make.link(fam$link)$linkinv } else { if ("linkinv" %in% names(fam)) { il <- fam$linkinv } else if ("link" %in% names(fam) && is.character(fam$link)) { il <- stats::make.link(fam$link)$linkinv } else { ff <- get(fam$family, asNamespace("stats")) il <- ff(fam$link)$linkinv } } il } #' @importFrom stats poisson .get_cplm_family <- function(x) { link <- parse(text = .safe_deparse(x@call))[[1]]$link if (!is.numeric(link)) { stats::poisson(link = link) } else { if (!requireNamespace("statmod", quietly = TRUE)) { stop("Package 'statmod' required. Please install it.") } statmod::tweedie(link.power = link) } } insight/R/helper_functions.R0000644000176200001440000003666513613300340015623 0ustar liggesusers# remove trailing/leading spaces from character vectors .trim <- function(x) gsub("^\\s+|\\s+$", "", x) # remove NULL elements from lists .compact_list <- function(x) x[!sapply(x, function(i) length(i) == 0 || is.null(i) || any(i == "NULL"))] # remove empty string from character .compact_character <- function(x) x[!sapply(x, function(i) nchar(i) == 0 || is.null(i) || any(i == "NULL"))] # remove values from vector .remove_values <- function(x, values) { remove <- x %in% values if (any(remove)) { x <- x[!remove] } x } # rename values in a vector .rename_values <- function(x, old, new) { x[x %in% old] <- new x } # is string empty? .is_empty_string <- function(x) { x <- x[!is.na(x)] length(x) == 0 || all(nchar(x) == 0) } # is string empty? .is_empty_object <- function(x) { if (is.list(x)) { x <- tryCatch( { .compact_list(x) }, error = function(x) { x } ) } # this is an ugly fix because of ugly tibbles if (inherits(x, c("tbl_df", "tbl"))) x <- as.data.frame(x) x <- suppressWarnings(x[!is.na(x)]) length(x) == 0 || is.null(x) } # does string contain pattern? .string_contains <- function(pattern, x) { pattern <- paste0("\\Q", pattern, "\\E") grepl(pattern, x, perl = TRUE) } # has object an element with given name? .obj_has_name <- function(x, name) { name %in% names(x) } # checks if a brms-models is a multi-membership-model .is_multi_membership <- function(x) { if (inherits(x, "brmsfit")) { re <- find_random(x, split_nested = TRUE, flatten = TRUE) any(grepl("^(mmc|mm)\\(", re)) } else { return(FALSE) } } # merge data frames, remove double columns .merge_dataframes <- function(data, ..., replace = TRUE) { # check for identical column names tmp <- cbind(...) if (nrow(data) == 0) { return(tmp) } doubles <- colnames(tmp) %in% colnames(data) # keep order? reihenfolge <- c(which(!doubles), which(doubles)) # remove duplicate column names, if requested if (replace && any(doubles)) tmp <- tmp[, !doubles, drop = FALSE] # bind all data x <- cbind(tmp, data) # restore order if (replace) { # check for correct length. if "data" had duplicated variables, # but not all variable are duplicates, add indices of regular values if (ncol(x) > length(reihenfolge)) { # get remaining indices xl <- seq_len(ncol(x))[-seq_len(length(reihenfolge))] # add to "reihefolge" reihenfolge <- c(reihenfolge, xl) } # sort data frame x <- x[, order(reihenfolge), drop = FALSE] } x } # removes random effects from a formula that is in lmer-notation #' @importFrom stats terms drop.terms update .get_fixed_effects <- function(f) { f_string <- .safe_deparse(f) # for some wird brms-models, we also have a "|" in the response. # in order to check for "|" only in the random effects, we have # to remove the response here... f_response <- .safe_deparse(f[[2]]) f_predictors <- sub(f_response, "", f_string, fixed = TRUE) if (grepl("|", f_predictors, fixed = TRUE)) { # intercept only model, w/o "1" in formula notation? # e.g. "Reaction ~ (1 + Days | Subject)" if (length(f) > 2 && grepl("^\\(", .safe_deparse(f[[3]]))) { # check if we have any terms *after* random effects, e.g. # social ~ (1|school) + open + extro + agree + school if (.formula_empty_after_random_effect(f_predictors)) { # here we fix intercept only models with random effects, # like social ~ (1|school). .trim(paste0(.safe_deparse(f[[2]]), " ~ 1")) } else { # here we fix models where random effects come first, # like social ~ (1|school) + open + extro + agree + school # the regex removes "(1|school) + " .trim(gsub("\\((.*)\\)(\\s)*\\+(\\s)*", "", f_string)) } } else if (!grepl("\\+(\\s)*\\((.*)\\)", f_string)) { f_terms <- stats::terms(f) pos_bar <- grep("|", labels(f_terms), fixed = TRUE) no_bars <- stats::drop.terms(f_terms, pos_bar, keep.response = TRUE) stats::update(f_terms, no_bars) } else { .trim(gsub("\\+(\\s)*\\((.*)\\)", "", f_string)) } } else { .trim(gsub("\\+(\\s)*\\((.*)\\)", "", f_string)) } } # check if any terms appear in the formula after random effects # like "~ (1|school) + open + extro + agree + school" # this regex removes "(1|school)", as well as any +, -, *, whitespace etc. # if there are any chars left, these come from further terms that come after # random effects... .formula_empty_after_random_effect <- function(f) { nchar(gsub("(~|\\+|\\*|-|/|:)", "", gsub(" ", "", gsub("\\((.*)\\)", "", f)))) == 0 } # extract random effects from formula .get_model_random <- function(f, split_nested = FALSE, model) { is_special <- inherits(model, c("MCMCglmm", "gee", "LORgee", "mixor", "clmm2", "felm", "feis", "BFBayesFactor", "BBmm", "glimML", "MANOVA", "RM", "cglm")) if (!requireNamespace("lme4", quietly = TRUE)) { stop("To use this function, please install package 'lme4'.") } if (identical(.safe_deparse(f), "~0") || identical(.safe_deparse(f), "~1")) { return(NULL) } re <- sapply(lme4::findbars(f), .safe_deparse) if (is_special && .is_empty_object(re)) { re <- all.vars(f[[2L]]) if (length(re) > 1) { re <- as.list(re) split_nested <- FALSE } } else { re <- .trim(substring(re, max(gregexpr(pattern = "\\|", re)[[1]]) + 1)) } # check for multi-membership models if (inherits(model, "brmsfit")) { if (grepl("mm\\((.*)\\)", re)) { re <- trimws(unlist(strsplit(gsub("mm\\((.*)\\)", "\\1", re), ","))) } } if (split_nested) { # remove parenthesis for nested models re <- unique(unlist(strsplit(re, "\\:"))) # nested random effects, e.g. g1 / g2 / g3, deparse to "g0:(g1:g2)". # when we split at ":", we have "g0", "(g1" and "g2)". In such cases, # we need to remove the parantheses. But we need to preserve them in # case we have group factors in other models, like panelr, where we can # have "lag(union)" as group factor. In such cases, parantheses should be # preserved. We here check if group factors, after passing to "clean_names()", # still have "(" or ")" in their name, and if so, just remove parantheses # for these cases... has_parantheses <- vapply( clean_names(re), function(i) { grepl("[\\(\\)]", x = i) }, logical(1) ) if (any(has_parantheses)) { re[has_parantheses] <- gsub(pattern = "[\\(\\)]", replacement = "", x = re[has_parantheses]) } re } else { unique(re) } } # in case we need the random effects terms as formula (symbol), # not as character string, then call this functions instead of # .get_model_random() .get_group_factor <- function(x, f) { if (is.list(f)) { f <- lapply(f, function(.x) { .get_model_random(.x, split_nested = TRUE, x) }) } else { f <- .get_model_random(f, split_nested = TRUE, x) } if (is.null(f)) { return(NULL) } if (is.list(f)) { f <- lapply(f, function(i) sapply(i, as.symbol)) } else { f <- sapply(f, as.symbol) } f } # to reduce redundant code, I extract this part which is used several # times accross this package .get_elements <- function(effects, component) { elements <- c("conditional", "conditional2", "conditional3", "precision", "nonlinear", "random", "zero_inflated", "zero_inflated_random", "dispersion", "instruments", "interactions", "simplex", "smooth_terms", "sigma", "nu", "tau", "correlation", "slopes", "cluster", "extra", "scale") elements <- switch( effects, all = elements, fixed = elements[elements %in% c("conditional", "conditional2", "conditional3", "precision", "zero_inflated", "dispersion", "instruments", "interactions", "simplex", "smooth_terms", "correlation", "slopes", "sigma", "nonlinear", "cluster", "extra", "scale")], random = elements[elements %in% c("random", "zero_inflated_random")] ) elements <- switch( component, all = elements, conditional = elements[elements %in% c("conditional", "conditional2", "conditional3", "precision", "nonlinear", "random", "slopes")], zi = , zero_inflated = elements[elements %in% c("zero_inflated", "zero_inflated_random")], dispersion = elements[elements == "dispersion"], instruments = elements[elements == "instruments"], interactions = elements[elements == "interactions"], simplex = elements[elements == "simplex"], sigma = elements[elements == "sigma"], smooth_terms = elements[elements == "smooth_terms"], correlation = elements[elements == "correlation"], cluster = elements[elements == "cluster"], nonlinear = elements[elements == "nonlinear"], slopes = elements[elements == "slopes"], extra = elements[elements == "extra"], scale = elements[elements == "scale"], precision = elements[elements == "precision"] ) elements } # checks if a mixed model fit is singular or not. Need own function, # because lme4::isSingular() does not work with glmmTMB #' @importFrom stats na.omit .is_singular <- function(x, vals, tolerance = 1e-5) { if (!requireNamespace("lme4", quietly = TRUE)) { stop("Package `lme4` needs to be installed to compute variances for mixed models.", call. = FALSE) } tryCatch( { if (inherits(x, c("glmmTMB", "clmm", "cpglmm"))) { is_si <- any(sapply(vals$vc, function(.x) any(abs(diag(.x)) < tolerance))) } else if (inherits(x, "merMod")) { theta <- lme4::getME(x, "theta") diag.element <- lme4::getME(x, "lower") == 0 is_si <- any(abs(theta[diag.element]) < tolerance) } else if (inherits(x, "MixMod")) { vc <- diag(x$D) is_si <- any(sapply(vc, function(.x) any(abs(.x) < tolerance))) } else if (inherits(x, "lme")) { is_si <- any(abs(stats::na.omit(as.numeric(diag(vals$vc))) < tolerance)) } else { is_si <- FALSE } is_si }, error = function(x) { FALSE } ) } # Filter parameters from Stan-model fits .filter_pars <- function(l, parameters = NULL, is_mv = NULL) { if (!is.null(parameters)) { if (is.null(is_mv)) { is_mv <- isTRUE(attr(l, "is_mv", exact = TRUE) == "1") } if (is_multivariate(l) || is_mv) { for (i in names(l)) { l[[i]] <- .filter_pars_univariate(l[[i]], parameters) } } else { l <- .filter_pars_univariate(l, parameters) } if (isTRUE(is_mv)) attr(l, "is_mv") <- "1" } l } .filter_pars_univariate <- function(l, parameters) { lapply(l, function(component) { unlist(unname(sapply( parameters, function(pattern) { component[grepl(pattern = pattern, x = component, perl = TRUE)] }, simplify = FALSE ))) }) } # remove column .remove_column <- function(data, variables) { data[, -which(colnames(data) %in% variables), drop = FALSE] } .grep_smoothers <- function(x) { grepl("^(s\\()", x, perl = TRUE) | grepl("^(ti\\()", x, perl = TRUE) | grepl("^(te\\()", x, perl = TRUE) | grepl("^(t2\\()", x, perl = TRUE) | grepl("^(gam::s\\()", x, perl = TRUE) | grepl("^(VGAM::s\\()", x, perl = TRUE) | grepl("^(mgcv::s\\()", x, perl = TRUE) | grepl("^(mgcv::ti\\()", x, perl = TRUE) | grepl("^(mgcv::te\\()", x, perl = TRUE) | grepl("^(brms::s\\()", x, perl = TRUE) | grepl("^(brms::t2\\()", x, perl = TRUE) | grepl("^(smooth_sd\\[)", x, perl = TRUE) } .grep_zi_smoothers <- function(x) { grepl("^(s\\.\\d\\()", x, perl = TRUE) | grepl("^(gam::s\\.\\d\\()", x, perl = TRUE) | grepl("^(mgcv::s\\.\\d\\()", x, perl = TRUE) } .grep_non_smoothers <- function(x) { grepl("^(?!(s\\())", x, perl = TRUE) & # this one captures smoothers in zi- or mv-models from gam grepl("^(?!(s\\.\\d\\())", x, perl = TRUE) & grepl("^(?!(ti\\())", x, perl = TRUE) & grepl("^(?!(te\\())", x, perl = TRUE) & grepl("^(?!(t2\\())", x, perl = TRUE) & grepl("^(?!(gam::s\\())", x, perl = TRUE) & grepl("^(?!(gam::s\\.\\d\\())", x, perl = TRUE) & grepl("^(?!(VGAM::s\\())", x, perl = TRUE) & grepl("^(?!(mgcv::s\\())", x, perl = TRUE) & grepl("^(?!(mgcv::s\\.\\d\\())", x, perl = TRUE) & grepl("^(?!(mgcv::ti\\())", x, perl = TRUE) & grepl("^(?!(mgcv::te\\())", x, perl = TRUE) & grepl("^(?!(brms::s\\())", x, perl = TRUE) & grepl("^(?!(brms::t2\\())", x, perl = TRUE) & grepl("^(?!(smooth_sd\\[))", x, perl = TRUE) } # .split_formula <- function(f) { # rhs <- if (length(f) > 2) # f[[3L]] # else # f[[2L]] # # lapply(.extract_formula_parts(rhs), .safe_deparse) # } # # # .extract_formula_parts <- function(x, sep = "|") { # if (is.null(x)) # return(NULL) # rval <- list() # if (length(x) > 1L && x[[1L]] == sep) { # while (length(x) > 1L && x[[1L]] == sep) { # rval <- c(x[[3L]], rval) # x <- x[[2L]] # } # } # c(x, rval) # } .safe_deparse <- function(string) { paste0(sapply(deparse(string, width.cutoff = 500), .trim, simplify = TRUE), collapse = " ") } #' @importFrom stats family .gam_family <- function(x) { faminfo <- tryCatch( { stats::family(x) }, error = function(e) { NULL } ) # try to set manually, if not found otherwise if (is.null(faminfo)) { faminfo <- tryCatch( { x$family }, error = function(e) { NULL } ) } faminfo } # for models with zero-inflation component, return # required component of model-summary .filter_component <- function(dat, component) { switch( component, "cond" = , "conditional" = dat[dat$Component == "conditional", ], "zi" = , "zero_inflated" = dat[dat$Component == "zero_inflated", ], "dispersion" = dat[dat$Component == "dispersion", ], "smooth_terms" = dat[dat$Component == "smooth_terms", ], dat ) } # capitalizes the first letter in a string .capitalize <- function(x) { capped <- grep("^[A-Z]", x, invert = TRUE) substr(x[capped], 1, 1) <- toupper(substr(x[capped], 1, 1)) x } .remove_backticks_from_parameter_names <- function(x) { if (is.data.frame(x) && "Parameter" %in% colnames(x)) { x$Parameter <- gsub("`", "", x$Parameter, fixed = TRUE) } x } .remove_backticks_from_string <- function(x) { if (is.character(x)) { x <- gsub("`", "", x, fixed = TRUE) } x } .remove_backticks_from_matrix_names <- function(x) { if (is.matrix(x)) { colnames(x) <- gsub("`", "", colnames(x), fixed = TRUE) rownames(x) <- gsub("`", "", colnames(x), fixed = TRUE) } x } #' @importFrom stats reshape #' @keywords internal .gather <- function(x, names_to = "key", values_to = "value", columns = colnames(x)) { if (is.numeric(columns)) columns <- colnames(x)[columns] dat <- stats::reshape( x, idvar = "id", ids = row.names(x), times = columns, timevar = names_to, v.names = values_to, varying = list(columns), direction = "long" ) if (is.factor(dat[[values_to]])) dat[[values_to]] <- as.character(dat[[values_to]]) dat[, 1:(ncol(dat) - 1), drop = FALSE] } insight/NEWS.md0000644000176200001440000002036513615554214013031 0ustar liggesusers# insight 0.8.1 ## New supported model classes * `cglm` (*cglm*), `DirichletRegModel` (*DirichletReg*). ## General * Improved efficiency of `find_parameters()` and `get_parameters()` for mixed models with large samples and many random effects, and only fixed effects where requested. ## Changes to functions * `model_info()` now returns `$is_multinomial` for multinomial (but not ordinal or cumulative) link models. * `format_value()` gets an `as_percent` argument to format values as percentages. ## Bug fixes * Fixed issue in `get_data()` for *clmm2*-models. * Fixed issue in `get_data()` for models that used the `lspline()`-function. * Fixed issue in `get_statistic()` for *multinom* models. * Fixed issue in `get_priors()` for *stanreg* models with flat intercept priors. * Fixed tests that failed due to latest **fixest** update. # insight 0.8.0 ## New supported model classes * `brglm` (*brglm*), `cgam`, `cgamm` (*cgam*), `cpglm`, `cpglmm` (*cplm*), `feglm` (*apaca*), `glmmadmb` (*glmmADMB*), `glmx` (*glmx*), partial support for `mcmc` (*coda*), `mixor` (*mixor*), `MANOVA`, `RM` (*MANOVA.RM*). ## General * Better handling of `clm2`, `clmm2` and `rqss` models. ## New functions * `format_ci()` (re-implemented and slightly enhanced from _parameters_), to format confidence/credible intervals. ## Changes to functions * `find_parameters()` now also works for `BFBayesFactor` objects. * Suppress non-informative warning in `get_data()` for model data with weights. * `format_value()` automatically uses scientific notation for *very* large numbers (> 1e+5). Furthermore, the check for integer values was made more robust, to avoid warnings when checking *very* large numbers for integer type. * Improved `find_parameters()`, `get_parameters()` and `clean_parameters()` for `BFBayesFactor`-objects. * `get_priors()` now works for `stanmvreg` objects. * Other minor improvements. ## Bug fixes * Better detect Tweedie-models in `model_info()`. * Fixed issue in `find_random_slopes()` for *panelr*-models with multiple random-effect parts. * Fixed issues with `zerotrunc` models. * Fixed issues with `brmsfit` models with correlated random effects. * Fixed issue with edge-cases in `clean_names()`. * Fixed issue with breaking changes with latest *brms*-update. * Further minor bug fixes. # insight 0.7.1 ## New supported model classes * `complmrob` (*complmrob*), `fixest` (*fixest*), `mclogit` and `mmclogit` (*mclogit*). ## Bug fixes * Fixed bug in `find_formula()` for mixed models, when random effects are written before any fixed effects terms (like `social ~ (1|school) + open + extro`). * Fixed bug in `model_info()` for *VGAM* models, where logit-link was not always correctly identified. * Fixed issue in `get_priors()` for *brmsfit* models, where parameters of conditional and zero-inflated model components had identical names. This caused errors in `bayestestR::simulate_prior()`. * Fixed CRAN check issue. # insight 0.7.0 ## Breaking changes * In order to unify column names across easystats-packages, `get_parameters()` and `get_priors()` now return column names according to our naming conventions (i.e. capitalized column names). * `model_info()` returned both `$is_zeroinf` and `$is_zero_inflated` for zero-inflated models. Now `$is_zeroinf` is softly deprecated, so `model_info()` will return `$is_zero_inflated` only in future updates. ## New supported model classes * `aareg` (*survival*), `brmultinom` and `bracl` (*brglm2*), and `wbgee` (*panelr*). Furthermore, for different model-types from *panelr* models (within-between, between, etc.) are now also supported. * Preliminary support for `rma` models (*metafor*). ## Changes to functions * `get_statistic()` supports `multinom` models (*nnet*). * `link_inverse()` gets a `what`-argument, to return the link-inverse function for specific distribution parameters from **gamls** models. ## Bug fixes * Fixed edge case for `find_weights()`. * Fixed bug in `get_statistic()` for *glmmTMB* models that won't return any data. # insight 0.6.0 ## New supported model classes * `bayesx` (*R2BayesX*), `bamlss` (*bamlss*) and `flexsurvreg` (*flexsurv*). Note that support for these models is still somewhat experimental. * Support for *lavaan* and *blavaan* was added, but only applies to some of the functions: `get_data()`, `get_parameters()`, `find_parameters()`, `clean_parameters()`, `find_algorithm()` and `get_priors()` (the two latter only for *blavaan*). ## New functions * `get_statistic()` to return the test statistic of model estimates. * `get_varcov()` to return the variance-covariance matrix for models. * `supported_models()` to print a list of supported models. ## Changes to functions * `model_info()` now returns the element `is_survival` for survival models. * `model_info()` now returns the element `is_truncated` for truncated regression, or *brmsfit* models with `trunc()` as additional response part. * `model_info()` now recognizes beta and beta inflated families from package *gamlss*. * Better support for nonlinear quantile regression (`quantreg::nlrq()`). * Better support for nonlinear mixed models (`lme4::nlmer()`). Note that model-specification requires the random term to be written in parentheses, i.e. `(slope | group)`. ## Bug fixes * Fixed issues in `get_data()`, `find_parameters()` and `get_parameters()` for *gamlss* models. * Fixed issue in `get_data()` for *plm* models, where the `index`-argument was used in the `plm()`-function call. * Fixed issue in `get_data()`, `find_predictors()` and `find_variables()` for *brmsfit* multi-membership-models. * `is_model()` did not recognize objects of class `anova` and `manova`. * `model_info()` now correctly recognizes censored regression models from *brmsfit*. * Fixed issues in `find_parameters()` and `get_parameters()` with *multinom* models. * Fixed issues in `clean_names()` for cases where variable transformations where made in specific patterns, like `log(test/10)`. # insight 0.5.0 ## Breaking Changes * The previous `is_model()` function has been renamed to `is_model_supported()` since it was unclear if the function checked the entered object was a model or a supported model in *insight*. The new `is_model()` function checks if the entered object is a model object, while `is_model_supported()` checks if a supported model object. ## New functions * `find_statistic()` to return the test statistic of a regression model. * `format_value()` and `format_table()` as utility-functions to format (model) output, especially for tabular output. * `color_if()` as utility-function to add color formatting to values, depending on certain conditions. ## General * Make extraction of model family information more stable for gam-objects. ## Changes to functions * `find_parameters()` and `get_parameters()` now also support objects of class `sim` and `sim.merMod` (from `arm::sim()`). * `get_variance()` now also supports models of class *clmm*. * `find_predictors()` and `find_variables()` now include the Euclidean distance matrix for spatial models from *glmmTMB* (returned as random effects element, or more precise, as random slope). ## Bug fixes * `find_formula()` now extracts group factors of random effects for *gamlss* models. * `find_parameters()` and `get_parameters()` no longer show `NA` coefficients from group factors of random effects for *gamlss* models. * `find_parameters()` and `get_parameters()` did not work for multivariate response models of class *brmsfit* when argument `parameters` was specified. * `get_data()` dropped value and variable label attributes, when model frame contained matrix variables (like splines). * `get_priors()` swapped column names `location` and `scale` for *brmsfit* -objects. * `get_parameters()` did not work for *glmmTMB* models without zero-inflation component. * `find_predictors()` did not remove parentheses from terms in multiple nested random effects. * Better support for *gam* models (package *mgcv*) with `ziplss` or `mvn` families. # insight 0.4.1 ## Changes to functions * `get_variance()` now supports models with Gamma-family. * `get_weights()` and `find_weights()` now work for *brms*-models. ## Bug fixes * Fix CRAN-check issues due to recent update from the *panelr*-package. insight/MD50000644000176200001440000002564213615601156012244 0ustar liggesusersa68b8069f64557fb840ae9239dc0fb3d *DESCRIPTION 1d230dddca5c883f07afd8d2e43b7689 *NAMESPACE 23e4076f41eb880be125ada95aab9588 *NEWS.md dc8d65e62e7ee58df1114ff139fe5401 *R/all_equal_models.R aeca14e11166af6a7ad19c8c21551513 *R/clean_names.R 6b8f93d2ba388f38667af3bea5557e7d *R/clean_parameters.R ba35db022b740bf2066e840380408f71 *R/color_if.R 61df921b8e7647fff07c89f4ab4a5868 *R/colour_tools.R c888fecd5d81eda3c585b57fca655db1 *R/compute_variances.R 9fb3e79faf86feaa0578b9a91c6924d0 *R/download_model.R 811ab9a0b92a13b62f42d9a56c81df6c *R/find_algorithm.R dc6b504924c16b02fec34300c92c6446 *R/find_formula.R f8057a8964264c1007c9b74f52614218 *R/find_interactions.R 4aa90e0256c81d65c531dd548adfb51c *R/find_parameters.R a6ffe6d96d59c7c589bdf464c94da049 *R/find_predictors.R 0835173d8a559f33fc37ef59ed976bba *R/find_random.R a357e8071edf03de22d5b947cfae2956 *R/find_random_slopes.R d86db51b6e871ea60dad254beafc09bc *R/find_response.R cc8c6450febfb5f3faddb08618f0fbfd *R/find_statistic.R 860de0cfcde49b8a1397a958714f59aa *R/find_terms.R 1ebab94b309b14236b84cd3b73be80a9 *R/find_variables.R d16a518ed5705a955057ae1058778ab8 *R/find_weights.R 01dec103d0d215941b1473f1beca696b *R/format_ci.R 29ad6cfb1b57e90bca0cdc0bc1473b6e *R/format_table.R a70305d27d72d270314567ae3388acb6 *R/format_value.R d6dc55ee44810cc1201e796673b12c9e *R/get_data.R 5d6c13813da07a8acdb595a7aaf02aab *R/get_nested_lme_varcorr.R 5e1d11f96cd160f07508c901ee79f88e *R/get_parameters.R 44003292e87c658d58b42149be373209 *R/get_predictors.R b8124d501cd79411a9ce67ed20b5f005 *R/get_priors.R 9af4f178cdfe7128237c4db1ed145307 *R/get_random.R 61ca352eff83e6860560442ab68c582f *R/get_response.R 602067eaaca35158800f20096c2c46d7 *R/get_statistic.R d78909827263dcee0f141d3b4a61f715 *R/get_varcov.R e869293c4fcbda4b6a5bf8e8923e22f7 *R/get_variances.R 5e3c2ada471c68a4d45bbb2490d238da *R/get_weights.R 35bda8f5c9af2fb037923dce8de72881 *R/has_intercept.R f041f21e1a7e3540246f9e54cd6646ce *R/helper_functions.R fb41342f64857e6a9fdc4b20419394c1 *R/is_model.R 1326b5d39b4268017897a5611bd00339 *R/is_model_supported.R 1b8cc11b5206d6f136e2761e0bff1f34 *R/is_multivariate.R ace8a39f103ed6ae780afab76e739b45 *R/is_nullmodel.R c396c972a7c0b18ca30cf6774d46c86f *R/link_function.R 0d929fb2ebf441b5b6bc89121a760734 *R/link_inverse.R 556d09d7a345d7b1b22528d92e937d9e *R/model_info.R 33adafadfaf1246d82534173f8510db7 *R/n_obs.R 95729c3d67066619fb165216b4511c7d *R/print.easystats_check.R 355cfb877da1a7c340e6e6d2711cc02d *R/print_color.R db236865adde5dd4b126a266dcbb9e12 *R/print_parameters.R e5aa52e6210ba720de303f92bb92f30a *R/utils_get_data.R 122e6f31b4a75f4a02990a7b1a5e2400 *R/utils_model_info.R e4f5dd5b481548cf07a74bdfde6127df *README.md 81a6a76b4d761d40a511741da114abe1 *build/partial.rdb ff97a19cbd5f291efce6296e130388d4 *build/vignette.rds fbd584790cacf26fa9e176040cb6d473 *inst/CITATION 58f1d39b8b4b9805bcc145fe995669b4 *inst/WORDLIST 7d1e8774d6fc84dfb770919331105163 *inst/doc/insight.R f966cff74a57381b9576307abb67c811 *inst/doc/insight.Rmd c0a539aac73bfc4a9083f9ffab6aa127 *inst/doc/insight.html ece9b53ac27ac5a772fe520d56f05b37 *man/all_models_equal.Rd f3ab0ff98a9182fd26a16b86c2441840 *man/clean_names.Rd d4fc6c09087717bfc4b1ac578ae2c4a9 *man/clean_parameters.Rd 9f17ef3a3aceb898a2331877f8c4b5d7 *man/color_if.Rd 3cb443dcacfa4ad1d223a80896b7de05 *man/dot-colour_detect.Rd aeb7141efd9f340944e5b5a6e3b06274 *man/download_model.Rd 734dc632a0c942a6c4bd3b04cb972714 *man/figures/logo.png 944ac94f1489aa4a78766026bcdbfba0 *man/find_algorithm.Rd 2452c443f163a0cbf1301296437caf01 *man/find_formula.Rd d69548da157044e65c3f45897c377c64 *man/find_interactions.Rd 072b2fd222b7cdeec3f37652386e0ee9 *man/find_parameters.Rd d3c0b9c5df0361ced429b60cd0ada321 *man/find_predictors.Rd 1b480e76a54bbaf023497438bf989591 *man/find_random.Rd cd327282231be6a00867254e654ad3ec *man/find_random_slopes.Rd 65f2e159a21134f78171fab9dc9a5d57 *man/find_response.Rd ca69717fc48a0a7aec230c10f2576687 *man/find_statistic.Rd 405aa07633011c061c4a8e6e6252e87a *man/find_terms.Rd f8d4fa43aed638a1d146cb63f1038057 *man/find_variables.Rd eaf5b6847622a83e757b2cdb65841e3e *man/find_weights.Rd 6f39e464ab9c8f57c3cb74f195d205ec *man/format_ci.Rd b072b187fc8ccbe3670c4b6a76963e1e *man/format_table.Rd de1a59d5008614e72530f6cc989c0f31 *man/format_value.Rd ab7f1c92b066499b7c67c790eebbc5e7 *man/get_data.Rd 13e37ff6361e0421eb045d00d7ded95e *man/get_parameters.Rd a954191d7fad45d859b82fb6be682bcd *man/get_predictors.Rd c1463a27e53d7830cfd3a1772bb34876 *man/get_priors.Rd 973e08c92295e83ab5aa98d6be9d9c5c *man/get_random.Rd 1703f76c56aef7b0a8aef7fb2b06885e *man/get_response.Rd f3d8ef1570cf41964b79c674f35fe400 *man/get_statistic.Rd 7182186091a95dab4a364d71c2e514e1 *man/get_varcov.Rd 7c8dd1dead299be14d43aafb80c3fdc2 *man/get_variance.Rd 052063ba912ae4c675e2617dfc546e5a *man/get_weights.Rd 890c95cf4d4afc9c6f08c8fffce71bc1 *man/has_intercept.Rd c05022b512db3533a33f4407c68daeda *man/is_model.Rd 5027ed84606ecd86e32f9fab257eeac6 *man/is_model_supported.Rd a7a67eb751941698a2c4974a2924975e *man/is_multivariate.Rd fe388894ccf9332f5595f2084de9036d *man/is_nullmodel.Rd cf35b9749dca2bcf83268fcd122774b9 *man/link_function.Rd 23fea2811f4e2f3887cd17fc7554151e *man/link_inverse.Rd 8d7388e5cbbc41103d31ead8603ae3e7 *man/model_info.Rd adb8540f10a7fc3d5db253a7a7779cdc *man/n_obs.Rd 06a901761fcf0229358ab16965bb66ac *man/print_color.Rd b9b4dad841c173259551b05c95e1fb89 *man/print_parameters.Rd 52e4cfc6848ac432bf7398e4f7b41889 *tests/spelling.R 3dd94ae1e0749ef1002f19657e397e9c *tests/testthat.R 9aed3735208b6021bef14abfbbb1428b *tests/testthat/test-BBmm.R 5dd24406d389762aabe47934d041f1a1 *tests/testthat/test-BBreg.R fd5f3ed1b491395fd868873c1cc3c9e3 *tests/testthat/test-BayesFactorBF.R 94da1ec7d940380cec89beebff2cee51 *tests/testthat/test-GLMMadaptive.R 8065c872e8fe1f2924e0f4f12c2ea1b5 *tests/testthat/test-Gam2.R 52c2f8a2d321b8720929568e88e17ce1 *tests/testthat/test-LORgee.R 4c763e3b95422697d561452b3c56cf23 *tests/testthat/test-MCMCglmm.R 13f801a82df54ed18f4c2f6c80e8f80d *tests/testthat/test-all_models_equal.R 8b75cac17e186c9e022739c19d3a5ac2 *tests/testthat/test-aovlist.R b67ecfaa85c6ef20c9a2bae450cdee4a *tests/testthat/test-backticks.R 79708e58b61f24385d6507b55c5eed9f *tests/testthat/test-betabin.R 957f2479a2d1c17af5fa04d1297477a8 *tests/testthat/test-betareg.R 733f0d8e30a49b1b4712865dc7396bfb *tests/testthat/test-bigglm.R b44364f7575aaa520b0edaa5131eb0fe *tests/testthat/test-blmer.R 4155d85275a17145ff51ef6868fd55dd *tests/testthat/test-brms.R 7fcbbc2fd523ed1ddffd73fb2f4f86fb *tests/testthat/test-censReg.R d22ba49a163f552c55feb601c8a799d5 *tests/testthat/test-cgam.R 03371b63ce766a6664781cec54250a8d *tests/testthat/test-clean_names.R 6da3fb5e729cc514d90674f11f03ffd1 *tests/testthat/test-clm.R b23bd9dcde395c763b9d44508e7f437f *tests/testthat/test-clm2.R 2ddb2eeda393640e691e035b265bb8bb *tests/testthat/test-clmm.R 1f4d897184d35112e414535a3d907b2b *tests/testthat/test-coxme.R 3c3c15234105d77544b920fc76ba3e8c *tests/testthat/test-coxph.R 82e4d513c4c66a5c6d66a3f9708d3362 *tests/testthat/test-cpglmm.R 83b518e4f236a2436026ac492061786c *tests/testthat/test-crch.R d483a040cc014385cb3bc26311e2faa3 *tests/testthat/test-data.frame.R b662d6ab1dd3e436ddc9ae6c8adda936 *tests/testthat/test-feis.R 9f536e0c63368278aa51db2bdc17b85f *tests/testthat/test-felm.R b16e13c6b188ac4354c5bac87be8ba5b *tests/testthat/test-find_predictor_nested_re.R e7cdd93a1ddf3549d4c8e292744b8d3f *tests/testthat/test-fixest.R 2a1f111701da379b67504f9b71917651 *tests/testthat/test-format.R c06cc2ea6f4e95ef416c581933c25c24 *tests/testthat/test-gam.R 61538fc31cd9f27e12cdc1b5c3105ee5 *tests/testthat/test-gamlss.R 7b6bca67537f7a693c3f7204e139f252 *tests/testthat/test-gamm.R 4d16a8a0efda98800a4bf797c1078847 *tests/testthat/test-gamm4.R 4c79580a3b43e3a6c15501dd8332e287 *tests/testthat/test-gbm.R 05248a55faac183c565ca83578535565 *tests/testthat/test-gee.R 8385354858fed70e4754b67c9b66c900 *tests/testthat/test-geeglm.R d4a4a706ad076fb2fdabe70b76023c99 *tests/testthat/test-glm.R 6843a85f2ad7021c701b9078c9faf049 *tests/testthat/test-glmmTMB.R f10ca5e562ffdeafe41e05d7014c6710 *tests/testthat/test-glmrob_base.R 1111e497893bd07eb1bd4b98f04f821d *tests/testthat/test-gls.R 92efb4694e248c2afc0bac79dedc56b6 *tests/testthat/test-gmnl.R cb2caa435f66f5eaf382fcd4c0427e84 *tests/testthat/test-has_intercept.R 8a7b0f4435c8f665b33f11264c39f4fc *tests/testthat/test-hurdle.R 7060a383e0d0f9d74d67403a49683a2c *tests/testthat/test-is_nullmodel.R 85f5db194c0bf9e8d7839f0b17257348 *tests/testthat/test-iv_robust.R e2ddfc68139cab3f9b70b3e9edf7b405 *tests/testthat/test-ivreg.R 14a2b2521c94b8733f160f5a9456edf8 *tests/testthat/test-lm.R 0374bc51a563526cbaa8fba9b830fd02 *tests/testthat/test-lm_robust.R 8241e4d63c78bdecb01ca524faf71bea *tests/testthat/test-lme.R 68f05a78f3b6e264c79c6c0f09bd696f *tests/testthat/test-lmer.R 71db4717b46d02faa15d1093a8e9bb99 *tests/testthat/test-lmrob_base.R 4474e95b660138754653d4fd8e60ed62 *tests/testthat/test-logistf.R 3e58715f2c7874343a9e50df23ce255b *tests/testthat/test-mixed.R 6b239a7a073800c8c60477b0b61fd16b *tests/testthat/test-mlogit.R 7fb20ff47143bddc06cf5fd2b7e48074 *tests/testthat/test-model_data.R 1ca31d326415b541f6f648c11bb36358 *tests/testthat/test-multinom.R 897582736faf5ba78dab495971a875ac *tests/testthat/test-mvrstanarm.R eb1c57e5001a3fce271a7f4113d45c61 *tests/testthat/test-namespace.R 716ced5290ed0760839f7fd7441b5cbd *tests/testthat/test-negbin.R 1c19193291e5cfbec10aed335b1c77b2 *tests/testthat/test-nlmer.R 0834b1c8afdeb25eb22ce536408b5107 *tests/testthat/test-ols.R 99509a9c325345c7111dd571a45bc400 *tests/testthat/test-panelr.R 94ae87449625e15e69d9355074707033 *tests/testthat/test-plm.R 383b125a184f45c2a9a2cc946032c72f *tests/testthat/test-polr.R ea659cee47de22e1b1bd5ef45cca567c *tests/testthat/test-psm.R 6dcf3f9a614caa9904c4986a3c97c2a7 *tests/testthat/test-response_data2.R 9112c12cfecec61344e39d7b1ddabd93 *tests/testthat/test-rlmer.R 49a99f9911999a7f421e94b8ccc4fcc0 *tests/testthat/test-rms.R d5411a53849d4ccac730fa24d3ba8fd0 *tests/testthat/test-rq.R 36ff4675cc8111abf31c657e26765243 *tests/testthat/test-rqss.R 2f046107347d18468d0c67b312d09599 *tests/testthat/test-rstanarm.R 896104e77424208ac1c224eec7f8c96b *tests/testthat/test-spatial.R 1ea0ae21b0ebfb3f7c9616f3f15542a1 *tests/testthat/test-speedglm.R 16d19b137855d3294964cd612bda370d *tests/testthat/test-speedlm.R d39579cc70cb6d57816fc5fd1de6fc80 *tests/testthat/test-survey.R a8908e7d7629654a94e36c02545530c6 *tests/testthat/test-survfit.R 506f47f2e186d41e9675ea7536420e0f *tests/testthat/test-survreg.R 212a6bbe0862876de239f948e788fb65 *tests/testthat/test-tobit.R 646ee584092453ab22f321a2618f9b8f *tests/testthat/test-truncreg.R 3e4f4aa8ca386085aa830f83487c2afb *tests/testthat/test-vgam.R 5d0d52c0cb1bcd5deb509a9e1c24ad1d *tests/testthat/test-vglm.R 63d361b549958d9d3c845f9f978a9c8a *tests/testthat/test-zeroinfl.R b3d6e26817614fc39933f2c801d2e074 *vignettes/figure3a.png d2532dd9f119fa9ee21d77389ce0d16c *vignettes/figure3b.png 517c45734e9c9dc34738063ff7e81ed0 *vignettes/figure3c.png 3e810b7bbd075fb581640cac1148ce86 *vignettes/figure3d.png f966cff74a57381b9576307abb67c811 *vignettes/insight.Rmd 1a24201ab3d9d3a81bf9dd53bb5102cd *vignettes/insight_design_1.png insight/inst/0000755000176200001440000000000013615562366012711 5ustar liggesusersinsight/inst/doc/0000755000176200001440000000000013615562367013457 5ustar liggesusersinsight/inst/doc/insight.html0000644000176200001440000105542713615562366016027 0ustar liggesusers Getting Started with Accessing Model Information

Getting Started with Accessing Model Information

When fitting any statistical model, there are many useful pieces of information that are simultaneously calculated and stored beyond coefficient estimates and general model fit statistics. Although there exist some generic functions to obtain model information and data, many package-specific modeling functions do not provide such methods to allow users to access such valuable information.

insight is an R-package that fills this important gap by providing a suite of functions to support almost any model. The goal of insight, then, is to provide tools to provide easy, intuitive, and consistent access to information contained in model objects. These tools aid applied research in virtually any field who fit, diagnose, and present statistical models by streamlining access to every aspect of many model objects via consistent syntax and output.

Built with non-programmers in mind, insight offers a broad toolbox for making model and data information easily accessible. While insight offers many useful functions for working with and understanding model objects (discussed below), we suggest users start with model_info(), as this function provides a clean and consistent overview of model objects (e.g., functional form of the model, the model family, link function, number of observations, variables included in the specification, etc.). With a clear understanding of the model introduced, users are able to adapt other functions for more nuanced exploration of and interaction with virtually any model object.

Overview of Core Functions

A statistical model is an object describing the relationship between variables. Although there are a lot of different types of models, each with their specificities, most of them also share some common components. The goal of insight is to help you retrieve these components.

The get_* prefix extracts values (or data) associated with model-specific objects (e.g., parameters or variables), while the find_* prefix lists model-specific objects (e.g., priors or predictors). These are powerful families of functions allowing for great flexibility in use, whether at a high, descriptive level (find_*) or narrower level of statistical inspection and reporting (get_*). We point users to the package documentation or the complementary package website, https://easystats.github.io/insight/, for a detailed list of the arguments associated with each function as well as the returned values from each function.

Definition of Model Components

The functions from insight address different components of a model. In an effort to avoid confusion about specific “targets” of each function, in this section we provide a short explanation of insight’s definitions of regression model components.

Data

The dataset used to fit the model.

Parameters

Values estimated or learned from data that capture the relationship between variables. In regression models, these are usually referred to as coefficients.

Response and Predictors

  • response: the outcome or response variable (dependent variable) of a regression model.
  • predictor: independent variables of (the fixed part of) a regression model. For mixed models, variables that are only in the random effects part (i.e. grouping factors) of the model are not returned as predictors by default. However, these can be included using additional arguments in the function call, treating predictors are “unique”. As such, if a variable appears as a fixed effect and a random slope, it is treated as one (the same) predictor.

Variables

Any unique variable names that appear in a regression model, e.g., response variable, predictors or random effects. A “variable” only relates to the unique occurrence of a term, or the term name. For instance, the expression x + poly(x, 2) has only the variable x.

Terms

Terms themselves consist of variable and factor names separated by operators, or involve arithmetic expressions. For instance, the expression x + poly(x, 2) has one variable x, but two terms x and poly(x, 2).

Random Effects

  • random slopes: variables that are specified as random slopes in a mixed effects model.
  • random or grouping factors: variables that are specified as grouping variables in a mixed effects model.

Examples

Aren’t the predictors, terms, and parameters the same thing?

In some cases, yes. But not in all cases, and sometimes it is useful to have the “bare” variable names (terms), but sometimes it is also useful to have the information about a possible transformation of variables. That is the main reason for having functions that cover similar aspects of a model object (like find_terms() and find_predictors() or find_variables()).

Here are some examples that demonstrate the differences of each function:

Finally, there is find_parameters(). Parameters are also known as coefficients, and find_parameters() does exactly that: returns the model coefficients.

Examples of Use Cases in R

We now would like to provide examples of use cases of the insight package. These examples probably do not cover typical real-world problems, but serve as illustration of the core idea of this package: The unified interface to access model information. insight should help both users and package developers in order to reduce the hassle with the many exceptions from various modelling packages when accessing model information.

Making Predictions at Specific Values of a Term of Interest

Say, the goal is to make predictions for a certain term, holding remaining co-variates constant. This is achieved by calling predict() and feeding the newdata-argument with the values of the term of interest as well as the “constant” values for remaining co-variates. The functions get_data() and find_predictors() are used to get this information, which then can be used in the call to predict().

In this example, we fit a simple linear model, but it could be replaced by (m)any other models, so this approach is “universal” and applies to many different model objects.

Printing Model Coefficients

The next example should emphasize the possibilities to generalize functions to many different model objects using insight. The aim is simply to print coefficients in a complete, human readable sentence.

The first approach uses the functions that are available for some, but obviously not for all models, to access the information about model coefficients.

As we can see, the function fails for gam-models. As the access to models depends on the type of the model in the R ecosystem, we would need to create specific functions for all models types. With insight, users can write a function without having to worry about the model type.

Examples of Use Cases in R packages

insight is already used by different packages to solve problems that typically occur when the users’ inputs are different model objects of varying complexity.

For example, ggeffects, a package that computes and visualizes marginal effects of regression models, requires extraction of the data (get_data()) that was used to fit the models, and also the retrieval all model predictors (find_predictors()) to decide which covariates are held constant when computing marginal effects. All of this information is required in order to create a data frame for predict(newdata=<data frame>). Furthermore, the models’ link-functions (link_function()) resp. link-inverse-functions (link_inverse()) are required to obtain predictors at the model’s response scale.

The sjPlot-package creates plots or summary tables from regression models, and uses insight-functions to get model-information (model_info() or find_response()), which is used to build the components of the final plot or table. This information helps, for example, in labeling table columns by providing information on the effect type (odds ratio, incidence rate ratio, etc.) or the different model components, which split plots and tables into the “conditional” and “zero-inflated” parts of a model, in the cases of models with zero-inflation.

bayestestR mainly relies on get_priors() and get_parameters() to retrieve the necessary information to compute various indices or statistics of Bayesian models (like HDI, Credible Interval, MCSE, effective sample size, Bayes factors, etc.). The advantage of get_parameters() in this context is that regardless of the number of parameters the posterior distribution has, the necessary data can be easily accessed from the model objects. There is no need to write original, complicated code or regular expressions.

A last example is the performance-package, which provides functions for computing measures to assess model quality. Many of these indices (e.g. check for overdispersion or zero-inflation, predictive accuracy, logloss, RMSE, etc.) require the number of observations (n_obs()) or the data from the response-variable (get_response()). Again, in this context, functions from insight are helpful, because they offer a unified access to this information.

insight/inst/doc/insight.Rmd0000644000176200001440000003224213614067316015564 0ustar liggesusers--- title: "Getting Started with Accessing Model Information" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{insight} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) if (!requireNamespace("lme4", quietly = TRUE)) { knitr::opts_chunk$set(eval = FALSE) } ``` When fitting any statistical model, there are many useful pieces of information that are simultaneously calculated and stored beyond coefficient estimates and general model fit statistics. Although there exist some generic functions to obtain model information and data, many package-specific modeling functions do not provide such methods to allow users to access such valuable information. **insight** is an R-package that fills this important gap by providing a suite of functions to support almost any model. The goal of **insight**, then, is to provide tools to provide *easy*, *intuitive*, and *consistent* access to information contained in model objects. These tools aid applied research in virtually any field who fit, diagnose, and present statistical models by streamlining access to every aspect of many model objects via consistent syntax and output. Built with non-programmers in mind, **insight** offers a broad toolbox for making model and data information easily accessible. While **insight** offers many useful functions for working with and understanding model objects (discussed below), we suggest users start with `model_info()`, as this function provides a clean and consistent overview of model objects (*e.g.*, functional form of the model, the model family, link function, number of observations, variables included in the specification, etc.). With a clear understanding of the model introduced, users are able to adapt other functions for more nuanced exploration of and interaction with virtually any model object. ## Overview of Core Functions A statistical model is an object describing the relationship between variables. Although there are a lot of *different types* of models, each with their specificities, most of them also share some *common components*. The goal of **insight** is to help you retrieve these components. The `get_*` prefix extracts *values* (or *data*) associated with model-specific objects (e.g., parameters or variables), while the `find_*` prefix *lists* model-specific objects (e.g., priors or predictors). These are powerful families of functions allowing for great flexibility in use, whether at a high, descriptive level (`find_*`) or narrower level of statistical inspection and reporting (`get_*`). We point users to the package documentation or the complementary package website, https://easystats.github.io/insight/, for a detailed list of the arguments associated with each function as well as the returned values from each function. ```{r out.width="100%", echo=FALSE} knitr::include_graphics("insight_design_1.png", dpi = 72) ``` ## Definition of Model Components The functions from **insight** address different components of a model. In an effort to avoid confusion about specific "targets" of each function, in this section we provide a short explanation of **insight**'s definitions of regression model components. ### Data The dataset used to fit the model. ### Parameters Values estimated or learned from data that capture the relationship between variables. In regression models, these are usually referred to as *coefficients*. ### Response and Predictors * **response**: the outcome or response variable (dependent variable) of a regression model. * **predictor**: independent variables of (the _fixed_ part of) a regression model. For mixed models, variables that are only in the _random effects_ part (i.e. grouping factors) of the model are not returned as predictors by default. However, these can be included using additional arguments in the function call, treating predictors are "unique". As such, if a variable appears as a fixed effect and a random slope, it is treated as one (the same) predictor. ```{r out.width="65%", echo=FALSE} knitr::include_graphics("figure3a.png", dpi = 72) ``` ### Variables Any unique variable names that appear in a regression model, e.g., response variable, predictors or random effects. A "variable" only relates to the unique occurrence of a term, or the term name. For instance, the expression `x + poly(x, 2)` has only the variable `x`. ```{r out.width="80%", echo=FALSE} knitr::include_graphics("figure3b.png", dpi = 72) ``` ### Terms Terms themselves consist of variable and factor names separated by operators, or involve arithmetic expressions. For instance, the expression `x + poly(x, 2)` has _one_ variable `x`, but _two_ terms `x` and `poly(x, 2)`. ```{r out.width="80%", echo=FALSE} knitr::include_graphics("figure3c.png", dpi = 72) ``` ### Random Effects * **random slopes**: variables that are specified as random slopes in a mixed effects model. * **random or grouping factors**: variables that are specified as grouping variables in a mixed effects model. ```{r out.width="65%", echo=FALSE} knitr::include_graphics("figure3d.png", dpi = 72) ``` ## Examples *Aren't the predictors, terms, and parameters the same thing?* In some cases, yes. But not in all cases, and sometimes it is useful to have the "bare" variable names (terms), but sometimes it is also useful to have the information about a possible transformation of variables. That is the main reason for having functions that cover similar aspects of a model object (like `find_terms()` and `find_predictors()` or `find_variables()`). Here are some examples that demonstrate the differences of each function: ```{r echo=TRUE,message=FALSE,warning=FALSE} library(insight) library(lme4) data(sleepstudy) sleepstudy$mygrp <- sample(1:5, size = 180, replace = TRUE) sleepstudy$mysubgrp <- NA sleepstudy$Weeks <- sleepstudy$Days / 7 sleepstudy$cat <- as.factor(sample(letters[1:4], nrow(sleepstudy), replace = TRUE)) for (i in 1:5) { filter_group <- sleepstudy$mygrp == i sleepstudy$mysubgrp[filter_group] <- sample(1:30, size = sum(filter_group), replace = TRUE) } model <- lmer( Reaction ~ Days + I(Days^2) + log1p(Weeks) + cat + (1 | mygrp / mysubgrp) + (1 + Days | Subject), data = sleepstudy ) ``` ```{r echo=TRUE,message=FALSE,warning=FALSE} # find the response variable find_response(model) # find all predictors, fixed part by default find_predictors(model) # find random effects, grouping factors only find_random(model) # find random slopes find_random_slopes(model) # find all predictors, including random effects find_predictors(model, effects = "all", component = "all") # find all terms, including response and random effects # this is essentially the same as the previous example plus response find_terms(model) # find all variables, i.e. also quadratic or log-transformed predictors find_variables(model) ``` Finally, there is `find_parameters()`. Parameters are also known as *coefficients*, and `find_parameters()` does exactly that: returns the model coefficients. ```{r echo=TRUE,message=FALSE,warning=FALSE} # find model parameters, i.e. coefficients find_parameters(model) ``` ## Examples of Use Cases in R We now would like to provide examples of use cases of the **insight** package. These examples probably do not cover typical real-world problems, but serve as illustration of the core idea of this package: The unified interface to access model information. **insight** should help both users and package developers in order to reduce the hassle with the many exceptions from various modelling packages when accessing model information. ### Making Predictions at Specific Values of a Term of Interest Say, the goal is to make predictions for a certain term, holding remaining co-variates constant. This is achieved by calling `predict()` and feeding the `newdata`-argument with the values of the term of interest as well as the "constant" values for remaining co-variates. The functions `get_data()` and `find_predictors()` are used to get this information, which then can be used in the call to `predict()`. In this example, we fit a simple linear model, but it could be replaced by (m)any other models, so this approach is "universal" and applies to many different model objects. ``` r library(insight) m <- lm( Sepal.Length ~ Species + Petal.Width + Sepal.Width, data = iris ) dat <- get_data(m) pred <- find_predictors(m, flatten = TRUE) l <- lapply(pred, function(x) { if (is.numeric(dat[[x]])) mean(dat[[x]]) else unique(dat[[x]]) }) names(l) <- pred l <- as.data.frame(l) cbind(l, predictions = predict(m, newdata = l)) #> Species Petal.Width Sepal.Width predictions #> 1 setosa 1.199333 3.057333 5.101427 #> 2 versicolor 1.199333 3.057333 6.089557 #> 3 virginica 1.199333 3.057333 6.339015 ``` ### Printing Model Coefficients The next example should emphasize the possibilities to generalize functions to many different model objects using **insight**. The aim is simply to print coefficients in a complete, human readable sentence. The first approach uses the functions that are available for some, but obviously not for all models, to access the information about model coefficients. ``` r print_params <- function(model){ paste0( "My parameters are ", paste0(row.names(summary(model)$coefficients), collapse = ", "), ", thank you for your attention!" ) } m1 <- lm(Sepal.Length ~ Petal.Width, data = iris) print_params(m1) #> [1] "My parameters are (Intercept), Petal.Width, thank you for your attention!" # obviously, something is missing in the output m2 <- mgcv::gam(Sepal.Length ~ Petal.Width + s(Petal.Length), data = iris) print_params(m2) #> [1] "My parameters are , thank you for your attention!" ``` As we can see, the function fails for *gam*-models. As the access to models depends on the type of the model in the R ecosystem, we would need to create specific functions for all models types. With **insight**, users can write a function without having to worry about the model type. ``` r print_params <- function(model){ paste0( "My parameters are ", paste0(insight::find_parameters(model, flatten = TRUE), collapse = ", "), ", thank you for your attention!" ) } m1 <- lm(Sepal.Length ~ Petal.Width, data = iris) print_params(m1) #> [1] "My parameters are (Intercept), Petal.Width, thank you for your attention!" m2 <- mgcv::gam(Sepal.Length ~ Petal.Width + s(Petal.Length), data = iris) print_params(m2) #> [1] "My parameters are (Intercept), Petal.Width, s(Petal.Length), thank you for your attention!" ``` ## Examples of Use Cases in R packages **insight** is already used by different packages to solve problems that typically occur when the users' inputs are different model objects of varying complexity. For example, [**ggeffects**](https://strengejacke.github.io/ggeffects), a package that computes and visualizes marginal effects of regression models, requires extraction of the data (`get_data()`) that was used to fit the models, and also the retrieval all model predictors (`find_predictors()`) to decide which covariates are held constant when computing marginal effects. All of this information is required in order to create a data frame for `predict(newdata=)`. Furthermore, the models' link-functions (`link_function()`) resp. link-inverse-functions (`link_inverse()`) are required to obtain predictors at the model's response scale. The [**sjPlot**-package](https://strengejacke.github.io/sjPlot/) creates plots or summary tables from regression models, and uses **insight**-functions to get model-information (`model_info()` or `find_response()`), which is used to build the components of the final plot or table. This information helps, for example, in labeling table columns by providing information on the effect type (odds ratio, incidence rate ratio, etc.) or the different model components, which split plots and tables into the "conditional" and "zero-inflated" parts of a model, in the cases of models with zero-inflation. [**bayestestR**](https://easystats.github.io/bayestestR/) mainly relies on `get_priors()` and `get_parameters()` to retrieve the necessary information to compute various indices or statistics of Bayesian models (like HDI, Credible Interval, MCSE, effective sample size, Bayes factors, etc.). The advantage of `get_parameters()` in this context is that regardless of the number of parameters the posterior distribution has, the necessary data can be easily accessed from the model objects. There is no need to write original, complicated code or regular expressions. A last example is the [**performance**-package](https://easystats.github.io/performance/), which provides functions for computing measures to assess model quality. Many of these indices (e.g. check for overdispersion or zero-inflation, predictive accuracy, logloss, RMSE, etc.) require the number of observations (`n_obs()`) or the data from the response-variable (`get_response()`). Again, in this context, functions from **insight** are helpful, because they offer a unified access to this information. insight/inst/doc/insight.R0000644000176200001440000000457313615562366015257 0ustar liggesusers## ---- include = FALSE--------------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) if (!requireNamespace("lme4", quietly = TRUE)) { knitr::opts_chunk$set(eval = FALSE) } ## ----out.width="100%", echo=FALSE--------------------------------------------- knitr::include_graphics("insight_design_1.png", dpi = 72) ## ----out.width="65%", echo=FALSE---------------------------------------------- knitr::include_graphics("figure3a.png", dpi = 72) ## ----out.width="80%", echo=FALSE---------------------------------------------- knitr::include_graphics("figure3b.png", dpi = 72) ## ----out.width="80%", echo=FALSE---------------------------------------------- knitr::include_graphics("figure3c.png", dpi = 72) ## ----out.width="65%", echo=FALSE---------------------------------------------- knitr::include_graphics("figure3d.png", dpi = 72) ## ----echo=TRUE,message=FALSE,warning=FALSE------------------------------------ library(insight) library(lme4) data(sleepstudy) sleepstudy$mygrp <- sample(1:5, size = 180, replace = TRUE) sleepstudy$mysubgrp <- NA sleepstudy$Weeks <- sleepstudy$Days / 7 sleepstudy$cat <- as.factor(sample(letters[1:4], nrow(sleepstudy), replace = TRUE)) for (i in 1:5) { filter_group <- sleepstudy$mygrp == i sleepstudy$mysubgrp[filter_group] <- sample(1:30, size = sum(filter_group), replace = TRUE) } model <- lmer( Reaction ~ Days + I(Days^2) + log1p(Weeks) + cat + (1 | mygrp / mysubgrp) + (1 + Days | Subject), data = sleepstudy ) ## ----echo=TRUE,message=FALSE,warning=FALSE------------------------------------ # find the response variable find_response(model) # find all predictors, fixed part by default find_predictors(model) # find random effects, grouping factors only find_random(model) # find random slopes find_random_slopes(model) # find all predictors, including random effects find_predictors(model, effects = "all", component = "all") # find all terms, including response and random effects # this is essentially the same as the previous example plus response find_terms(model) # find all variables, i.e. also quadratic or log-transformed predictors find_variables(model) ## ----echo=TRUE,message=FALSE,warning=FALSE------------------------------------ # find model parameters, i.e. coefficients find_parameters(model) insight/inst/CITATION0000644000176200001440000000057313504604506014041 0ustar liggesusersbibentry( bibtype = "article", title = "insight: A Unified Interface to Access Information from Model Objects in R.", volume = "4", doi = "10.21105/joss.01412", number = "38", journal = "Journal of Open Source Software", author = c(person("Daniel", "Lüdecke"), person("Philip", "Waggoner"), person("Dominique", "Makowski")), year = "2019", pages = "1412" ) insight/inst/WORDLIST0000644000176200001440000000151713602213235014067 0ustar liggesusers’s AER afex al Anova aod apaca bamlss BayesFactor bayestestR BayesX biglm blavaan brglm brms brmsfit censReg clmm colour coloured Coloured comparator complmrob cplm crch doi DOI easystats estimatr et feisr fixest flexsurv gam gamls gamlss gbm ggeffects github GLMM GLMMadaptive glmmADMB glmmTMB glmx HDI HRQoL https Ieno intra intraclass io joss JOSS lavaan lfe logloss mclogit MCSE metafor mgcv MixMod mixor modelling monotic multgee multinom Nakagawa Newburgh nnet occurence optimizers panelr plm poisson polr pre quantreg rms robustbase robustlmm Savel'ev Schielzeth Schielzeth’s sjPlot specificities speedglm stanmvreg stanreg substracted substraction tibbles tranformations tweedie Tweedie untransformed variates VGAM warmup warmups Zuur