简体   繁体   English

从 rms 中获取残差诊断图 package ols() function

[英]Obtain residual diagnostic plots from rms package ols() function

How do you obtain residual diagnostic plots from an ols() object?如何从ols() object 中获取残差诊断图? normally if using glm() or lm() , I'd just do plot(lm()) , but plot(ols()) gives an error.通常,如果使用glm()lm() ,我只会执行plot(lm()) ,但plot(ols())会给出错误。

My code is:我的代码是:

fit <- ols(y ~ rcs(x1,4)*x2, data=data, x=TRUE, y=TRUE)
plot(fit)

The error message I receive is我收到的错误信息是

Error in match.arg(type): 'arg' should be one of “ordinary”, “score”, “dfbeta”, “dfbetas”, “dffit”, “dffits”, “hat”, “hscore” match.arg(type) 错误:'arg' 应该是“ordinary”、“score”、“dfbeta”、“dfbetas”、“dffit”、“dffits”、“hat”、“hscore”之一

Laboriously (but flexibly), you need to compute residuals and estimates (using resid() and fitted() ) and bind them into your data frame, then use plotting package like ggplot2 or lattice to create the plots yourself.费力地(但灵活地),您需要计算残差和估计值(使用resid()和 compatible fitted() )并将它们绑定到您的数据框中,然后使用像 ggplot2 或 lattice 之类的绘图 package 或 lattice 自己创建图。 Harrell gives examples at bottom of p. Harrell 在 p 的底部给出了示例。 153 of the 2nd edition of his book that describes the use of this package in detail.他的书第 2 版的 153 详细描述了这个 package 的使用。

As a quick and dirty alternative, you can fit a version using conventional functions (eg lm() ) and plot() will return the usual diagnostic plots.作为一种快速而肮脏的替代方案,您可以使用常规函数(例如lm() )拟合一个版本,并且plot()将返回通常的诊断图。 Things like rcs() will work with many of the base fitting functions.诸如rcs()之类的东西可以与许多基本拟合函数一起使用。

The ols object does inherit from the lm object, ols object 确实继承自lm object,

class(rcsLogFit)
## [1] "ols" "rms" "lm" 

but I was unable to gets stats:::lm() to work without the error noted here.但是我无法让stats:::lm()在没有此处指出的错误的情况下工作。

A quick workaround is to make a copy that forgets its rms -specific classes:一个快速的解决方法是制作一个忘记其rms特定类的副本:

rcsLogCopy <- rcsLogFit
class(rcsLogCopy) <- "lm"

and then然后

plot(rcsLogCopy)

works fine.工作良好。 I suppose you could do this directly on the original instead.我想您可以直接在原件上执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM