Type: | Package |
Title: | Hierarchical Partitioning of R2 for Spatial Simultaneous Autoregressive Model |
Version: | 0.0-1 |
Date: | 2025-8-22 |
Depends: | R (≥ 3.4.0),spatialreg,ggplot2,vegan |
Imports: | spdep |
Maintainer: | Jiangshan Lai <lai@njfu.edu.cn> |
Description: | Conducts hierarchical partitioning to calculate individual contributions of spatial and predictors (groups) towards total R2 for spatial simultaneous autoregressive model. |
License: | GPL-2 | GPL-3 [expanded from: GPL] |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.1 |
NeedsCompilation: | no |
Packaged: | 2025-08-22 06:05:33 UTC; lai |
Author: | Jiangshan Lai |
Repository: | CRAN |
Date/Publication: | 2025-08-27 16:30:07 UTC |
Internal function for glmm.hp() to create diagonal matrix
Description
Internal function for glmm.hp() to create diagonal matrix
Usage
creatbin(col, binmatrix)
Arguments
col |
Imput number. |
binmatrix |
Imput empty matrix. |
Value
a matrix
a matix |
A diagonal matrix |
Internal function for glmm.hp()
Description
Internal function for glmm.hp()
Usage
genList(ivlist, value)
Arguments
ivlist |
The names of explanatory variable. |
value |
The sequence ID. |
Value
a vector
newlist |
A vector for variable index. |
Calculate Nagelkerke pseudo R-squared for a linear model
Description
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).
Usage
nagelkerke_r2_lm(model)
Arguments
model |
An object of class |
Details
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:
R^2_{Nagelkerke} = \frac{1 - \exp\left(\frac{2}{n} (LL_{null} - LL_{model})\right)}{1 - \exp\left(\frac{2}{n} LL_{null}\right)}
where LL_{model}
is the log-likelihood of the fitted model and LL_{null}
is the log-likelihood of the null model.
Value
A numeric value representing the Nagelkerke pseudo R-squared.
References
Nagelkerke, N. J. D. (1991). A note on a general definition of the coefficient of determination. Biometrika, 78(3), 691–692.
Examples
data(mtcars)
fit <- lm(mpg ~ wt + hp, data = mtcars)
nagelkerke_r2_lm(fit)
Internal function for glmm.hp() to determine whether the odd number
Description
Internal function for glmm.hp() to determine whether the odd number
Usage
odd(val)
Arguments
val |
Imput number. |
Value
a logical value
Logical value |
TRUE or FALSE |
Plot for a spatialreg.hp
object
Description
Plot for a spatialreg.hp
object
Usage
## S3 method for class 'spatialreghp'
plot(x, plot.perc = FALSE, commonality = FALSE, color = NULL, dig = 4, ...)
Arguments
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 |
Value
a ggplot object
Author(s)
Jiangshan Lai lai@njfu.edu.cn
Examples
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
Description
Hierarchical Partitioning of R2 for Spatial Simultaneous Autoregressive Model
Usage
spatialreg.hp(mod, iv = NULL, commonality = FALSE)
Arguments
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. |
Details
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.
Value
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 |
Author(s)
Jiangshan Lai lai@njfu.edu.cn
References
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.
Examples
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)