getR2.Rd
These functions extract goodness-of-fit measures from fitted GVF models.
getR2(object, adjusted = FALSE, ...) # S3 method for gvf.fits AIC(object, ...) # S3 method for gvf.fits BIC(object, ...)
object | An object containing one or more fitted GVF models. |
---|---|
adjusted | Should the adjusted |
... | Further arguments passed to or from other methods. |
These functions compute three goodness-of-fit measures on fitted GVF models: R^2
, AIC, and BIC. Such measures can help compare the relative quality of competing GVF models, hence facilitating model selection (see also function getBest
).
Though object
can also be a single fitted GVF model, these functions are principally meant to compare different GVF models fitted to the same data (i.e. the same estimates and errors).
To request the adjusted R^2
, use function getR2
and specify adjusted = TRUE
.
If object
is a single GVF model (class gvf.fit
), the requested quality measure.
If object
is a set of GVF models fitted to the same data (class gvf.fits
), a vector whose elements store the requested quality measure for each GVF model.
If object
is a single GVF model fitted to "grouped" data (class gvf.fit.gr
), a list whose components store the requested quality measure for the corresponding groups.
If object
is a set of GVF models fitted to "grouped" data (class gvf.fits.gr
), a list whose components store vectors whose elements report the requested quality measure for each GVF model of each group.
Each one of the provided quality measures has its own specificities and limitations (e.g. it is senseless to use AIC to compare two GVF models with different response variables). It is up to the user to select the measure which is appropriate to his goals.
GVF.db
to manage ReGenesees archive of registered GVF models, gvf.input
and svystat
to prepare the input for GVF model fitting, fit.gvf
to fit GVF models, plot.gvf.fit
to get diagnostic plots for fitted GVF models, drop.gvf.points
to drop alleged outliers from a fitted GVF model and simultaneously refit it, and predictCV
to predict CV values via fitted GVF models.
#> Classes ‘gvf.input’ and 'data.frame': 349 obs. of 5 variables: #> $ name: Factor w/ 349 levels "age10c1","age10c10",..: 331 348 349 332 333 334 11 12 13 14 ... #> $ Y : num 924101 470061 454041 536680 312655 ... #> $ SE : num 17173 12796 11360 13970 11181 ... #> $ CV : num 0.0186 0.0272 0.025 0.026 0.0358 ... #> $ VAR : num 2.95e+08 1.64e+08 1.29e+08 1.95e+08 1.25e+08 ... #> - attr(*, "y.vars")= chr [1:7] "ind" "sex" "marstat" "age5c" ... #> - attr(*, "stats.kind")= chr "Absolute Frequency" #> - attr(*, "has.Deff")= logi FALSE #> - attr(*, "design")= symbol exdes# List available registered GVF models: GVF.db#> #> # Registered GVF models currently available: #> #> Model.id GVF.model Estimator.kind Resp.to.CV #> 1 1 log(CV^2) ~ log(Y) Frequency sqrt(exp(resp)) #> 2 2 CV^2 ~ I(1/Y) Frequency sqrt(resp) #> 3 3 CV^2 ~ I(1/Y) + I(1/Y^2) Frequency sqrt(resp) #> 4 4 SE ~ Y + I(Y^2) Total resp/Y #> 5 5 CV ~ I(1/Y) + Y Total resp #>## (A) A *single* fitted GVF model ## # Fit example data to registered GVF model number one: m <- fit.gvf(ee.AF, 1) # Compute some goodness-of-fit measures: getR2(m)#> [1] 0.9429861AIC(m)#> [1] 371.4342## (B) A *a set* of GVF models fitted to the same data ## # Fit example data to all registered GVF models: mm <- fit.gvf(ee.AF) # Compute some goodness-of-fit measures: getR2(mm, adjusted = TRUE)#> [1] 0.9428189 0.9098248 0.9302265 0.8626912 0.8228374BIC(mm)#> [1] 382.9473 -959.6775 -1042.8270 5792.3883 -659.2480## (C) a *single* GVF model fitted to *grouped* data ## # We have at our disposal the following survey design object on household data: exdes#> Stratified 2 - Stage Cluster Sampling Design (with replacement) #> - [55] strata #> - [1307, 2372] clusters #> #> Call: #> e.svydesign(data = example, ids = ~towcod + famcod, strata = ~SUPERSTRATUM, #> weights = ~weight, fpc = NULL, self.rep.str = NULL, check.data = TRUE)# Use function svystat to prepare *grouped* estimates and errors of counts # to be fitted separately (here groups are regions): ee.g <- svystat(exdes, y=~ind, by=~age5c:marstat:sex, combo=3, group=~regcod) str(ee.g)#> List of 3 #> $ 6 :Classes ‘gvf.input’ and 'data.frame': 69 obs. of 5 variables: #> ..$ name: chr [1:69] "6:ind" "6.1:ind" "6.2:ind" "6.3:ind" ... #> ..$ Y : num [1:69] 293458 40903 93388 118888 34964 ... #> ..$ SE : num [1:69] 8924 4080 6249 5682 4605 ... #> ..$ CV : num [1:69] 0.0304 0.0998 0.0669 0.0478 0.1317 ... #> ..$ VAR : num [1:69] 79634317 16648310 39046122 32287405 21209323 ... #> ..- attr(*, "y.vars")= chr "ind" #> ..- attr(*, "stats.kind")= chr "Absolute Frequency" #> ..- attr(*, "has.Deff")= logi FALSE #> $ 7 :Classes ‘gvf.input’ and 'data.frame': 71 obs. of 5 variables: #> ..$ name: chr [1:71] "7:ind" "7.1:ind" "7.2:ind" "7.3:ind" ... #> ..$ Y : num [1:71] 410672 55834 131681 148350 63303 ... #> ..$ SE : num [1:71] 12714 4814 6149 6490 5796 ... #> ..$ CV : num [1:71] 0.031 0.0862 0.0467 0.0437 0.0916 ... #> ..$ VAR : num [1:71] 1.62e+08 2.32e+07 3.78e+07 4.21e+07 3.36e+07 ... #> ..- attr(*, "y.vars")= chr "ind" #> ..- attr(*, "stats.kind")= chr "Absolute Frequency" #> ..- attr(*, "has.Deff")= logi FALSE #> $ 10:Classes ‘gvf.input’ and 'data.frame': 71 obs. of 5 variables: #> ..$ name: chr [1:71] "10:ind" "10.1:ind" "10.2:ind" "10.3:ind" ... #> ..$ Y : num [1:71] 219971 32191 69506 89226 24631 ... #> ..$ SE : num [1:71] 7322 2678 4026 3620 3092 ... #> ..$ CV : num [1:71] 0.0333 0.0832 0.0579 0.0406 0.1255 ... #> ..$ VAR : num [1:71] 53611574 7170100 16205547 13102640 9562313 ... #> ..- attr(*, "y.vars")= chr "ind" #> ..- attr(*, "stats.kind")= chr "Absolute Frequency" #> ..- attr(*, "has.Deff")= logi FALSE #> - attr(*, "group.vars")= chr "regcod" #> - attr(*, "class")= chr [1:2] "gvf.input.gr" "list"# Fit registered GVF model number one separately inside groups: m.g <- fit.gvf(ee.g, 1) # Compute some goodness-of-fit measures: getR2(mm)#> [1] 0.9429861 0.9100884 0.9306346 0.8634803 0.8238734AIC(mm)#> [1] 371.4342 -971.1907 -1058.1779 5776.9680 -674.5989## (D) a *set of* GVF models fitted to *grouped* data ## # Fit all registered GVF model number separately inside groups: mm.g <- fit.gvf(ee.g) # Compute some goodness-of-fit measures: getR2(mm.g, adjusted = TRUE)#> $`6` #> [1] 0.9596039 0.8480656 0.8835943 0.8817586 0.8698454 #> #> $`7` #> [1] 0.9796080 0.9685130 0.9686853 0.9167893 0.9135516 #> #> $`10` #> [1] 0.9765799 0.9602597 0.9649448 0.8950423 0.9140170 #>BIC(mm.g)#> $`6` #> [1] 47.33868 -202.80282 -217.98568 1114.02946 -166.94776 #> #> $`7` #> [1] 6.82783 -251.16698 -248.33042 1147.46414 -172.75144 #> #> $`10` #> [1] 22.78307 -227.65365 -233.33388 1096.06999 -162.47598 #>