[英]multinom: how to get the number of observations
I am using multinom
from nnet
to create a logistic model from a massive clinical database. 我正在使用
nnet
multinom
从大型临床数据库创建逻辑模型。 The syntax I'm using is: 我使用的语法是:
library(nnet)
fit=multinom(group ~ sex + age + var3 + var4,
data=d, na.action = na.omit)
Now, each row (a patient) has a different number of NAs, as not all clinical data were recorded for all patients, and it is not clear to me if the model only uses those rows for which all of the variables do not contain any NAs. 现在,每行(患者)具有不同数量的NA,因为并非针对所有患者都记录了所有临床数据,并且我不清楚模型是否仅使用那些所有变量均不包含任何变量的行NAs。 More in general, it would be useful to obtain the Ns of observations that the model is based on, which I suspect is smaller that the number of rows of my dataframe (N of patients).
更一般而言,获得模型所基于的观察值的Ns会很有用,我怀疑它小于我数据框的行数(N个患者)。 I have looked everywhere but I don't seem to be able to find how to do this.
我到处都看过,但似乎找不到解决方法。
I believe length(residuals(fit))
should work. 我相信
length(residuals(fit))
应该起作用。
If you want to explore the data set that was used to fit the model, you can do: 如果要探索用于拟合模型的数据集,则可以执行以下操作:
mf <- model.frame(group ~ sex + age + var3 + var4, data=d,
na.action=na.omit)
(this is how multinom
processes your data) and then count the number of rows, tabulate the number of observations in different categories for different variables (eg table(mf$var3)
), etc.. lapply(mf,table)
should tabulate the number of observations by category for every variable. (这是
multinom
处理数据的方式),然后计算行数,将不同变量中不同类别的观察值列表(例如table(mf$var3)
),等等lapply(mf,table)
应该列表每个变量的类别观察数。
You might find the describe
function from the Hmisc
package useful: 您可能会发现
Hmisc
包中的describe
函数很有用:
Hmisc::describe(group ~ sex + age + var3 + var4, data=d)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.