get_residuals: Retrieving equations' residuals

Description Usage Arguments Value Examples

View source: R/class_model_ss.R

Description

The get_residuals function allows to check the residuals of the steady-state (equilibrium) equations of a dynamic (static) model and identify equations with the largest errors. This may help to assign initial values to the model's variables more accurately when the solver cannot find the steady state (equilibrium).

Usage

1
get_residuals(model, largest = 5, calibration = TRUE)

Arguments

model

an object of gecon_model class.

largest

the number of equations with the largest errors which are to be printed.

calibration

if FALSE, calibrating equations will not be taken into account when computing equations' residuals. Initial values of calibrated parameters will be then treated as their values.

Value

The function returns a list of two elements: initial and final. Initial residuals are steady-state (equilibrium) equations' residuals computed using the initial values of variables. Final residuals are residuals computed after the solver has exited. The function prints the indices of equations with the largest initial and final errors. The equations can be further investigated using the list_eq function.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# copy the example to the current working directory
file.copy(from = file.path(system.file("examples", package = "gEcon"),
                           "home_production_templ.gcn"), to = getwd())

# make and load the model
home_prod_templ <- make_model("home_production_templ.gcn")

# for the purpose of the example, initial values are set very far from the solution
home_prod_templ <- initval_var(home_prod_templ, c(N = 0.02,
                                                  N__H = 0.01,
                                                  N__M = 0.01))
home_prod_templ <- steady_state(home_prod_templ)
get_residuals(home_prod_templ)

# after setting more reasonable values the steady state is found
home_prod_templ <- initval_var(home_prod_templ, c(N = 0.5,
                                                  N__H = 0.25,
                                                  N__M = 0.25))
home_prod_templ <- steady_state(home_prod_templ)
get_residuals(home_prod_templ)

gEcon documentation built on May 2, 2019, 6:52 p.m.

Related to get_residuals in gEcon...