简体   繁体   English

多项式:如何获得观察数

[英]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.

相关问题 如何获得使用R中的函数multinom创建的模型中包含的观察数? - How to get the number of observations included in a model created using the function multinom in R? 如何获得R中multinom()中分析的确切观测值,或如何使fit()对包括NA在内的整个数据产生拟合 - how to get the exact observations analyzed in multinom() in R, or how to make fitted() produce a fit on entire data including NAs 如何获得R中一组观测值的平均数 - How to get the average number of a set of observations in R 如何获取数据框中连续观测的总数 - How to get a total number of consecutive observations in a dataframe 如何用R中的multinom()预测 - How to predict with multinom() in R 如何使用 R 中的 mutate 获取这些数据的观察次数和平均值 - How to get the number of observations and average for these data using mutate in R 如何获得每个(的观测总数 <field> = <value> )在R中? (例如,每个日期的观测总数) - How can I get the total number of observations per (<field> = <value>) in R? (e.g. total number of observations per Date) 如何将观察值转换为列并表示这些观察值的出现次数 - How to transform observations to column and reprensent the number of occurence of these observations R中multinom()函数中有大量变量 - Strange big number of variables in multinom() function in R 如何使用基于 nnet::multinom() 模型的 {ggeffects} 获得预测概率图的置信区间? - How to get confidence intervals for predicted probability plot using {ggeffects} based on nnet::multinom() model?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM