Skip to content

Commit 6cdcbef

Browse files
committed
Durbin factors code factor
1 parent 39fd133 commit 6cdcbef

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Diff for: R/spBreg.R

+15
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ spBreg_lag <- function(formula, data = list(), listw, na.action, Durbin, type,
3838
if (!inherits(formula, "formula")) formula <- as.formula(formula)
3939
mt <- terms(formula, data = data)
4040
mf <- lm(formula, data, na.action=na.action, method="model.frame")
41+
have_factor_preds <- have_factor_preds_mf(mf)
4142
na.act <- attr(mf, "na.action")
4243
if (!inherits(listw, "listw")) stop("No neighbourhood list")
4344
can.sim <- FALSE
@@ -85,6 +86,7 @@ spBreg_lag <- function(formula, data = list(), listw, na.action, Durbin, type,
8586
if (is.formula(Durbin) || isTRUE(Durbin)) {
8687
prefix <- "lag"
8788
if (isTRUE(Durbin)) {
89+
if (have_factor_preds) warn_factor_preds(have_factor_preds)
8890
WX <- create_WX(x, listw, zero.policy=zero.policy,
8991
prefix=prefix)
9092
} else {
@@ -95,6 +97,9 @@ spBreg_lag <- function(formula, data = list(), listw, na.action, Durbin, type,
9597
}
9698
dmf <- lm(Durbin, data1, na.action=na.fail,
9799
method="model.frame")
100+
formula_durbin_factors <- have_factor_preds_mf(dmf)
101+
if (formula_durbin_factors)
102+
warn_factor_preds(formula_durbin_factors)
98103
# dmf <- lm(Durbin, data, na.action=na.action,
99104
# method="model.frame")
100105
fx <- try(model.matrix(Durbin, dmf), silent=TRUE)
@@ -521,6 +526,7 @@ spBreg_err <- function(formula, data = list(), listw, na.action, Durbin, etype,
521526
if (!inherits(formula, "formula")) formula <- as.formula(formula)
522527
mt <- terms(formula, data = data)
523528
mf <- lm(formula, data, na.action=na.action, method="model.frame")
529+
have_factor_preds <- have_factor_preds_mf(mf)
524530
na.act <- attr(mf, "na.action")
525531
if (!inherits(listw, "listw")) stop("No neighbourhood list")
526532
can.sim <- FALSE
@@ -563,6 +569,7 @@ spBreg_err <- function(formula, data = list(), listw, na.action, Durbin, etype,
563569
if (is.formula(Durbin) || isTRUE(Durbin)) {
564570
prefix <- "lag"
565571
if (isTRUE(Durbin)) {
572+
if (have_factor_preds) warn_factor_preds(have_factor_preds)
566573
WX <- create_WX(x, listw, zero.policy=zero.policy,
567574
prefix=prefix)
568575
} else {
@@ -573,6 +580,9 @@ spBreg_err <- function(formula, data = list(), listw, na.action, Durbin, etype,
573580
}
574581
dmf <- lm(Durbin, data1, na.action=na.fail,
575582
method="model.frame")
583+
formula_durbin_factors <- have_factor_preds_mf(dmf)
584+
if (formula_durbin_factors)
585+
warn_factor_preds(formula_durbin_factors)
576586
# dmf <- lm(Durbin, data, na.action=na.action,
577587
# method="model.frame")
578588
fx <- try(model.matrix(Durbin, dmf), silent=TRUE)
@@ -998,6 +1008,7 @@ spBreg_sac <- function(formula, data = list(), listw, listw2=NULL, na.action,
9981008
if (!inherits(formula, "formula")) formula <- as.formula(formula)
9991009
mt <- terms(formula, data = data)
10001010
mf <- lm(formula, data, na.action=na.action, method="model.frame")
1011+
have_factor_preds <- have_factor_preds_mf(mf)
10011012
na.act <- attr(mf, "na.action")
10021013
if (!inherits(listw, "listw")) stop("No neighbourhood list")
10031014
if (is.null(listw2)) listw2 <- listw
@@ -1057,6 +1068,7 @@ spBreg_sac <- function(formula, data = list(), listw, listw2=NULL, na.action,
10571068
if (is.formula(Durbin) || isTRUE(Durbin)) {
10581069
prefix <- "lag"
10591070
if (isTRUE(Durbin)) {
1071+
if (have_factor_preds) warn_factor_preds(have_factor_preds)
10601072
WX <- create_WX(x, listw, zero.policy=zero.policy,
10611073
prefix=prefix)
10621074
} else {
@@ -1067,6 +1079,9 @@ spBreg_sac <- function(formula, data = list(), listw, listw2=NULL, na.action,
10671079
}
10681080
dmf <- lm(Durbin, data1, na.action=na.fail,
10691081
method="model.frame")
1082+
formula_durbin_factors <- have_factor_preds_mf(dmf)
1083+
if (formula_durbin_factors)
1084+
warn_factor_preds(formula_durbin_factors)
10701085
# dmf <- lm(Durbin, data, na.action=na.action,
10711086
# method="model.frame")
10721087
fx <- try(model.matrix(Durbin, dmf), silent=TRUE)

0 commit comments

Comments
 (0)