Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spatialreg #847

Merged
merged 108 commits into from Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
95dcabb
Add logitmfx tidiers
grantmcdermott Aug 27, 2019
128aa3c
Better regexp
grantmcdermott Aug 27, 2019
bca5a7f
Add more examples
grantmcdermott Aug 27, 2019
6931875
Add probit tidiers (same as logit TBH)
grantmcdermott Aug 27, 2019
1c965df
Updated NAMESPACE after adding new mfx tidiers
grantmcdermott Aug 27, 2019
ead49a4
Correct function name would be nice
grantmcdermott Aug 28, 2019
1bb8481
Just use logitmfx tidiers for probitmfx equivalents
grantmcdermott Aug 28, 2019
88f031a
Catch cases where user doesn't specify atmean argument
grantmcdermott Aug 28, 2019
90ada8d
Add tests for mfxlogit
grantmcdermott Aug 28, 2019
3aaf56a
Argh, correct function name again
grantmcdermott Aug 28, 2019
a142eeb
Better name
grantmcdermott Aug 28, 2019
29f61c9
Add probitmfx tests
grantmcdermott Aug 28, 2019
731b186
Squash into generic tidiers with various methods
grantmcdermott Aug 29, 2019
0e9652d
Missed on previous commit
grantmcdermott Aug 29, 2019
2dbe94c
Right export names would help...
grantmcdermott Aug 29, 2019
b5db88c
Add contributor details
grantmcdermott Aug 29, 2019
0f2b067
Suggest packages
grantmcdermott Sep 19, 2019
d112dd7
Fix mfx rdnames and methods
grantmcdermott Sep 19, 2019
0664c80
Auto-remove trailing whitespace
karldw Nov 22, 2019
fd42d16
Start adding fixest
karldw Nov 22, 2019
f97dfdd
Progress on fixest tidiers
karldw Nov 22, 2019
e7ee068
Progress on fixest tidiers
karldw Nov 23, 2019
050e450
Retain SEs of input object
grantmcdermott Nov 27, 2019
91ea9b6
mfx tidiers to NEWS.md
grantmcdermott Nov 28, 2019
55d7eb0
Merge pull request #2 from karldw/se-args
karldw Nov 30, 2019
f7aa314
Fixes to fixest tidiers
karldw Nov 30, 2019
93f7b15
Fix roxygen issues
karldw Dec 2, 2019
c4b949d
Resolve Alex's PR commments
grantmcdermott Dec 13, 2019
79789ef
Merge branch 'master' into mfx_tidiers
grantmcdermott Dec 13, 2019
4291fa2
Address fixest PR comments
karldw Dec 14, 2019
2fbf31d
Merge branch 'master' into master
karldw Dec 14, 2019
8a2e6ab
Address additional fixest comments
karldw Dec 14, 2019
e94266f
Separate out betamfx tidiers
grantmcdermott Dec 16, 2019
5df3ab4
Merge branch 'mfx_tidiers' of github.com:grantmcdermott/broom into mf…
grantmcdermott Dec 16, 2019
a69fff6
Merge branch 'master' into mfx_tidiers
grantmcdermott Dec 16, 2019
5f1a711
Merge branch 'master' into master
karldw Feb 3, 2020
bff7efe
Bump required fixest version
karldw Feb 17, 2020
607fe01
Add option to return p.values to tidy.polr
LukasWallrich Apr 16, 2020
0428c7d
Update NEWS.md
LukasWallrich Apr 24, 2020
1b5d178
Update DESCRIPTION
LukasWallrich Apr 24, 2020
6053a27
Write tidy method for sarlm models
gregmacfarlane May 12, 2020
501115d
Add glance and augment for sarlm objects; document
gregmacfarlane May 12, 2020
e5f5570
Another model support added (line 31)
petrhrobar May 14, 2020
7ee6c79
model added
petrhrobar May 14, 2020
4635d65
revdeps on 05-26
topepo May 26, 2020
f12396c
note deprecation of fix_data_frame() (#806, #862)
simonpcouch May 26, 2020
f6d1b99
restore n column re: chest revdepcheck (#862)
simonpcouch May 26, 2020
3d072c3
refresh docs with devel modeltests version
simonpcouch May 26, 2020
d7cd604
Merge pull request #1 from petrhrobar/patch-1
gregmacfarlane May 26, 2020
abb152d
Simplify logic of spatial regression tidying
gregmacfarlane May 26, 2020
45b7d0e
restore .resid column to augment.nls output
simonpcouch May 27, 2020
2f44ab8
restore sparse matrix tidiers (closes #470)
simonpcouch May 27, 2020
bda8e33
merge pr #863 - changes re: revdepcheck for 0.7.0
simonpcouch May 27, 2020
1012c16
small build fixes
simonpcouch May 27, 2020
b47753c
use_tidy_style() (closes #640)
simonpcouch May 28, 2020
5263067
document after use_tidy_style()
simonpcouch May 28, 2020
a1bf387
last few fixes to evalRd return_*() calls
simonpcouch May 28, 2020
5b8d2af
deprecate fix_data_frame() (closes #629, closes #806)
simonpcouch May 28, 2020
195cfd6
add contributors🙂
simonpcouch May 28, 2020
6066f8c
Merge branch 'master' into mfx_tidiers
grantmcdermott May 29, 2020
f85a22a
merge with upstream
grantmcdermott May 29, 2020
2fd1557
Merge branch 'mfx_tidiers' of github.com:grantmcdermott/broom into mf…
grantmcdermott May 29, 2020
bea3402
Drop deprecated fix_data_frame function
grantmcdermott May 29, 2020
5a10a03
Update NAMESPACE
grantmcdermott May 29, 2020
4600d9f
glance.lm edge cases (closes #865)
simonpcouch May 29, 2020
08dd0b5
add helper for tidy methods
simonpcouch May 29, 2020
b470e64
merge pr #756: mfx tidiers from @grantmcdermott
simonpcouch May 29, 2020
fbf5d96
small build fixes
simonpcouch May 29, 2020
0784be9
Merge remote-tracking branch 'upstream/master'
karldw May 29, 2020
e165e3d
Remove deprecated `fix_data_frame`
karldw May 29, 2020
ce45a85
use modeltests for car:: unit tests
simonpcouch May 31, 2020
efb3c2c
unname columns generated from predict() (closes #866)
simonpcouch May 31, 2020
1b55a67
for now, use devel modeltests for unit testing
simonpcouch May 31, 2020
f543da3
wait on modeltests release for car::Anova tests
simonpcouch May 31, 2020
71e3295
Merge branch 'master' into patch-1
simonpcouch Jun 2, 2020
e9e2c96
merge pr #833: add p.values argument to tidy.polr
simonpcouch Jun 2, 2020
dbceb3e
wait for modeltests release to check arguments
simonpcouch Jun 2, 2020
4e3e59d
document p.values arguments
simonpcouch Jun 2, 2020
839a287
correct language about glance.aov changes (closes #864)
simonpcouch Jun 2, 2020
9645c58
warn on tidy_optim standard error (closes #529)
simonpcouch Jun 2, 2020
1474b09
deprecate summary.manova()
simonpcouch Jun 2, 2020
fea0cfc
address TODOs in NEWS.md
simonpcouch Jun 2, 2020
2c26183
spellcheck
simonpcouch Jun 3, 2020
08ccfde
update to new tidyr::(un)nest() API (#831, closes #870)
simonpcouch Jun 3, 2020
d2f5d53
more vignette edits (closes #831)
simonpcouch Jun 3, 2020
b6472a4
windows 3.6 build fix
simonpcouch Jun 3, 2020
25b764a
only manually install mnormt on windows
simonpcouch Jun 3, 2020
7f5f66b
windows 3.6 build failing re: new mnormt release
simonpcouch Jun 3, 2020
76ed8f5
add glance helper (#823)
simonpcouch Jun 3, 2020
a563187
run document()
simonpcouch Jun 3, 2020
0992155
refactor glance() methods (closes #823)
simonpcouch Jun 3, 2020
27005a7
a few more NEWS.md updates for 0.7.0
simonpcouch Jun 3, 2020
a435421
rename helpers for internal consistency
simonpcouch Jun 4, 2020
e43db85
ensure no docs for map_as_tidy_tibble
simonpcouch Jun 4, 2020
0ec08b9
small vignette style edits (closes #831)
simonpcouch Jun 4, 2020
13ad2d3
restore unit tests re: modeltests v0.1.2 (closes #869)
simonpcouch Jun 4, 2020
273c058
Merge branch 'master' into master
simonpcouch Jun 5, 2020
82954e2
merge pr #793: add tidiers for `fixest` models
simonpcouch Jun 5, 2020
a989581
update fixest tidiers with new internal helpers and documentation
simonpcouch Jun 5, 2020
9e4fc3b
document tidy.map return value (closes #481)
simonpcouch Jun 5, 2020
04070a2
small build fixes
simonpcouch Jun 5, 2020
7925ff0
remove duplicate entry
simonpcouch Jun 5, 2020
2573c0f
Write tidy method for sarlm models
gregmacfarlane May 12, 2020
67e4d3e
Add glance and augment for sarlm objects; document
gregmacfarlane May 12, 2020
f811e96
Another model support added (line 31)
petrhrobar May 14, 2020
a2ef3f0
model added
petrhrobar May 14, 2020
6d8334e
Simplify logic of spatial regression tidying
gregmacfarlane May 26, 2020
ada6d65
Merge remote-tracking branch 'origin/spatialreg' into spatialreg
gregmacfarlane Jun 5, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Expand Up @@ -465,6 +465,7 @@ Collate:
'robustbase-glmrob-tidiers.R'
'robustbase-lmrob-tidiers.R'
'sp-tidiers.R'
'spdep-tidiers.R'
'speedglm-speedglm-tidiers.R'
'speedglm-speedlm-tidiers.R'
'stats-anova-tidiers.R'
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Expand Up @@ -34,6 +34,7 @@ S3method(augment,rlm)
S3method(augment,rma)
S3method(augment,rq)
S3method(augment,rqs)
S3method(augment,sarlm)
S3method(augment,smooth.spline)
S3method(augment,speedglm)
S3method(augment,speedlm)
Expand Down Expand Up @@ -96,6 +97,7 @@ S3method(glance,rlm)
S3method(glance,rma)
S3method(glance,rq)
S3method(glance,rqs)
S3method(glance,sarlm)
S3method(glance,smooth.spline)
S3method(glance,speedglm)
S3method(glance,speedlm)
Expand Down Expand Up @@ -204,6 +206,7 @@ S3method(tidy,rma)
S3method(tidy,roc)
S3method(tidy,rq)
S3method(tidy,rqs)
S3method(tidy,sarlm)
S3method(tidy,spec)
S3method(tidy,speedglm)
S3method(tidy,speedlm)
Expand Down
126 changes: 126 additions & 0 deletions R/spdep-tidiers.R
@@ -0,0 +1,126 @@
#' Tidying methods for spatially autoregressive models
#'
#' These methods tidy the coefficients of spatial autoregression
#' models generated by functions of the `spatialreg` package.
#'
#' @param x An object of object returned from [spatialreg::lagsarlm()] or [spatialreg::errorsarlm()].
#' @template param_confint
#' @template param_unused_dots
#'
#' @examples
#' library(spatialreg)
#' data(oldcol, package="spdep")
#' listw <- spdep::nb2listw(COL.nb, style="W")
#'
#' crime_sar <- lagsarlm(CRIME ~ INC + HOVAL, data=COL.OLD,
#' listw=listw, method="eigen")
#'
#' tidy(crime_sar)
#' tidy(crime_sar, conf.int = TRUE)
#' glance(crime_sar)
#' augment(crime_sar)
#'
#' crime_sem <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, listw)
#'
#' tidy(crime_sem)
#' tidy(crime_sem, conf.int = TRUE)
#' glance(crime_sem)
#' augment(crime_sem)
#'
#'
#' @aliases spatialreg_tidiers
#' @export
#' @family spatialreg tidiers
#' @seealso [tidy()], [spatialreg::lagsarlm()], [spatialreg::errorsarlm()]
tidy.sarlm <- function(x, conf.int = FALSE, conf.level = .95, ...) {
# construct parameter table
s <- summary(x)
ret <- as_tibble(s$Coef, rownames = 'term')
colnames(ret) <- c("term", "estimate", "std.error", "statistic", "p.value")

# append spatial autoregression coefficient to parameter table
if (!is.null(s$rho) == T) {
# if SAR model, get rho and append to table
ret2 <- tibble(
term = "rho",
estimate = as.numeric(s$rho),
std.error = as.numeric(s$rho.se),
statistic = as.numeric(estimate / std.error),
p.value = as.numeric(2 * (1 - pnorm( abs(statistic) ) ) )
)
ret = rbind(ret, ret2)
} else if (!is.null(s$lambda)) {
# if SEM model, get lambda and append to table
ret2 <- tibble(
term = "lambda",
estimate = as.numeric(s$lambda),
std.error = as.numeric(s$lambda.se),
statistic = as.numeric(estimate / std.error),
p.value = as.numeric(2 * (1 - pnorm( abs(statistic) ) ) )
)
colnames(ret2) <- c("term", "estimate", "std.error", "statistic", "p.value")
ret = rbind(ret, ret2)
}


# Calculate confidence interval
if (conf.int) {
ci <- confint(x, level = conf.level)
ci <- as_tibble(ci, rownames = "term")
colnames(ci) <- c("term", "conf.low", "conf.high")
ret <- dplyr::left_join(ret, ci, by = "term")
}

ret
}

#' @templateVar class spatialreg
#' @template title_desc_augment
#'
#' @template augment_NAs
#'
#' @inherit tidy.sarlm params examples
#'
#' @export
#' @seealso [augment()],[mlogit::miscmethods.mlogit()]
#' @family spatialreg tidiers
augment.sarlm <- function(x) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a ... argument here for compatibility with the generic and @template param_unused_dots roxygen tag?


reg <- as_tibble(x$X) %>%
select(-1) %>%
dplyr::mutate(
y = x$y,
.fitted = x$fitted.values,
.resid = x$residuals
)

#TODO: Extend for spatial lags of variables
gregmacfarlane marked this conversation as resolved.
Show resolved Hide resolved

reg

}


#' @templateVar class spatialreg
#' @template title_desc_glance
#'
#' @inherit tidy.sarlm params examples
#'
#' @evalRd return_glance("logLik", "AIC", "BIC", "deviance", "logLik", "nobs")
#' @export
#' @family spatialreg tidiers
#' @seealso [glance()], [spatialreg::lagsarlm()], [spatialreg::errorsarlm()]
glance.sarlm <- function(x) {

res <- tibble(
# Using Pseudo R squared.
r.squared = cor(x$fitted.values, x$y)^2,
AIC = stats::AIC(x),
BIC = stats::BIC(x),
deviance = stats::deviance(x),
logLik = as.numeric(x$LL),
nobs = length(x$fitted.values)
)

res
}
92 changes: 92 additions & 0 deletions man/augment.sarlm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions man/glance.sarlm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions man/tidy.sarlm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.