| Title: | Hierarchical Partitioning of R2 for Spatial Simultaneous Autoregressive Model |
|---|---|
| Description: | Conducts hierarchical partitioning to calculate individual contributions of spatial and predictors (groups) towards total R2 for spatial simultaneous autoregressive model. |
| Authors: | Jiangshan Lai [aut, cre] (ORCID: <https://orcid.org/0000-0002-0279-8816>) |
| Maintainer: | Jiangshan Lai <[email protected]> |
| License: | GPL |
| Version: | 0.0-2 |
| Built: | 2026-05-23 07:39:18 UTC |
| Source: | https://github.com/cran/spatialreg.hp |
This function computes the Nagelkerke pseudo R-squared for a linear model ('lm' object) by comparing the log-likelihood of the fitted model to that of the null model (intercept-only).
nagelkerke_r2_lm(model)nagelkerke_r2_lm(model)
model |
An object of class |
Nagelkerke R² is a normalized version of the likelihood ratio R², scaled to have a maximum of 1. It is commonly used for generalized linear models but can also be applied to linear models.
The formula used is:
where is the log-likelihood of the fitted model and is the log-likelihood of the null model.
A numeric value representing the Nagelkerke pseudo R-squared.
Nagelkerke, N. J. D. (1991). A note on a general definition of the coefficient of determination. Biometrika, 78(3), 691–692.
data(mtcars) fit <- lm(mpg ~ wt + hp, data = mtcars) nagelkerke_r2_lm(fit)data(mtcars) fit <- lm(mpg ~ wt + hp, data = mtcars) nagelkerke_r2_lm(fit)
spatialreg.hp objectPlot for a spatialreg.hp object
## S3 method for class 'spatialreghp' plot(x, plot.perc = FALSE, commonality = FALSE, color = NULL, dig = 4, ...)## S3 method for class 'spatialreghp' plot(x, plot.perc = FALSE, commonality = FALSE, color = NULL, dig = 4, ...)
x |
A |
plot.perc |
Logical;if TRUE, the bar plot (based on ggplot2 package) of the percentage to individual effects of variables and spatial towards total explained variation, the default is FALSE to show plot with original individual effects. |
commonality |
Logical; If TRUE, the result of commonality analysis is shown, the default is FALSE. |
color |
Color of variables. |
dig |
Integer; number of decimal places in Venn diagram. |
... |
unused |
a ggplot object
Jiangshan Lai [email protected]
library(spatialreg) library(spdep) data(oldcol, package="spdep") listw <- spdep::nb2listw(COL.nb, style="W") ev <- eigenw(listw) W <- as(listw, "CsparseMatrix") trMatc <- trW(W, type="mult") COL.lag.eig <- lagsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, listw=listw, method="eigen", control=list(pre_eig=ev, OrdVsign=1)) spatialreg.hp(COL.lag.eig) spatialreg.hp(COL.lag.eig,iv=list(pre1="INC",pre2="HOVAL")) spatialreg.hp(COL.lag.eig,iv=list(pre1="INC",pre2="HOVAL"),commonality=TRUE) plot(spatialreg.hp(COL.lag.eig)) plot(spatialreg.hp(COL.lag.eig,commonality=TRUE),commonality=TRUE)library(spatialreg) library(spdep) data(oldcol, package="spdep") listw <- spdep::nb2listw(COL.nb, style="W") ev <- eigenw(listw) W <- as(listw, "CsparseMatrix") trMatc <- trW(W, type="mult") COL.lag.eig <- lagsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, listw=listw, method="eigen", control=list(pre_eig=ev, OrdVsign=1)) spatialreg.hp(COL.lag.eig) spatialreg.hp(COL.lag.eig,iv=list(pre1="INC",pre2="HOVAL")) spatialreg.hp(COL.lag.eig,iv=list(pre1="INC",pre2="HOVAL"),commonality=TRUE) plot(spatialreg.hp(COL.lag.eig)) plot(spatialreg.hp(COL.lag.eig,commonality=TRUE),commonality=TRUE)
Hierarchical Partitioning of R2 for Spatial Simultaneous Autoregressive Model
spatialreg.hp(mod, iv = NULL, commonality = FALSE)spatialreg.hp(mod, iv = NULL, commonality = FALSE)
mod |
Fitted spatialreg objects. |
iv |
optional The relative importance of predictor groups will be assessed. The input for iv should be a list, where each element contains the names of variables belonging to a specific group. These variable names must correspond to the predictor variables defined in the model (mod). |
commonality |
Logical; If TRUE, the result of commonality analysis is shown, the default is FALSE. |
This function conducts hierarchical partitioning to calculate the individual contributions of spatial and each predictor towards total R2 from spatialreg package for spatial simultaneous autoregressive model.
Total.R2 |
The R2 for the full model. |
commonality.analysis |
If commonality=TRUE, a matrix containing the value and percentage of all commonality (2^N-1 for N predictors or matrices). |
Individual.R2 |
A matrix containing individual effects and percentage of individual effects for spatial and each predictor |
Jiangshan Lai [email protected]
Lai J.,Zhu W., Cui D.,Mao L.(2023)Extension of the glmm.hp package to Zero-Inflated generalized linear mixed models and multiple regression.Journal of Plant Ecology,16(6):rtad038<DOI:10.1093/jpe/rtad038>
Lai J.,Zou Y., Zhang S.,Zhang X.,Mao L.(2022)glmm.hp: an R package for computing individual effect of predictors in generalized linear mixed models.Journal of Plant Ecology,15(6):1302-1307<DOI:10.1093/jpe/rtac096>
Lai J.,Zou Y., Zhang J.,Peres-Neto P.(2022) Generalizing hierarchical and variation partitioning in multiple regression and canonical analyses using the rdacca.hp R package.Methods in Ecology and Evolution,13(4):782-788<DOI:10.1111/2041-210X.13800>
Chevan, A. & Sutherland, M. (1991). Hierarchical partitioning. American Statistician, 45, 90-96. doi:10.1080/00031305.1991.10475776
Nimon, K., Oswald, F.L. & Roberts, J.K. (2013). Yhat: Interpreting regression effects. R package version 2.0.0.
Nimon, Ho, L. S. T. and Ane, C. 2014. "A linear-time algorithm for Gaussian and non-Gaussian trait evolution models". Systematic Biology 63(3):397-408.
library(spatialreg) library(spdep) data(oldcol, package="spdep") listw <- spdep::nb2listw(COL.nb, style="W") ev <- eigenw(listw) W <- as(listw, "CsparseMatrix") trMatc <- trW(W, type="mult") COL.lag.eig <- lagsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, listw=listw, method="eigen", control=list(pre_eig=ev, OrdVsign=1)) spatialreg.hp(COL.lag.eig) spatialreg.hp(COL.lag.eig,iv=list(pre1="INC",pre2="HOVAL")) spatialreg.hp(COL.lag.eig,iv=list(pre1="INC",pre2="HOVAL"),commonality=TRUE) COL.errW.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, listw, control=list(pre_eig=ev)) spatialreg.hp(COL.errW.eig) spatialreg.hp(COL.errW.eig,iv=list(pre1="INC",pre2="HOVAL")) spatialreg.hp(COL.errW.eig,iv=list(pre1="INC",pre2="HOVAL"),commonality=TRUE)library(spatialreg) library(spdep) data(oldcol, package="spdep") listw <- spdep::nb2listw(COL.nb, style="W") ev <- eigenw(listw) W <- as(listw, "CsparseMatrix") trMatc <- trW(W, type="mult") COL.lag.eig <- lagsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, listw=listw, method="eigen", control=list(pre_eig=ev, OrdVsign=1)) spatialreg.hp(COL.lag.eig) spatialreg.hp(COL.lag.eig,iv=list(pre1="INC",pre2="HOVAL")) spatialreg.hp(COL.lag.eig,iv=list(pre1="INC",pre2="HOVAL"),commonality=TRUE) COL.errW.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, listw, control=list(pre_eig=ev)) spatialreg.hp(COL.errW.eig) spatialreg.hp(COL.errW.eig,iv=list(pre1="INC",pre2="HOVAL")) spatialreg.hp(COL.errW.eig,iv=list(pre1="INC",pre2="HOVAL"),commonality=TRUE)