diagnostics: Goodness of fit measures for both parts

Description Usage Arguments Value Examples

Description

Calculation RMSE, misclassification and other goodness of fit measures.

Usage

1
2
3
4
5
6
7
8
diagnostics(
  x,
  xdigit = 4,
  which = "all",
  only_total = FALSE,
  cPseudoR = TRUE,
  cRs = TRUE
)

Arguments

x

Fitted nmm model.

xdigit

rounding number

which

What to calculate. Options: "all", "RMSE", "MAPE", "Rx2", "Rx2adj".

only_total

If TRUE, calculate statistics only for the whole system

cPseudoR

If TRUE, calculate pseudo R^2s.

cRs

Include "AIC", "AICc", "BIC"

Value

matrix with goodness of fit measures. attribute corr holds empirical variance-covariance matrix.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
library(systemfit)
data( ppine , package="systemfit")
hg.formula <- hg ~ exp( h0 + h1*log(tht) + h2*tht^2 + h3*elev)
dg.formula <- dg ~ exp( d0 + d1*log(dbh) + d2*hg + d3*cr)
labels <- list( "height.growth", "diameter.growth" )
model <- list( hg.formula, dg.formula )
start.values <- c(h0=-0.5, h1=0.5, h2=-0.001, h3=0.0001,
                  d0=-0.5, d1=0.009, d2=0.25, d3=0.005)
model.sur <- nlsystemfit( "SUR", model, start.values, data=ppine, eqnlabels=labels )
eq_c <- as.character(c(hg.formula, dg.formula))
parl <- c(paste0("h", 0:3),paste0("d", 0:3))
start.values <- c(h0=-0.5, h1=0.5, h2=-0.001, h3=0.0001,
                  d0=-0.5, d1=0.009, d2=0.25, d3=0.005)
res <- nmm(ppine, eq_c=eq_c, start_v=start.values, par_c=parl, eq_type = "cont",
best_method = FALSE)
ressur <- in2nmm(res, new_coef=model.sur$b)
diagnostics(res)
diagnostics(ressur)

#example discrete
library(mlogit)
data("Fishing", package = "mlogit")
Fish <- mlogit.data(Fishing, varying = c(2:9), shape = "wide", choice = "mode")
## a pure "conditional" model
mres <- summary(mlogit(mode ~ price + catch, data = Fish))
data <- prepare_data(Fish %>% data.frame %>% dplyr::select(-idx), 
choice="alt", dummy="mode", PeID="chid", mode_spec_var = c("price", "catch"),
type="long")
eq_d <- c("a1 + p1 * price_1 + p2 * catch_2", "a2 + p1 * price_2 + p2 * catch_2",
             "a3 + p1 * price_3 + p2 * catch_3", "a4 + p1 * price_4 + p2 * catch_4")
par_d <- c(paste0("a", 1:4), paste0("p", 1:2))
res <- nmm(data, eq_d=eq_d, par_d=par_d,  eq_type="disc")
ncoef <- mres$coefficients
names(ncoef) <- par_d[-1]
resdisc <- in2nmm(res, new_coef = ncoef)
a <- diagnostics(res, xdigit=2)
a2 <- diagnostics(resdisc)
attributes(a2)$corr

nmm documentation built on Jan. 7, 2021, 5:10 p.m.

Related to diagnostics in nmm...