@@ -18,14 +18,7 @@ lmSLX <- function(formula, data = list(), listw, na.action, weights=NULL, Durbin
18
18
if (attr(mt , " intercept" ) == 1 && ! any(attr(mt , " factors" ) == 1 )) {
19
19
stop(" intercept-only model, Durbin invalid" )
20
20
}
21
- dcfact <- which(attr(attr(mf , " terms" ), " dataClasses" ) == " factor" )
22
- have_factor_preds <- FALSE
23
- if (length(dcfact ) > 0 ) {
24
- have_factor_preds <- TRUE
25
- factnames <- names(dcfact )
26
- xlevels <- lapply(factnames , function (xnms ) levels(mf [[xnms ]]))
27
- names(xlevels ) <- factnames
28
- }
21
+ have_factor_preds <- have_factor_preds_mf(mf )
29
22
na.act <- attr(mf , " na.action" )
30
23
if (! inherits(listw , " listw" )) stop(" No neighbourhood list" )
31
24
if (listw $ style == " M" ) warning(" missing spatial weights style" )
@@ -58,7 +51,8 @@ lmSLX <- function(formula, data = list(), listw, na.action, weights=NULL, Durbin
58
51
if (isTRUE(Durbin )) {
59
52
if (have_factor_preds )
60
53
warning(" use of spatially lagged factors (categorical variables)\n " ,
61
- paste(factnames , collapse = " , " ), " \n is not well-understood" )
54
+ paste(attr(have_factor_preds , " factnames" ), collapse = " , " ),
55
+ " \n is not well-understood" )
62
56
WX <- create_WX(x , listw , zero.policy = zero.policy ,
63
57
prefix = prefix )
64
58
} else if (is.formula(Durbin )) {
@@ -69,10 +63,11 @@ lmSLX <- function(formula, data = list(), listw, na.action, weights=NULL, Durbin
69
63
}
70
64
dmf <- lm(Durbin , data1 , na.action = na.fail ,
71
65
method = " model.frame" )
72
- Ddcfact <- which(attr(attr( dmf , " terms " ), " dataClasses " ) == " factor " )
73
- if (length( Ddcfact ) > 0 ) {
66
+ formula_durbin_factors <- have_factor_preds_mf( dmf )
67
+ if (formula_durbin_factors ) {
74
68
warning(" use of spatially lagged factors (categorical variables)\n " ,
75
- paste(names(Ddcfact ), collapse = " , " ), " \n is not well-understood" )
69
+ paste(attr(formula_durbin_factors , " factnames" ), collapse = " , " ),
70
+ " \n is not well-understood" )
76
71
}
77
72
# dmf <- lm(Durbin, data, na.action=na.action,
78
73
# method="model.frame")
0 commit comments