我在R中拟合一个GLM模型,在结果模型对象中,有一个称为'terms'的元素。"terms"对象是一个"language"对象。
我不熟悉"语言"对象。我想知道我如何能够从模型$terms对象中提取"属性"。例如,如果我想从这个对象获得"predvars"属性,我应该怎么做?
> model = glm(...)
> typeof(model$terms)
[1] "language"
> model$terms
losscost_bc_fire_cap ~ pol_year_fac + ded_group + ind_score
attr(,"variables")
list(target, pol_year_fac, ded_group , ind_score)
......
attr(,"term.labels")
[1] "pol_year_fac" "ded_bco_fire_group" "ind_grewscore" "cv_grewscore"
[5] "cv_log_tiv"
attr(,"order")
[1] 1 1 1 1 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
attr(,"predvars")
list(losscost_bc_fire_cap, pol_year_fac, ded_bco_fire_group,
ind_grewscore, cv_grewscore, cv_log_tiv)
attr(,"dataClasses")
losscost_bc_fire_cap pol_year_fac ded_bco_fire_group ind_grewscore
"numeric" "factor" "factor" "factor"
cv_grewscore cv_log_tiv (weights)
"numeric" "numeric" "numeric"
使用attr()
函数
attr(model$terms, "predvars")
或者(我想)attributes(model$terms)$predvars
predvars
是一个未求值的语言对象。如果你想使用eval()
(或其他东西),你需要使用它。