In the syntax of the formula R, sometimes the user specifies a very simple model that has only interception, for example
fit = lm(Response ~ 1, data)
These models allow simplification of relatively more complex models, for example. lm(Response ~ A + B + A:B, ...), and I would like to have an easy way to detect when the RHS equation contains only 1and no other terms. Text manipulations seem possible, but are there other ways to do this using the R class formulaor other methods?
lm(Response ~ A + B + A:B, ...)
1
formula
terms, , , , LHS ~1:
terms
~1
fit = lm(Response ~ 1, data=data.frame(Response=1:10)) identical(formula(fit)[-2],~1)
(~,Response,1)
[-2]
@G.Grothendieck ( ) , update, 0:
update
identical(update(formula(fit), 0 ~ .), 0 ~ 1)
-
names(coef(fit))
"()", .
- "terms". , lm . :
lm
f <- Response ~ 1
terms(f) "terms". lmObject .
terms(f)
lmObject
attr(terms(fit), "intercept") ## to use formula only without actually fitting a model, do ## attr(terms(f), "intercept")
1, ; 0, .
,
length(attr(terms(fit), "term.labels")) ## to use formula only without actually fitting a model, do ## attr(terms(f), "terms.labels")
0, ; 0, .
Source: https://habr.com/ru/post/1664617/More articles:When do we need to use @Injectable for our services in Angular2? - dependency-injectionCreating a wireframe with Carthage in Xcode - frameworksEquivalent to OS X - unresolved-symbols = ignore-in-object-files - c ++Manipulate: before pseudoword background with jQuery - javascriptBreaded Sonata Admin Icon - symfonyЧто не так с этими определениями seq/pseq? - computer-scienceC # - How to prevent class member access? - c #Добавление ключа из переменной строки (es6) при использовании синтаксиса распространения - javascriptNpm package.json configuration options used for version numbers - npmIonic 2, how to make an ion list, grow from bottom to top? - cssAll Articles