Description Usage Arguments Value Slots See Also Examples
Creates an object of class amModel, which is a fitted model object (or similar) with mandatory metadata.
An S4 class to store models with descriptive metadata.
1 |
model |
A model fit object or similar. |
... |
Named metadata elements, either supplied individually and coerced to list or supplied as a named list. |
An object of class amModel suitable for inclusion in an amModelLib.
modelA model fit object, e.g. from lm or any single object containing the means to predict values from data.
metadataA named list of length 1 character vectors that form name:value pairs, e.g. the analyst, the project, the data used, etc. The metadata name data can be used to link the model with the name of a data object, and when manipulated in the amModelLib an effort will be made to keep the model and data together. When embedded in an amModelLib, model metadata may be retrieved or set with modelMeta.
Other amModelLib: AMModels,
amData, amModelLib,
getters, grepAMModelLib,
insertAMModelLib, lsModels,
rmModel
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | # run models from from lm helpfile
## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
## Page 9: Plant Weight Data.
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2, 10, 20, labels = c("Ctl","Trt"))
weight <- c(ctl, trt)
lm.D9 <- lm(weight ~ group)
lm.D90 <- lm(weight ~ group - 1) # omitting intercept
# note the original class of models is 'lm'
class(lm.D9)
# wrap lm.D9 in an amModel object
mod1 <- amModel(model = lm.D9, comment='example from lm')
# summarize mod1; summary for the original object class, plus the metadata
summary(mod1)
# convert lm.D90 to an amModel object
mod2 <- amModel(model = lm.D90, comment='second example from lm')
# use the function, amModelLib, to create a new amModelLib that includes both models
# the models must be supplied as a named list
mymodels <- amModelLib(
models = list(
mod1 = mod1,
mod2 = mod2
),
description = "This amModelLib stores linear models from the lm helpfile."
)
# list the models of the amModelLib
lsModels(mymodels)
# the modelMeta function can be used to retrieve model metadata
modelMeta(mymodels, 'mod1')
# the modelMeta function can also be used to set model metadata
modelMeta(mymodels, 'mod1') <- list(
url = "https://stat.ethz.ch/R-manual/R-devel/library/stats/html/lm.html"
)
modelMeta(amml = mymodels, 'mod1')
# use getAMModel to extract the model by name
getAMModel(amml = mymodels, 'mod2', as.list = FALSE)
# notice the retrieved model is returned in its original class
class(getAMModel(amml = mymodels, 'mod2', as.list = FALSE))
# create a new empty amModelLib called mymodels2
mymodels2 <- amModelLib(description = "A second amModelLib called mymodels2.")
# use insertAMModelLib to insert amModel objects to an existing amModelLib
mymodels2 <- insertAMModelLib(models = list(mod1 = mod1, mod2 = mod2))
# use rmModel to remove an amModel object from an amModelLib
rmModel('mod2', amml = mymodels2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.