-
Notifications
You must be signed in to change notification settings - Fork 299
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
Spatialreg #847
Changes from 2 commits
Commits
Show all changes
108 commits
Select commit
Hold shift + click to select a range
95dcabb
Add logitmfx tidiers
grantmcdermott 128aa3c
Better regexp
grantmcdermott bca5a7f
Add more examples
grantmcdermott 6931875
Add probit tidiers (same as logit TBH)
grantmcdermott 1c965df
Updated NAMESPACE after adding new mfx tidiers
grantmcdermott ead49a4
Correct function name would be nice
grantmcdermott 1bb8481
Just use logitmfx tidiers for probitmfx equivalents
grantmcdermott 88f031a
Catch cases where user doesn't specify atmean argument
grantmcdermott 90ada8d
Add tests for mfxlogit
grantmcdermott 3aaf56a
Argh, correct function name again
grantmcdermott a142eeb
Better name
grantmcdermott 29f61c9
Add probitmfx tests
grantmcdermott 731b186
Squash into generic tidiers with various methods
grantmcdermott 0e9652d
Missed on previous commit
grantmcdermott 2dbe94c
Right export names would help...
grantmcdermott b5db88c
Add contributor details
grantmcdermott 0f2b067
Suggest packages
grantmcdermott d112dd7
Fix mfx rdnames and methods
grantmcdermott 0664c80
Auto-remove trailing whitespace
karldw fd42d16
Start adding fixest
karldw f97dfdd
Progress on fixest tidiers
karldw e7ee068
Progress on fixest tidiers
karldw 050e450
Retain SEs of input object
grantmcdermott 91ea9b6
mfx tidiers to NEWS.md
grantmcdermott 55d7eb0
Merge pull request #2 from karldw/se-args
karldw f7aa314
Fixes to fixest tidiers
karldw 93f7b15
Fix roxygen issues
karldw c4b949d
Resolve Alex's PR commments
grantmcdermott 79789ef
Merge branch 'master' into mfx_tidiers
grantmcdermott 4291fa2
Address fixest PR comments
karldw 2fbf31d
Merge branch 'master' into master
karldw 8a2e6ab
Address additional fixest comments
karldw e94266f
Separate out betamfx tidiers
grantmcdermott 5df3ab4
Merge branch 'mfx_tidiers' of github.com:grantmcdermott/broom into mf…
grantmcdermott a69fff6
Merge branch 'master' into mfx_tidiers
grantmcdermott 5f1a711
Merge branch 'master' into master
karldw bff7efe
Bump required fixest version
karldw 607fe01
Add option to return p.values to tidy.polr
LukasWallrich 0428c7d
Update NEWS.md
LukasWallrich 1b5d178
Update DESCRIPTION
LukasWallrich 6053a27
Write tidy method for sarlm models
gregmacfarlane 501115d
Add glance and augment for sarlm objects; document
gregmacfarlane e5f5570
Another model support added (line 31)
petrhrobar 7ee6c79
model added
petrhrobar 4635d65
revdeps on 05-26
topepo f12396c
note deprecation of fix_data_frame() (#806, #862)
simonpcouch f6d1b99
restore n column re: chest revdepcheck (#862)
simonpcouch 3d072c3
refresh docs with devel modeltests version
simonpcouch d7cd604
Merge pull request #1 from petrhrobar/patch-1
gregmacfarlane abb152d
Simplify logic of spatial regression tidying
gregmacfarlane 45b7d0e
restore .resid column to augment.nls output
simonpcouch 2f44ab8
restore sparse matrix tidiers (closes #470)
simonpcouch bda8e33
merge pr #863 - changes re: revdepcheck for 0.7.0
simonpcouch 1012c16
small build fixes
simonpcouch b47753c
use_tidy_style() (closes #640)
simonpcouch 5263067
document after use_tidy_style()
simonpcouch a1bf387
last few fixes to evalRd return_*() calls
simonpcouch 5b8d2af
deprecate fix_data_frame() (closes #629, closes #806)
simonpcouch 195cfd6
add contributors🙂
simonpcouch 6066f8c
Merge branch 'master' into mfx_tidiers
grantmcdermott f85a22a
merge with upstream
grantmcdermott 2fd1557
Merge branch 'mfx_tidiers' of github.com:grantmcdermott/broom into mf…
grantmcdermott bea3402
Drop deprecated fix_data_frame function
grantmcdermott 5a10a03
Update NAMESPACE
grantmcdermott 4600d9f
glance.lm edge cases (closes #865)
simonpcouch 08dd0b5
add helper for tidy methods
simonpcouch b470e64
merge pr #756: mfx tidiers from @grantmcdermott
simonpcouch fbf5d96
small build fixes
simonpcouch 0784be9
Merge remote-tracking branch 'upstream/master'
karldw e165e3d
Remove deprecated `fix_data_frame`
karldw ce45a85
use modeltests for car:: unit tests
simonpcouch efb3c2c
unname columns generated from predict() (closes #866)
simonpcouch 1b55a67
for now, use devel modeltests for unit testing
simonpcouch f543da3
wait on modeltests release for car::Anova tests
simonpcouch 71e3295
Merge branch 'master' into patch-1
simonpcouch e9e2c96
merge pr #833: add p.values argument to tidy.polr
simonpcouch dbceb3e
wait for modeltests release to check arguments
simonpcouch 4e3e59d
document p.values arguments
simonpcouch 839a287
correct language about glance.aov changes (closes #864)
simonpcouch 9645c58
warn on tidy_optim standard error (closes #529)
simonpcouch 1474b09
deprecate summary.manova()
simonpcouch fea0cfc
address TODOs in NEWS.md
simonpcouch 2c26183
spellcheck
simonpcouch 08ccfde
update to new tidyr::(un)nest() API (#831, closes #870)
simonpcouch d2f5d53
more vignette edits (closes #831)
simonpcouch b6472a4
windows 3.6 build fix
simonpcouch 25b764a
only manually install mnormt on windows
simonpcouch 7f5f66b
windows 3.6 build failing re: new mnormt release
simonpcouch 76ed8f5
add glance helper (#823)
simonpcouch a563187
run document()
simonpcouch 0992155
refactor glance() methods (closes #823)
simonpcouch 27005a7
a few more NEWS.md updates for 0.7.0
simonpcouch a435421
rename helpers for internal consistency
simonpcouch e43db85
ensure no docs for map_as_tidy_tibble
simonpcouch 0ec08b9
small vignette style edits (closes #831)
simonpcouch 13ad2d3
restore unit tests re: modeltests v0.1.2 (closes #869)
simonpcouch 273c058
Merge branch 'master' into master
simonpcouch 82954e2
merge pr #793: add tidiers for `fixest` models
simonpcouch a989581
update fixest tidiers with new internal helpers and documentation
simonpcouch 9e4fc3b
document tidy.map return value (closes #481)
simonpcouch 04070a2
small build fixes
simonpcouch 7925ff0
remove duplicate entry
simonpcouch 2573c0f
Write tidy method for sarlm models
gregmacfarlane 67e4d3e
Add glance and augment for sarlm objects; document
gregmacfarlane f811e96
Another model support added (line 31)
petrhrobar a2ef3f0
model added
petrhrobar 6d8334e
Simplify logic of spatial regression tidying
gregmacfarlane ada6d65
Merge remote-tracking branch 'origin/spatialreg' into spatialreg
gregmacfarlane File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) { | ||
|
||
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 | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?