Visualization of coefficients

classic Classic list List threaded Threaded
20 messages Options
Reply | Threaded
Open this post in threaded view
|

Visualization of coefficients

Wincent
Dear all,

I try to show a subset of coefficients in my presentation. It seems
that a "standard" table is not a good way to go. I found figure 9
(page 9) in this file (
http://www.destatis.de/jetspeed/portal/cms/Sites/destatis/Internet/DE/Content/Wissenschaftsforum/Kolloquien/VisualisierungModellierung__Beitrag,property=file.pdf
) looks pretty good. I wonder if there is any function for such plot?
Or any suggestion on how to present statistical models in a
presentation?

Thank you.

--
Wincent Rong-gui HUANG
Doctoral Candidate
Dept of Public and Social Administration
City University of Hong Kong
http://asrr.r-forge.r-project.org/rghuang.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Visualization of coefficients

Bernd Weiss
Am 02.07.2010 08:10, schrieb Wincent:
> Dear all,
>
> I try to show a subset of coefficients in my presentation. It seems
> that a "standard" table is not a good way to go. I found figure 9
> (page 9) in this file (
> http://www.destatis.de/jetspeed/portal/cms/Sites/destatis/Internet/DE/Content/Wissenschaftsforum/Kolloquien/VisualisierungModellierung__Beitrag,property=file.pdf
>
>
) looks pretty good. I wonder if there is any function for such plot?
> Or any suggestion on how to present statistical models in a
> presentation?

Hi Wincent,

I guess you are looking for "Using Graphs Instead of Tables in Political
Science" by Kastellec/Leoni <http://tables2graphs.com/doku.php>.

HTH,

Bernd

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Visualization of coefficients

cybaea
In reply to this post by Wincent
http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=114 should
get you started.

On 02/07/10 07:10, Wincent wrote:

> Dear all,
>
> I try to show a subset of coefficients in my presentation. It seems
> that a "standard" table is not a good way to go. I found figure 9
> (page 9) in this file (
> http://www.destatis.de/jetspeed/portal/cms/Sites/destatis/Internet/DE/Content/Wissenschaftsforum/Kolloquien/VisualisierungModellierung__Beitrag,property=file.pdf
> ) looks pretty good. I wonder if there is any function for such plot?
> Or any suggestion on how to present statistical models in a
> presentation?
>
> Thank you.
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Visualization of coefficients

Tal Galili
In reply to this post by Bernd Weiss
Specifically this link:
http://tables2graphs.com/doku.php?id=04_regression_coefficients

Great reference Bernd, thank you.

Tal


----------------Contact
Details:-------------------------------------------------------
Contact me: [hidden email] |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
----------------------------------------------------------------------------------------------




On Fri, Jul 2, 2010 at 10:31 AM, Bernd Weiss <[hidden email]>wrote:

> Am 02.07.2010 08:10, schrieb Wincent:
> > Dear all,
> >
> > I try to show a subset of coefficients in my presentation. It seems
> > that a "standard" table is not a good way to go. I found figure 9
> > (page 9) in this file (
> >
> http://www.destatis.de/jetspeed/portal/cms/Sites/destatis/Internet/DE/Content/Wissenschaftsforum/Kolloquien/VisualisierungModellierung__Beitrag,property=file.pdf
> >
> >
> ) looks pretty good. I wonder if there is any function for such plot?
> > Or any suggestion on how to present statistical models in a
> > presentation?
>
> Hi Wincent,
>
> I guess you are looking for "Using Graphs Instead of Tables in Political
> Science" by Kastellec/Leoni <http://tables2graphs.com/doku.php>.
>
> HTH,
>
> Bernd
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Visualization of coefficients

Achim Zeileis-4
I've thought about adding a plot() method for the coeftest() function in
the "lmtest" package. Essentially, it relies on a coef() and a vcov()
method being available - and that a central limit theorem holds. For
releasing it as a general function in the package the code is still too
raw, but maybe it's useful for someone on the list. Hence, I've included
it below.

An example would be to visualize all coefficients except the intercept for
the Mroz data:

data("Mroz", package = "car")
fm <- glm(lfp ~ ., data = Mroz, family = binomial)
coefplot(fm, parm = -1)

hth,
Z

coefplot <- function(object, df = NULL, level = 0.95, parm = NULL,
   labels = TRUE, xlab = "Coefficient confidence intervals", ylab = "",
   xlim = NULL, ylim = NULL,
   las = 1, lwd = 1, lty = c(1, 2), pch = 19, col = 1,
   length = 0, angle = 30, code = 3, ...)
{
   cf <- coef(object)
   se <- sqrt(diag(vcov(object)))
   if(is.null(parm)) parm <- seq_along(cf)
   if(is.numeric(parm) | is.logical(parm)) parm <- names(cf)[parm]
   if(is.character(parm)) parm <- which(names(cf) %in% parm)
   cf <- cf[parm]
   se <- se[parm]
   k <- length(cf)

   if(is.null(df)) {
     df <- if(identical(class(object), "lm")) df.residual(object) else 0
   }

   critval <- if(df > 0 & is.finite(df)) {
     qt((1 - level)/2, df = df)
   } else {
     qnorm((1 - level)/2)
   }
   ci1 <- cf + critval * se
   ci2 <- cf - critval * se

   lwd <- rep(lwd, length.out = 2)
   lty <- rep(lty, length.out = 2)
   pch <- rep(pch, length.out = k)
   col <- rep(col, length.out = k)

   if(is.null(xlim)) xlim <- range(c(0, min(ci1), max(ci2)))
   if(is.null(ylim)) ylim <- c(1 - 0.05 * k, 1.05 * k)

   if(isTRUE(labels)) labels <- names(cf)
   if(identical(labels, FALSE)) labels <- ""
   labels <- rep(labels, length.out = k)

   plot(0, 0, xlim = xlim, ylim = ylim, xlab = xlab, ylab = ylab,
     axes = FALSE, type = "n", las = las, ...)
   arrows(ci1, 1:k, ci2, 1:k, lty = lty[1], lwd = lwd[1], col = col,
     length = length, angle = angle, code = code)
   points(cf, 1:k, pch = pch, col = col)
   abline(v = 0, lty = lty[2], lwd = lwd[2])
   axis(1)
   axis(2, at = 1:k, labels = labels, las = las)
   box()
}


On Fri, 2 Jul 2010, Tal Galili wrote:

> Specifically this link:
> http://tables2graphs.com/doku.php?id=04_regression_coefficients
>
> Great reference Bernd, thank you.
>
> Tal
>
>
> ----------------Contact
> Details:-------------------------------------------------------
> Contact me: [hidden email] |  972-52-7275845
> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> www.r-statistics.com (English)
> ----------------------------------------------------------------------------------------------
>
>
>
>
> On Fri, Jul 2, 2010 at 10:31 AM, Bernd Weiss <[hidden email]>wrote:
>
>> Am 02.07.2010 08:10, schrieb Wincent:
>>> Dear all,
>>>
>>> I try to show a subset of coefficients in my presentation. It seems
>>> that a "standard" table is not a good way to go. I found figure 9
>>> (page 9) in this file (
>>>
>> http://www.destatis.de/jetspeed/portal/cms/Sites/destatis/Internet/DE/Content/Wissenschaftsforum/Kolloquien/VisualisierungModellierung__Beitrag,property=file.pdf
>>>
>>>
>> ) looks pretty good. I wonder if there is any function for such plot?
>>> Or any suggestion on how to present statistical models in a
>>> presentation?
>>
>> Hi Wincent,
>>
>> I guess you are looking for "Using Graphs Instead of Tables in Political
>> Science" by Kastellec/Leoni <http://tables2graphs.com/doku.php>.
>>
>> HTH,
>>
>> Bernd
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Visualization of coefficients

Tal Galili
In reply to this post by Wincent
BTW, another visualization that might be useful in your case is
Nomogram<http://en.wikipedia.org/wiki/Nomogram>
:
http://lib.stat.cmu.edu/S/Harrell/help/Design/html/nomogram.html

(I remember first encountering it on a lecture by Frank Harrell lecture and
being very happy for the discovery)



Tal

----------------Contact
Details:-------------------------------------------------------
Contact me: [hidden email] |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
----------------------------------------------------------------------------------------------




On Fri, Jul 2, 2010 at 9:10 AM, Wincent <[hidden email]> wrote:

> Dear all,
>
> I try to show a subset of coefficients in my presentation. It seems
> that a "standard" table is not a good way to go. I found figure 9
> (page 9) in this file (
>
> http://www.destatis.de/jetspeed/portal/cms/Sites/destatis/Internet/DE/Content/Wissenschaftsforum/Kolloquien/VisualisierungModellierung__Beitrag,property=file.pdf
> ) looks pretty good. I wonder if there is any function for such plot?
> Or any suggestion on how to present statistical models in a
> presentation?
>
> Thank you.
>
> --
> Wincent Rong-gui HUANG
> Doctoral Candidate
> Dept of Public and Social Administration
> City University of Hong Kong
> http://asrr.r-forge.r-project.org/rghuang.html
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Visualization of coefficients

Frank Harrell
Please note that Statlib is about 10 years out of date with respect to
my software.

See http://biostat.mc.vanderbilt.edu/Rrms

Frank


On 07/02/2010 01:12 PM, Tal Galili wrote:

> BTW, another visualization that might be useful in your case is
> Nomogram<http://en.wikipedia.org/wiki/Nomogram>
> :
> http://lib.stat.cmu.edu/S/Harrell/help/Design/html/nomogram.html
>
> (I remember first encountering it on a lecture by Frank Harrell lecture and
> being very happy for the discovery)
>
>
>
> Tal
>
> ----------------Contact
> Details:-------------------------------------------------------
> Contact me: [hidden email] |  972-52-7275845
> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> www.r-statistics.com (English)
> ----------------------------------------------------------------------------------------------
>
>
>
>
> On Fri, Jul 2, 2010 at 9:10 AM, Wincent<[hidden email]>  wrote:
>
>> Dear all,
>>
>> I try to show a subset of coefficients in my presentation. It seems
>> that a "standard" table is not a good way to go. I found figure 9
>> (page 9) in this file (
>>
>> http://www.destatis.de/jetspeed/portal/cms/Sites/destatis/Internet/DE/Content/Wissenschaftsforum/Kolloquien/VisualisierungModellierung__Beitrag,property=file.pdf
>> ) looks pretty good. I wonder if there is any function for such plot?
>> Or any suggestion on how to present statistical models in a
>> presentation?
>>
>> Thank you.
>>
>> --
>> Wincent Rong-gui HUANG
>> Doctoral Candidate
>> Dept of Public and Social Administration
>> City University of Hong Kong
>> http://asrr.r-forge.r-project.org/rghuang.html
>>

--
Frank E Harrell Jr   Professor and Chairman        School of Medicine
                      Department of Biostatistics   Vanderbilt University

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Frank Harrell
Department of Biostatistics, Vanderbilt University
Reply | Threaded
Open this post in threaded view
|

Re: Visualization of coefficients

Thomas Lumley
In reply to this post by Achim Zeileis-4
On Fri, 2 Jul 2010, Achim Zeileis wrote:

> I've thought about adding a plot() method for the coeftest() function in the
> "lmtest" package. Essentially, it relies on a coef() and a vcov() method
> being available - and that a central limit theorem holds. For releasing it as
> a general function in the package the code is still too raw, but maybe it's
> useful for someone on the list. Hence, I've included it below.


Achim,

If you are putting this in the lmtest package it would be nice if it also handled multiple models.   I'm more often interested in plotting estimates of the same coefficient in different models than of different coefficients in the same model.

    -thomas

> An example would be to visualize all coefficients except the intercept for
> the Mroz data:
>
> data("Mroz", package = "car")
> fm <- glm(lfp ~ ., data = Mroz, family = binomial)
> coefplot(fm, parm = -1)
>
> hth,
> Z
>
> coefplot <- function(object, df = NULL, level = 0.95, parm = NULL,
>  labels = TRUE, xlab = "Coefficient confidence intervals", ylab = "",
>  xlim = NULL, ylim = NULL,
>  las = 1, lwd = 1, lty = c(1, 2), pch = 19, col = 1,
>  length = 0, angle = 30, code = 3, ...)
> {
>  cf <- coef(object)
>  se <- sqrt(diag(vcov(object)))
>  if(is.null(parm)) parm <- seq_along(cf)
>  if(is.numeric(parm) | is.logical(parm)) parm <- names(cf)[parm]
>  if(is.character(parm)) parm <- which(names(cf) %in% parm)
>  cf <- cf[parm]
>  se <- se[parm]
>  k <- length(cf)
>
>  if(is.null(df)) {
>    df <- if(identical(class(object), "lm")) df.residual(object) else 0
>  }
>
>  critval <- if(df > 0 & is.finite(df)) {
>    qt((1 - level)/2, df = df)
>  } else {
>    qnorm((1 - level)/2)
>  }
>  ci1 <- cf + critval * se
>  ci2 <- cf - critval * se
>
>  lwd <- rep(lwd, length.out = 2)
>  lty <- rep(lty, length.out = 2)
>  pch <- rep(pch, length.out = k)
>  col <- rep(col, length.out = k)
>
>  if(is.null(xlim)) xlim <- range(c(0, min(ci1), max(ci2)))
>  if(is.null(ylim)) ylim <- c(1 - 0.05 * k, 1.05 * k)
>
>  if(isTRUE(labels)) labels <- names(cf)
>  if(identical(labels, FALSE)) labels <- ""
>  labels <- rep(labels, length.out = k)
>
>  plot(0, 0, xlim = xlim, ylim = ylim, xlab = xlab, ylab = ylab,
>    axes = FALSE, type = "n", las = las, ...)
>  arrows(ci1, 1:k, ci2, 1:k, lty = lty[1], lwd = lwd[1], col = col,
>    length = length, angle = angle, code = code)
>  points(cf, 1:k, pch = pch, col = col)
>  abline(v = 0, lty = lty[2], lwd = lwd[2])
>  axis(1)
>  axis(2, at = 1:k, labels = labels, las = las)
>  box()
> }
>
>
> On Fri, 2 Jul 2010, Tal Galili wrote:
>
>> Specifically this link:
>> http://tables2graphs.com/doku.php?id=04_regression_coefficients
>>
>> Great reference Bernd, thank you.
>>
>> Tal
>>
>>
>> ----------------Contact
>> Details:-------------------------------------------------------
>> Contact me: [hidden email] |  972-52-7275845
>> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
>> www.r-statistics.com (English)
>>  
>> ----------------------------------------------------------------------------------------------
>>
>>
>>
>>
>> On Fri, Jul 2, 2010 at 10:31 AM, Bernd Weiss
>> <[hidden email]>wrote:
>>
>>> Am 02.07.2010 08:10, schrieb Wincent:
>>>> Dear all,
>>>>
>>>> I try to show a subset of coefficients in my presentation. It seems
>>>> that a "standard" table is not a good way to go. I found figure 9
>>>> (page 9) in this file (
>>>>
>>> http://www.destatis.de/jetspeed/portal/cms/Sites/destatis/Internet/DE/Content/Wissenschaftsforum/Kolloquien/VisualisierungModellierung__Beitrag,property=file.pdf
>>>>
>>>>
>>> ) looks pretty good. I wonder if there is any function for such plot?
>>>> Or any suggestion on how to present statistical models in a
>>>> presentation?
>>>
>>> Hi Wincent,
>>>
>>> I guess you are looking for "Using Graphs Instead of Tables in Political
>>> Science" by Kastellec/Leoni <http://tables2graphs.com/doku.php>.
>>>
>>> HTH,
>>>
>>> Bernd
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

Thomas Lumley
Professor of Biostatistics
University of Washington, Seattle

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Visualization of coefficients

Achim Zeileis-4
On Fri, 2 Jul 2010, Thomas Lumley wrote:

> On Fri, 2 Jul 2010, Achim Zeileis wrote:
>
>> I've thought about adding a plot() method for the coeftest() function in
>> the "lmtest" package. Essentially, it relies on a coef() and a vcov()
>> method being available - and that a central limit theorem holds. For
>> releasing it as a general function in the package the code is still too
>> raw, but maybe it's useful for someone on the list. Hence, I've included it
>> below.
>
>
> Achim,
>
> If you are putting this in the lmtest package it would be nice if it also
> handled multiple models.   I'm more often interested in plotting estimates of
> the same coefficient in different models than of different coefficients in
> the same model.

Yes, good suggestion. I'll have a stab at it over the summer...
Z

>   -thomas
>
>> An example would be to visualize all coefficients except the intercept for
>> the Mroz data:
>>
>> data("Mroz", package = "car")
>> fm <- glm(lfp ~ ., data = Mroz, family = binomial)
>> coefplot(fm, parm = -1)
>>
>> hth,
>> Z
>>
>> coefplot <- function(object, df = NULL, level = 0.95, parm = NULL,
>>  labels = TRUE, xlab = "Coefficient confidence intervals", ylab = "",
>>  xlim = NULL, ylim = NULL,
>>  las = 1, lwd = 1, lty = c(1, 2), pch = 19, col = 1,
>>  length = 0, angle = 30, code = 3, ...)
>> {
>>  cf <- coef(object)
>>  se <- sqrt(diag(vcov(object)))
>>  if(is.null(parm)) parm <- seq_along(cf)
>>  if(is.numeric(parm) | is.logical(parm)) parm <- names(cf)[parm]
>>  if(is.character(parm)) parm <- which(names(cf) %in% parm)
>>  cf <- cf[parm]
>>  se <- se[parm]
>>  k <- length(cf)
>>
>>  if(is.null(df)) {
>>    df <- if(identical(class(object), "lm")) df.residual(object) else 0
>>  }
>>
>>  critval <- if(df > 0 & is.finite(df)) {
>>    qt((1 - level)/2, df = df)
>>  } else {
>>    qnorm((1 - level)/2)
>>  }
>>  ci1 <- cf + critval * se
>>  ci2 <- cf - critval * se
>>
>>  lwd <- rep(lwd, length.out = 2)
>>  lty <- rep(lty, length.out = 2)
>>  pch <- rep(pch, length.out = k)
>>  col <- rep(col, length.out = k)
>>
>>  if(is.null(xlim)) xlim <- range(c(0, min(ci1), max(ci2)))
>>  if(is.null(ylim)) ylim <- c(1 - 0.05 * k, 1.05 * k)
>>
>>  if(isTRUE(labels)) labels <- names(cf)
>>  if(identical(labels, FALSE)) labels <- ""
>>  labels <- rep(labels, length.out = k)
>>
>>  plot(0, 0, xlim = xlim, ylim = ylim, xlab = xlab, ylab = ylab,
>>    axes = FALSE, type = "n", las = las, ...)
>>  arrows(ci1, 1:k, ci2, 1:k, lty = lty[1], lwd = lwd[1], col = col,
>>    length = length, angle = angle, code = code)
>>  points(cf, 1:k, pch = pch, col = col)
>>  abline(v = 0, lty = lty[2], lwd = lwd[2])
>>  axis(1)
>>  axis(2, at = 1:k, labels = labels, las = las)
>>  box()
>> }
>>
>>
>> On Fri, 2 Jul 2010, Tal Galili wrote:
>>
>>> Specifically this link:
>>> http://tables2graphs.com/doku.php?id=04_regression_coefficients
>>>
>>> Great reference Bernd, thank you.
>>>
>>> Tal
>>>
>>>
>>> ----------------Contact
>>> Details:-------------------------------------------------------
>>> Contact me: [hidden email] |  972-52-7275845
>>> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
>>> www.r-statistics.com (English)
>>>
>>> ----------------------------------------------------------------------------------------------
>>>
>>>
>>>
>>>
>>> On Fri, Jul 2, 2010 at 10:31 AM, Bernd Weiss
>>> <[hidden email]>wrote:
>>>
>>>> Am 02.07.2010 08:10, schrieb Wincent:
>>>>> Dear all,
>>>>>
>>>>> I try to show a subset of coefficients in my presentation. It seems
>>>>> that a "standard" table is not a good way to go. I found figure 9
>>>>> (page 9) in this file (
>>>>>
>>>> http://www.destatis.de/jetspeed/portal/cms/Sites/destatis/Internet/DE/Content/Wissenschaftsforum/Kolloquien/VisualisierungModellierung__Beitrag,property=file.pdf
>>>>>
>>>>>
>>>> ) looks pretty good. I wonder if there is any function for such plot?
>>>>> Or any suggestion on how to present statistical models in a
>>>>> presentation?
>>>>
>>>> Hi Wincent,
>>>>
>>>> I guess you are looking for "Using Graphs Instead of Tables in Political
>>>> Science" by Kastellec/Leoni <http://tables2graphs.com/doku.php>.
>>>>
>>>> HTH,
>>>>
>>>> Bernd
>>>>
>>>> ______________________________________________
>>>> [hidden email] mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> PLEASE do read the posting guide
>>>> http://www.R-project.org/posting-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> Thomas Lumley
> Professor of Biostatistics
> University of Washington, Seattle
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Visualization of coefficients

David Atkins
In reply to this post by Achim Zeileis-4


FYI, there is already a function coefplot in the arm package; for
example, compare:

 > library(arm)
Loading required package: MASS
Loading required package: Matrix
[snip]
Attaching package: 'arm'

The following object(s) are masked from 'package:coda':

     traceplot

 > data("Mroz", package = "car")
 > fm <- glm(lfp ~ ., data = Mroz, family = binomial)
 > coefplot(fm)

with version below.

cheeres, Dave

 >
 > detach("package:arm")
 > coefplot <- function(object, df = NULL, level = 0.95, parm = NULL,
+    labels = TRUE, xlab = "Coefficient confidence intervals", ylab = "",
+    xlim = NULL, ylim = NULL,
+    las = 1, lwd = 1, lty = c(1, 2), pch = 19, col = 1,
+    length = 0, angle = 30, code = 3, ...)
+ {
+    cf <- coef(object)
+    se <- sqrt(diag(vcov(object)))
+    if(is.null(parm)) parm <- seq_along(cf)
+    if(is.numeric(parm) | is.logical(parm)) parm <- names(cf)[parm]
+    if(is.character(parm)) parm <- which(names(cf) %in% parm)
+    cf <- cf[parm]
+    se <- se[parm]
+    k <- length(cf)
+
+    if(is.null(df)) {
+      df <- if(identical(class(object), "lm")) df.residual(object) else 0
+    }
+
+    critval <- if(df > 0 & is.finite(df)) {
+      qt((1 - level)/2, df = df)
+    } else {
+      qnorm((1 - level)/2)
+    }
+    ci1 <- cf + critval * se
+    ci2 <- cf - critval * se
+
+    lwd <- rep(lwd, length.out = 2)
+    lty <- rep(lty, length.out = 2)
+    pch <- rep(pch, length.out = k)
+    col <- rep(col, length.out = k)
+
+    if(is.null(xlim)) xlim <- range(c(0, min(ci1), max(ci2)))
+    if(is.null(ylim)) ylim <- c(1 - 0.05 * k, 1.05 * k)
+
+    if(isTRUE(labels)) labels <- names(cf)
+    if(identical(labels, FALSE)) labels <- ""
+    labels <- rep(labels, length.out = k)
+
+    plot(0, 0, xlim = xlim, ylim = ylim, xlab = xlab, ylab = ylab,
+      axes = FALSE, type = "n", las = las, ...)
+    arrows(ci1, 1:k, ci2, 1:k, lty = lty[1], lwd = lwd[1], col = col,
+      length = length, angle = angle, code = code)
+    points(cf, 1:k, pch = pch, col = col)
+    abline(v = 0, lty = lty[2], lwd = lwd[2])
+    axis(1)
+    axis(2, at = 1:k, labels = labels, las = las)
+    box()
+ }
 >
 >
 > coefplot(fm, parm = -1)



Achim Zeileis wrote:

I've thought about adding a plot() method for the coeftest() function in
the "lmtest" package. Essentially, it relies on a coef() and a vcov()
method being available - and that a central limit theorem holds. For
releasing it as a general function in the package the code is still too
raw, but maybe it's useful for someone on the list. Hence, I've included
it below.

An example would be to visualize all coefficients except the intercept for
the Mroz data:

data("Mroz", package = "car")
fm <- glm(lfp ~ ., data = Mroz, family = binomial)
coefplot(fm, parm = -1)

hth,
Z

coefplot <- function(object, df = NULL, level = 0.95, parm = NULL,
    labels = TRUE, xlab = "Coefficient confidence intervals", ylab = "",
    xlim = NULL, ylim = NULL,
    las = 1, lwd = 1, lty = c(1, 2), pch = 19, col = 1,
    length = 0, angle = 30, code = 3, ...)
{
    cf <- coef(object)
    se <- sqrt(diag(vcov(object)))
    if(is.null(parm)) parm <- seq_along(cf)
    if(is.numeric(parm) | is.logical(parm)) parm <- names(cf)[parm]
    if(is.character(parm)) parm <- which(names(cf) %in% parm)
    cf <- cf[parm]
    se <- se[parm]
    k <- length(cf)

    if(is.null(df)) {
      df <- if(identical(class(object), "lm")) df.residual(object) else 0
    }

    critval <- if(df > 0 & is.finite(df)) {
      qt((1 - level)/2, df = df)
    } else {
      qnorm((1 - level)/2)
    }
    ci1 <- cf + critval * se
    ci2 <- cf - critval * se

    lwd <- rep(lwd, length.out = 2)
    lty <- rep(lty, length.out = 2)
    pch <- rep(pch, length.out = k)
    col <- rep(col, length.out = k)

    if(is.null(xlim)) xlim <- range(c(0, min(ci1), max(ci2)))
    if(is.null(ylim)) ylim <- c(1 - 0.05 * k, 1.05 * k)

    if(isTRUE(labels)) labels <- names(cf)
    if(identical(labels, FALSE)) labels <- ""
    labels <- rep(labels, length.out = k)

    plot(0, 0, xlim = xlim, ylim = ylim, xlab = xlab, ylab = ylab,
      axes = FALSE, type = "n", las = las, ...)
    arrows(ci1, 1:k, ci2, 1:k, lty = lty[1], lwd = lwd[1], col = col,
      length = length, angle = angle, code = code)
    points(cf, 1:k, pch = pch, col = col)
    abline(v = 0, lty = lty[2], lwd = lwd[2])
    axis(1)
    axis(2, at = 1:k, labels = labels, las = las)
    box()
}


On Fri, 2 Jul 2010, Tal Galili wrote:

 > Specifically this link:
 > http://tables2graphs.com/doku.php?id=04_regression_coefficients
 >
 > Great reference Bernd, thank you.
 >
 > Tal
 >
 >
 > ----------------Contact
 > Details:-------------------------------------------------------
 > Contact me: Tal.Galili at gmail.com |  972-52-7275845
 > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
 > www.r-statistics.com (English)
 >
----------------------------------------------------------------------------------------------
 >
 >
 >
 >
 > On Fri, Jul 2, 2010 at 10:31 AM, Bernd Weiss <bernd.weiss at
uni-koeln.de>wrote:
 >
 >> Am 02.07.2010 08:10, schrieb Wincent:
 >>> Dear all,
 >>>
 >>> I try to show a subset of coefficients in my presentation. It seems
 >>> that a "standard" table is not a good way to go. I found figure 9
 >>> (page 9) in this file (
 >>>
 >>
http://www.destatis.de/jetspeed/portal/cms/Sites/destatis/Internet/DE/Content/Wissenschaftsforum/Kolloquien/VisualisierungModellierung__Beitrag,property=file.pdf
 >>>
 >>>
 >> ) looks pretty good. I wonder if there is any function for such plot?
 >>> Or any suggestion on how to present statistical models in a
 >>> presentation?
 >>
 >> Hi Wincent,
 >>
 >> I guess you are looking for "Using Graphs Instead of Tables in Political
 >> Science" by Kastellec/Leoni <http://tables2graphs.com/doku.php>.
 >>
 >> HTH,
 >>
 >> Bernd
 >>
 >> ______________________________________________
 >> R-help at r-project.org mailing list
 >> https://stat.ethz.ch/mailman/listinfo/r-help
 >> PLEASE do read the posting guide
 >> http://www.R-project.org/posting-guide.html
 >> and provide commented, minimal, self-contained, reproducible code.
 >>
 >
 > [[alternative HTML version deleted]]
 >
 > ______________________________________________
 > R-help at r-project.org mailing list
 > https://stat.ethz.ch/mailman/listinfo/r-help
 > PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
 > and provide commented, minimal, self-contained, reproducible code.
 >

--
Dave Atkins, PhD
Research Associate Professor
Department of Psychiatry and Behavioral Science
University of Washington
[hidden email]

Center for the Study of Health and Risk Behaviors (CSHRB)
1100 NE 45th Street, Suite 300
Seattle, WA  98105
206-616-3879
http://depts.washington.edu/cshrb/
(Mon-Wed)

Center for Healthcare Improvement, for Addictions, Mental Illness,
   Medically Vulnerable Populations (CHAMMP)
325 9th Avenue, 2HH-15
Box 359911
Seattle, WA 98104
http://www.chammp.org
(Thurs)

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Visualization of coefficients

Tal Galili
Hello David,
Thanks to your posting I started looking at the function in the arm package.
 It appears this function is quite mature, and offers (for example) the
ability to easily overlap coefficients from several models.

I updated the post I published on the subject, so at the end of it I give an
example of comparing the coef of several models:
http://www.r-statistics.com/2010/07/visualization-of-regression-coefficients-in-r/

Thanks again for the pointer.

Best,
Tal




----------------Contact
Details:-------------------------------------------------------
Contact me: [hidden email] |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
----------------------------------------------------------------------------------------------




On Wed, Jul 7, 2010 at 12:02 AM, David Atkins <[hidden email]>wrote:

>
>
> FYI, there is already a function coefplot in the arm package; for example,
> compare:
>
> > library(arm)
> Loading required package: MASS
> Loading required package: Matrix
> [snip]
> Attaching package: 'arm'
>
> The following object(s) are masked from 'package:coda':
>
>    traceplot
>
>
> > data("Mroz", package = "car")
> > fm <- glm(lfp ~ ., data = Mroz, family = binomial)
> > coefplot(fm)
>
> with version below.
>
> cheeres, Dave
>
> >
> > detach("package:arm")
>
> > coefplot <- function(object, df = NULL, level = 0.95, parm = NULL,
> +    labels = TRUE, xlab = "Coefficient confidence intervals", ylab = "",
> +    xlim = NULL, ylim = NULL,
> +    las = 1, lwd = 1, lty = c(1, 2), pch = 19, col = 1,
> +    length = 0, angle = 30, code = 3, ...)
> + {
> +    cf <- coef(object)
> +    se <- sqrt(diag(vcov(object)))
> +    if(is.null(parm)) parm <- seq_along(cf)
> +    if(is.numeric(parm) | is.logical(parm)) parm <- names(cf)[parm]
> +    if(is.character(parm)) parm <- which(names(cf) %in% parm)
> +    cf <- cf[parm]
> +    se <- se[parm]
> +    k <- length(cf)
> +
> +    if(is.null(df)) {
> +      df <- if(identical(class(object), "lm")) df.residual(object) else 0
> +    }
> +
> +    critval <- if(df > 0 & is.finite(df)) {
> +      qt((1 - level)/2, df = df)
> +    } else {
> +      qnorm((1 - level)/2)
> +    }
> +    ci1 <- cf + critval * se
> +    ci2 <- cf - critval * se
> +
> +    lwd <- rep(lwd, length.out = 2)
> +    lty <- rep(lty, length.out = 2)
> +    pch <- rep(pch, length.out = k)
> +    col <- rep(col, length.out = k)
> +
> +    if(is.null(xlim)) xlim <- range(c(0, min(ci1), max(ci2)))
> +    if(is.null(ylim)) ylim <- c(1 - 0.05 * k, 1.05 * k)
> +
> +    if(isTRUE(labels)) labels <- names(cf)
> +    if(identical(labels, FALSE)) labels <- ""
> +    labels <- rep(labels, length.out = k)
> +
> +    plot(0, 0, xlim = xlim, ylim = ylim, xlab = xlab, ylab = ylab,
> +      axes = FALSE, type = "n", las = las, ...)
> +    arrows(ci1, 1:k, ci2, 1:k, lty = lty[1], lwd = lwd[1], col = col,
> +      length = length, angle = angle, code = code)
> +    points(cf, 1:k, pch = pch, col = col)
> +    abline(v = 0, lty = lty[2], lwd = lwd[2])
> +    axis(1)
> +    axis(2, at = 1:k, labels = labels, las = las)
> +    box()
> + }
> >
> >
> > coefplot(fm, parm = -1)
>
>
>
>
> Achim Zeileis wrote:
>
> I've thought about adding a plot() method for the coeftest() function in
> the "lmtest" package. Essentially, it relies on a coef() and a vcov()
> method being available - and that a central limit theorem holds. For
> releasing it as a general function in the package the code is still too
> raw, but maybe it's useful for someone on the list. Hence, I've included
> it below.
>
> An example would be to visualize all coefficients except the intercept for
> the Mroz data:
>
> data("Mroz", package = "car")
> fm <- glm(lfp ~ ., data = Mroz, family = binomial)
> coefplot(fm, parm = -1)
>
> hth,
> Z
>
> coefplot <- function(object, df = NULL, level = 0.95, parm = NULL,
>   labels = TRUE, xlab = "Coefficient confidence intervals", ylab = "",
>   xlim = NULL, ylim = NULL,
>   las = 1, lwd = 1, lty = c(1, 2), pch = 19, col = 1,
>   length = 0, angle = 30, code = 3, ...)
> {
>   cf <- coef(object)
>   se <- sqrt(diag(vcov(object)))
>   if(is.null(parm)) parm <- seq_along(cf)
>   if(is.numeric(parm) | is.logical(parm)) parm <- names(cf)[parm]
>   if(is.character(parm)) parm <- which(names(cf) %in% parm)
>   cf <- cf[parm]
>   se <- se[parm]
>   k <- length(cf)
>
>   if(is.null(df)) {
>     df <- if(identical(class(object), "lm")) df.residual(object) else 0
>   }
>
>   critval <- if(df > 0 & is.finite(df)) {
>     qt((1 - level)/2, df = df)
>   } else {
>     qnorm((1 - level)/2)
>   }
>   ci1 <- cf + critval * se
>   ci2 <- cf - critval * se
>
>   lwd <- rep(lwd, length.out = 2)
>   lty <- rep(lty, length.out = 2)
>   pch <- rep(pch, length.out = k)
>   col <- rep(col, length.out = k)
>
>   if(is.null(xlim)) xlim <- range(c(0, min(ci1), max(ci2)))
>   if(is.null(ylim)) ylim <- c(1 - 0.05 * k, 1.05 * k)
>
>   if(isTRUE(labels)) labels <- names(cf)
>   if(identical(labels, FALSE)) labels <- ""
>   labels <- rep(labels, length.out = k)
>
>   plot(0, 0, xlim = xlim, ylim = ylim, xlab = xlab, ylab = ylab,
>     axes = FALSE, type = "n", las = las, ...)
>   arrows(ci1, 1:k, ci2, 1:k, lty = lty[1], lwd = lwd[1], col = col,
>     length = length, angle = angle, code = code)
>   points(cf, 1:k, pch = pch, col = col)
>   abline(v = 0, lty = lty[2], lwd = lwd[2])
>   axis(1)
>   axis(2, at = 1:k, labels = labels, las = las)
>   box()
> }
>
>
> On Fri, 2 Jul 2010, Tal Galili wrote:
>
> > Specifically this link:
> > http://tables2graphs.com/doku.php?id=04_regression_coefficients
> >
> > Great reference Bernd, thank you.
> >
> > Tal
> >
> >
> > ----------------Contact
> > Details:-------------------------------------------------------
> > Contact me: Tal.Galili at gmail.com |  972-52-7275845
>
> > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> > www.r-statistics.com (English)
> >
> ----------------------------------------------------------------------------------------------
> >
> >
> >
> >
> > On Fri, Jul 2, 2010 at 10:31 AM, Bernd Weiss <bernd.weiss at
> uni-koeln.de>wrote:
>
> >
> >> Am 02.07.2010 08:10, schrieb Wincent:
> >>> Dear all,
> >>>
> >>> I try to show a subset of coefficients in my presentation. It seems
> >>> that a "standard" table is not a good way to go. I found figure 9
> >>> (page 9) in this file (
> >>>
> >>
> http://www.destatis.de/jetspeed/portal/cms/Sites/destatis/Internet/DE/Content/Wissenschaftsforum/Kolloquien/VisualisierungModellierung__Beitrag,property=file.pdf
> >>>
> >>>
> >> ) looks pretty good. I wonder if there is any function for such plot?
> >>> Or any suggestion on how to present statistical models in a
> >>> presentation?
> >>
> >> Hi Wincent,
> >>
> >> I guess you are looking for "Using Graphs Instead of Tables in Political
> >> Science" by Kastellec/Leoni <http://tables2graphs.com/doku.php>.
> >>
> >> HTH,
> >>
> >> Bernd
> >>
> >> ______________________________________________
> >> R-help at r-project.org mailing list
>
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
>
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
> --
> Dave Atkins, PhD
> Research Associate Professor
> Department of Psychiatry and Behavioral Science
> University of Washington
> [hidden email]
>
> Center for the Study of Health and Risk Behaviors (CSHRB)
> 1100 NE 45th Street, Suite 300
> Seattle, WA  98105
> 206-616-3879
> http://depts.washington.edu/cshrb/
> (Mon-Wed)
>
> Center for Healthcare Improvement, for Addictions, Mental Illness,
>  Medically Vulnerable Populations (CHAMMP)
> 325 9th Avenue, 2HH-15
> Box 359911
> Seattle, WA 98104
> http://www.chammp.org
> (Thurs)
>
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Visualization of coefficients

cybaea
Thanks Tal.  Nice summary on the web page.  I think the last example
would be even better if it was a stand-alone piece of code (i.e.: with
data) that we could run.  For example

library("arm")
data("Mroz", package = "car")
M1<-      glm(lfp ~ ., data = Mroz, family = binomial)
M2<- bayesglm(lfp ~ ., data = Mroz, family = binomial)
M3<-      glm(lfp ~ ., data = Mroz, family = binomial(probit))
coefplot(M2, xlim=c(-2, 6),            intercept=TRUE)
coefplot(M1, add=TRUE, col.pts="red",  intercept=TRUE)
coefplot(M3, add=TRUE, col.pts="blue", intercept=TRUE, offset=0.2)


Allan

On 07/07/10 09:16, Tal Galili wrote:

> Hello David,
> Thanks to your posting I started looking at the function in the arm
> package.  It appears this function is quite mature, and offers (for
> example) the ability to easily overlap coefficients from several models.
>
> I updated the post I published on the subject, so at the end of it I
> give an example of comparing the coef of several models:
> http://www.r-statistics.com/2010/07/visualization-of-regression-coefficients-in-r/
>
> Thanks again for the pointer.
>
> Best,
> Tal
> [...]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Visualization of coefficients

Achim Zeileis-4
In reply to this post by Tal Galili
On Wed, 7 Jul 2010, Tal Galili wrote:

> Hello David,
> Thanks to your posting I started looking at the function in the arm package.
>  It appears this function is quite mature, and offers (for example) the
> ability to easily overlap coefficients from several models.

Re: more mature. arm's coefplot() is more flexible in certain respects,
mine is more convenient in others. The overlay functionality is something
arm's coefplot() is better in and it also as some further options
(vertical vs. horizontal etc.). My coefplot() has the advantage that it
does not need any modification as long as coef() and vcov() methods are
available. Furthermore, "level" can specify the significance level
(instead of always using one and two standard errors, respectively).
But it shouldn't be too hard to create a superset of all options.

> I updated the post I published on the subject, so at the end of it I give an
> example of comparing the coef of several models:
> http://www.r-statistics.com/2010/07/visualization-of-regression-coefficient
> s-in-r/

As Allan pointed out in his reply, something fully reproducible would be
nice. Also, if you keep the example with quasi-complete separation, it
would be worth pointing this out. (Because the maximum likelihood
estimator is Infinity in this case.)

Finally, the Poisson model in comparison with the binomial models does not
make much sense, I guess.

Best,
Z

> Thanks again for the pointer.
>
> Best,
> Tal
>
>
>
>
> ----------------Contact
> Details:-------------------------------------------------------
> Contact me: [hidden email] |  972-52-7275845
> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> www.r-statistics.com (English)
> ---------------------------------------------------------------------------
> -------------------
>
>
>
>
> On Wed, Jul 7, 2010 at 12:02 AM, David Atkins <[hidden email]>
> wrote:
>
>
>       FYI, there is already a function coefplot in the arm package;
>       for example, compare:
>
>       > library(arm)
>       Loading required package: MASS
>       Loading required package: Matrix
>       [snip]
>       Attaching package: 'arm'
>
>       The following object(s) are masked from 'package:coda':
>
>          traceplot
>
>       > data("Mroz", package = "car")
>       > fm <- glm(lfp ~ ., data = Mroz, family = binomial)
> > coefplot(fm)
>
> with version below.
>
> cheeres, Dave
>
> >
> > detach("package:arm")
>
> > coefplot <- function(object, df = NULL, level = 0.95, parm = NULL,
> +    labels = TRUE, xlab = "Coefficient confidence intervals", ylab =
> "",
> +    xlim = NULL, ylim = NULL,
> +    las = 1, lwd = 1, lty = c(1, 2), pch = 19, col = 1,
> +    length = 0, angle = 30, code = 3, ...)
> + {
> +    cf <- coef(object)
> +    se <- sqrt(diag(vcov(object)))
> +    if(is.null(parm)) parm <- seq_along(cf)
> +    if(is.numeric(parm) | is.logical(parm)) parm <- names(cf)[parm]
> +    if(is.character(parm)) parm <- which(names(cf) %in% parm)
> +    cf <- cf[parm]
> +    se <- se[parm]
> +    k <- length(cf)
> +
> +    if(is.null(df)) {
> +      df <- if(identical(class(object), "lm")) df.residual(object)
> else 0
> +    }
> +
> +    critval <- if(df > 0 & is.finite(df)) {
> +      qt((1 - level)/2, df = df)
> +    } else {
> +      qnorm((1 - level)/2)
> +    }
> +    ci1 <- cf + critval * se
> +    ci2 <- cf - critval * se
> +
> +    lwd <- rep(lwd, length.out = 2)
> +    lty <- rep(lty, length.out = 2)
> +    pch <- rep(pch, length.out = k)
> +    col <- rep(col, length.out = k)
> +
> +    if(is.null(xlim)) xlim <- range(c(0, min(ci1), max(ci2)))
> +    if(is.null(ylim)) ylim <- c(1 - 0.05 * k, 1.05 * k)
> +
> +    if(isTRUE(labels)) labels <- names(cf)
> +    if(identical(labels, FALSE)) labels <- ""
> +    labels <- rep(labels, length.out = k)
> +
> +    plot(0, 0, xlim = xlim, ylim = ylim, xlab = xlab, ylab = ylab,
> +      axes = FALSE, type = "n", las = las, ...)
> +    arrows(ci1, 1:k, ci2, 1:k, lty = lty[1], lwd = lwd[1], col = col,
> +      length = length, angle = angle, code = code)
> +    points(cf, 1:k, pch = pch, col = col)
> +    abline(v = 0, lty = lty[2], lwd = lwd[2])
> +    axis(1)
> +    axis(2, at = 1:k, labels = labels, las = las)
> +    box()
> + }
> >
> >
> > coefplot(fm, parm = -1)
>
>
>
>
> Achim Zeileis wrote:
>
> I've thought about adding a plot() method for the coeftest() function
> in
> the "lmtest" package. Essentially, it relies on a coef() and a vcov()
> method being available - and that a central limit theorem holds. For
> releasing it as a general function in the package the code is still
> too
> raw, but maybe it's useful for someone on the list. Hence, I've
> included
> it below.
>
> An example would be to visualize all coefficients except the intercept
> for
> the Mroz data:
>
> data("Mroz", package = "car")
> fm <- glm(lfp ~ ., data = Mroz, family = binomial)
> coefplot(fm, parm = -1)
>
> hth,
> Z
>
> coefplot <- function(object, df = NULL, level = 0.95, parm = NULL,
>   labels = TRUE, xlab = "Coefficient confidence intervals", ylab = "",
>   xlim = NULL, ylim = NULL,
>   las = 1, lwd = 1, lty = c(1, 2), pch = 19, col = 1,
>   length = 0, angle = 30, code = 3, ...)
> {
>   cf <- coef(object)
>   se <- sqrt(diag(vcov(object)))
>   if(is.null(parm)) parm <- seq_along(cf)
>   if(is.numeric(parm) | is.logical(parm)) parm <- names(cf)[parm]
>   if(is.character(parm)) parm <- which(names(cf) %in% parm)
>   cf <- cf[parm]
>   se <- se[parm]
>   k <- length(cf)
>
>   if(is.null(df)) {
>     df <- if(identical(class(object), "lm")) df.residual(object) else
> 0
>   }
>
>   critval <- if(df > 0 & is.finite(df)) {
>     qt((1 - level)/2, df = df)
>   } else {
>     qnorm((1 - level)/2)
>   }
>   ci1 <- cf + critval * se
>   ci2 <- cf - critval * se
>
>   lwd <- rep(lwd, length.out = 2)
>   lty <- rep(lty, length.out = 2)
>   pch <- rep(pch, length.out = k)
>   col <- rep(col, length.out = k)
>
>   if(is.null(xlim)) xlim <- range(c(0, min(ci1), max(ci2)))
>   if(is.null(ylim)) ylim <- c(1 - 0.05 * k, 1.05 * k)
>
>   if(isTRUE(labels)) labels <- names(cf)
>   if(identical(labels, FALSE)) labels <- ""
>   labels <- rep(labels, length.out = k)
>
>   plot(0, 0, xlim = xlim, ylim = ylim, xlab = xlab, ylab = ylab,
>     axes = FALSE, type = "n", las = las, ...)
>   arrows(ci1, 1:k, ci2, 1:k, lty = lty[1], lwd = lwd[1], col = col,
>     length = length, angle = angle, code = code)
>   points(cf, 1:k, pch = pch, col = col)
>   abline(v = 0, lty = lty[2], lwd = lwd[2])
>   axis(1)
>   axis(2, at = 1:k, labels = labels, las = las)
>   box()
> }
>
>
> On Fri, 2 Jul 2010, Tal Galili wrote:
>
> > Specifically this link:
> > http://tables2graphs.com/doku.php?id=04_regression_coefficients
> >
> > Great reference Bernd, thank you.
> >
> > Tal
> >
> >
> > ----------------Contact
> > Details:-------------------------------------------------------
> > Contact me: Tal.Galili at gmail.com |  972-52-7275845
> > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il
> (Hebrew) |
> > www.r-statistics.com (English)
> >---------------------------------------------------------------------------
> -------------------
> >
> >
> >
> >
> > On Fri, Jul 2, 2010 at 10:31 AM, Bernd Weiss <bernd.weiss at
> uni-koeln.de>wrote:
> >
> >> Am 02.07.2010 08:10, schrieb Wincent:
> >>> Dear all,
> >>>
> >>> I try to show a subset of coefficients in my presentation. It
> seems
> >>> that a "standard" table is not a good way to go. I found figure 9
> >>> (page 9) in this file (
> >>>
> >>http://www.destatis.de/jetspeed/portal/cms/Sites/destatis/Internet/DE/Conte
> nt/Wissenschaftsforum/Kolloquien/VisualisierungModellierung__Beitrag,proper
> ty=file.pdf
> >>>
> >>>
> >> ) looks pretty good. I wonder if there is any function for such
> plot?
> >>> Or any suggestion on how to present statistical models in a
> >>> presentation?
> >>
> >> Hi Wincent,
> >>
> >> I guess you are looking for "Using Graphs Instead of Tables in
> Political
> >> Science" by Kastellec/Leoni <http://tables2graphs.com/doku.php>.
> >>
> >> HTH,
> >>
> >> Bernd
> >>
> >> ______________________________________________
> >> R-help at r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
> --
> Dave Atkins, PhD
> Research Associate Professor
> Department of Psychiatry and Behavioral Science
> University of Washington
> [hidden email]
>
> Center for the Study of Health and Risk Behaviors (CSHRB)            
>  
> 1100 NE 45th Street, Suite 300  
> Seattle, WA  98105      
> 206-616-3879    
> http://depts.washington.edu/cshrb/
> (Mon-Wed)      
>
> Center for Healthcare Improvement, for Addictions, Mental Illness,
>  Medically Vulnerable Populations (CHAMMP)
> 325 9th Avenue, 2HH-15
> Box 359911
> Seattle, WA 98104
> http://www.chammp.org
> (Thurs)
>
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
>
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Visualization of coefficients

Tal Galili
Hi Achim and Allan,
I updated the post with Allan's example (thanks Allan).

Achim, you wrote:
"Finally, the Poisson model in comparison with the binomial models does not
make much sense, I guess."
I agree.  I wanted something to showcase the function on 3 models (with the
same predictors), and that's the easiest I could think of.  If you'd think
of a smarter example I'd be happy to incorporate it.

Best,
Tal



----------------Contact
Details:-------------------------------------------------------
Contact me: [hidden email] |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
----------------------------------------------------------------------------------------------




On Wed, Jul 7, 2010 at 12:10 PM, Achim Zeileis <[hidden email]>wrote:

> On Wed, 7 Jul 2010, Tal Galili wrote:
>
>  Hello David,
>> Thanks to your posting I started looking at the function in the arm
>> package.
>>  It appears this function is quite mature, and offers (for example) the
>> ability to easily overlap coefficients from several models.
>>
>
> Re: more mature. arm's coefplot() is more flexible in certain respects,
> mine is more convenient in others. The overlay functionality is something
> arm's coefplot() is better in and it also as some further options (vertical
> vs. horizontal etc.). My coefplot() has the advantage that it does not need
> any modification as long as coef() and vcov() methods are available.
> Furthermore, "level" can specify the significance level (instead of always
> using one and two standard errors, respectively).
> But it shouldn't be too hard to create a superset of all options.
>
>
>  I updated the post I published on the subject, so at the end of it I give
>> an
>> example of comparing the coef of several models:
>>
>> http://www.r-statistics.com/2010/07/visualization-of-regression-coefficient
>> s-in-r/
>>
>
> As Allan pointed out in his reply, something fully reproducible would be
> nice. Also, if you keep the example with quasi-complete separation, it would
> be worth pointing this out. (Because the maximum likelihood estimator is
> Infinity in this case.)
>
> Finally, the Poisson model in comparison with the binomial models does not
> make much sense, I guess.
>
> Best,
> Z
>
>  Thanks again for the pointer.
>>
>> Best,
>> Tal
>>
>>
>>
>>
>> ----------------Contact
>> Details:-------------------------------------------------------
>> Contact me: [hidden email] |  972-52-7275845
>> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
>> www.r-statistics.com (English)
>>
>> ---------------------------------------------------------------------------
>> -------------------
>>
>>
>>
>>
>> On Wed, Jul 7, 2010 at 12:02 AM, David Atkins <[hidden email]>
>> wrote:
>>
>>
>>      FYI, there is already a function coefplot in the arm package;
>>      for example, compare:
>>
>>      > library(arm)
>>      Loading required package: MASS
>>      Loading required package: Matrix
>>      [snip]
>>      Attaching package: 'arm'
>>
>>      The following object(s) are masked from 'package:coda':
>>
>>         traceplot
>>
>>      > data("Mroz", package = "car")
>>      > fm <- glm(lfp ~ ., data = Mroz, family = binomial)
>> > coefplot(fm)
>>
>> with version below.
>>
>> cheeres, Dave
>>
>> >
>> > detach("package:arm")
>>
>> > coefplot <- function(object, df = NULL, level = 0.95, parm = NULL,
>> +    labels = TRUE, xlab = "Coefficient confidence intervals", ylab =
>> "",
>> +    xlim = NULL, ylim = NULL,
>> +    las = 1, lwd = 1, lty = c(1, 2), pch = 19, col = 1,
>> +    length = 0, angle = 30, code = 3, ...)
>> + {
>> +    cf <- coef(object)
>> +    se <- sqrt(diag(vcov(object)))
>> +    if(is.null(parm)) parm <- seq_along(cf)
>> +    if(is.numeric(parm) | is.logical(parm)) parm <- names(cf)[parm]
>> +    if(is.character(parm)) parm <- which(names(cf) %in% parm)
>> +    cf <- cf[parm]
>> +    se <- se[parm]
>> +    k <- length(cf)
>> +
>> +    if(is.null(df)) {
>> +      df <- if(identical(class(object), "lm")) df.residual(object)
>> else 0
>> +    }
>> +
>> +    critval <- if(df > 0 & is.finite(df)) {
>> +      qt((1 - level)/2, df = df)
>> +    } else {
>> +      qnorm((1 - level)/2)
>> +    }
>> +    ci1 <- cf + critval * se
>> +    ci2 <- cf - critval * se
>> +
>> +    lwd <- rep(lwd, length.out = 2)
>> +    lty <- rep(lty, length.out = 2)
>> +    pch <- rep(pch, length.out = k)
>> +    col <- rep(col, length.out = k)
>> +
>> +    if(is.null(xlim)) xlim <- range(c(0, min(ci1), max(ci2)))
>> +    if(is.null(ylim)) ylim <- c(1 - 0.05 * k, 1.05 * k)
>> +
>> +    if(isTRUE(labels)) labels <- names(cf)
>> +    if(identical(labels, FALSE)) labels <- ""
>> +    labels <- rep(labels, length.out = k)
>> +
>> +    plot(0, 0, xlim = xlim, ylim = ylim, xlab = xlab, ylab = ylab,
>> +      axes = FALSE, type = "n", las = las, ...)
>> +    arrows(ci1, 1:k, ci2, 1:k, lty = lty[1], lwd = lwd[1], col = col,
>> +      length = length, angle = angle, code = code)
>> +    points(cf, 1:k, pch = pch, col = col)
>> +    abline(v = 0, lty = lty[2], lwd = lwd[2])
>> +    axis(1)
>> +    axis(2, at = 1:k, labels = labels, las = las)
>> +    box()
>> + }
>> >
>> >
>> > coefplot(fm, parm = -1)
>>
>>
>>
>>
>> Achim Zeileis wrote:
>>
>> I've thought about adding a plot() method for the coeftest() function
>> in
>> the "lmtest" package. Essentially, it relies on a coef() and a vcov()
>> method being available - and that a central limit theorem holds. For
>> releasing it as a general function in the package the code is still
>> too
>> raw, but maybe it's useful for someone on the list. Hence, I've
>> included
>> it below.
>>
>> An example would be to visualize all coefficients except the intercept
>> for
>> the Mroz data:
>>
>> data("Mroz", package = "car")
>> fm <- glm(lfp ~ ., data = Mroz, family = binomial)
>> coefplot(fm, parm = -1)
>>
>> hth,
>> Z
>>
>> coefplot <- function(object, df = NULL, level = 0.95, parm = NULL,
>>   labels = TRUE, xlab = "Coefficient confidence intervals", ylab = "",
>>   xlim = NULL, ylim = NULL,
>>   las = 1, lwd = 1, lty = c(1, 2), pch = 19, col = 1,
>>   length = 0, angle = 30, code = 3, ...)
>> {
>>   cf <- coef(object)
>>   se <- sqrt(diag(vcov(object)))
>>   if(is.null(parm)) parm <- seq_along(cf)
>>   if(is.numeric(parm) | is.logical(parm)) parm <- names(cf)[parm]
>>   if(is.character(parm)) parm <- which(names(cf) %in% parm)
>>   cf <- cf[parm]
>>   se <- se[parm]
>>   k <- length(cf)
>>
>>   if(is.null(df)) {
>>     df <- if(identical(class(object), "lm")) df.residual(object) else
>> 0
>>   }
>>
>>   critval <- if(df > 0 & is.finite(df)) {
>>     qt((1 - level)/2, df = df)
>>   } else {
>>     qnorm((1 - level)/2)
>>   }
>>   ci1 <- cf + critval * se
>>   ci2 <- cf - critval * se
>>
>>   lwd <- rep(lwd, length.out = 2)
>>   lty <- rep(lty, length.out = 2)
>>   pch <- rep(pch, length.out = k)
>>   col <- rep(col, length.out = k)
>>
>>   if(is.null(xlim)) xlim <- range(c(0, min(ci1), max(ci2)))
>>   if(is.null(ylim)) ylim <- c(1 - 0.05 * k, 1.05 * k)
>>
>>   if(isTRUE(labels)) labels <- names(cf)
>>   if(identical(labels, FALSE)) labels <- ""
>>   labels <- rep(labels, length.out = k)
>>
>>   plot(0, 0, xlim = xlim, ylim = ylim, xlab = xlab, ylab = ylab,
>>     axes = FALSE, type = "n", las = las, ...)
>>   arrows(ci1, 1:k, ci2, 1:k, lty = lty[1], lwd = lwd[1], col = col,
>>     length = length, angle = angle, code = code)
>>   points(cf, 1:k, pch = pch, col = col)
>>   abline(v = 0, lty = lty[2], lwd = lwd[2])
>>   axis(1)
>>   axis(2, at = 1:k, labels = labels, las = las)
>>   box()
>> }
>>
>>
>> On Fri, 2 Jul 2010, Tal Galili wrote:
>>
>> > Specifically this link:
>> > http://tables2graphs.com/doku.php?id=04_regression_coefficients
>> >
>> > Great reference Bernd, thank you.
>> >
>> > Tal
>> >
>> >
>> > ----------------Contact
>> > Details:-------------------------------------------------------
>> > Contact me: Tal.Galili at gmail.com |  972-52-7275845
>> > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il
>> (Hebrew) |
>> > www.r-statistics.com (English)
>>
>> >---------------------------------------------------------------------------
>> -------------------
>> >
>> >
>> >
>> >
>> > On Fri, Jul 2, 2010 at 10:31 AM, Bernd Weiss <bernd.weiss at
>> uni-koeln.de>wrote:
>> >
>> >> Am 02.07.2010 08:10, schrieb Wincent:
>> >>> Dear all,
>> >>>
>> >>> I try to show a subset of coefficients in my presentation. It
>> seems
>> >>> that a "standard" table is not a good way to go. I found figure 9
>> >>> (page 9) in this file (
>> >>>
>> >>
>> http://www.destatis.de/jetspeed/portal/cms/Sites/destatis/Internet/DE/Conte
>>
>> nt/Wissenschaftsforum/Kolloquien/VisualisierungModellierung__Beitrag,proper
>> ty=file.pdf
>> >>>
>> >>>
>> >> ) looks pretty good. I wonder if there is any function for such
>> plot?
>> >>> Or any suggestion on how to present statistical models in a
>> >>> presentation?
>> >>
>> >> Hi Wincent,
>> >>
>> >> I guess you are looking for "Using Graphs Instead of Tables in
>> Political
>> >> Science" by Kastellec/Leoni <http://tables2graphs.com/doku.php>.
>> >>
>> >> HTH,
>> >>
>> >> Bernd
>> >>
>> >> ______________________________________________
>> >> R-help at r-project.org mailing list
>> >> https://stat.ethz.ch/mailman/listinfo/r-help
>> >> PLEASE do read the posting guide
>> >> http://www.R-project.org/posting-guide.html
>> >> and provide commented, minimal, self-contained, reproducible code.
>> >>
>> >
>> >       [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > R-help at r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>> >
>>
>> --
>> Dave Atkins, PhD
>> Research Associate Professor
>> Department of Psychiatry and Behavioral Science
>> University of Washington
>> [hidden email]
>>
>> Center for the Study of Health and Risk Behaviors (CSHRB)
>>
>> 1100 NE 45th Street, Suite 300
>> Seattle, WA  98105
>> 206-616-3879
>> http://depts.washington.edu/cshrb/
>> (Mon-Wed)
>>
>> Center for Healthcare Improvement, for Addictions, Mental Illness,
>>  Medically Vulnerable Populations (CHAMMP)
>> 325 9th Avenue, 2HH-15
>> Box 359911
>> Seattle, WA 98104
>> http://www.chammp.org
>> (Thurs)
>>
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>
>>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Visualization of coefficients

Achim Zeileis-4
On Wed, 7 Jul 2010, Tal Galili wrote:

> Hi Achim and Allan,I updated the post with Allan's example (thanks Allan).

Thanks!

> Achim, you wrote:
> "Finally, the Poisson model in comparison with the binomial models does not
> make much sense, I guess."
> I agree.  I wanted something to showcase the function on 3 models (with the
> same predictors), and that's the easiest I could think of.  If you'd think
> of a smarter example I'd be happy to incorporate it.

You could generate Poisson data and then fit the binomial model to the
threshold version of the response.

But I guess that would be a bit over the top. Also, one could argue in
that case that a complementary log-log link should be employed.

Hence, I would simply "say" (verbally) that it works for baysglm, glm, lm,
polr objects and that a default method is available which takes
pre-computed coefficients and associated standard errors from any suitable
model.

Best,
Z

> Best,
> Tal
>
>
>
> ----------------Contact
> Details:-------------------------------------------------------
> Contact me: [hidden email] |  972-52-7275845
> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> www.r-statistics.com (English)
> ---------------------------------------------------------------------------
> -------------------
>
>
>
>
> On Wed, Jul 7, 2010 at 12:10 PM, Achim Zeileis <[hidden email]>
> wrote:
>       On Wed, 7 Jul 2010, Tal Galili wrote:
>
>             Hello David,
>             Thanks to your posting I started looking at the
>             function in the arm package.
>              It appears this function is quite mature, and
>             offers (for example) the
>             ability to easily overlap coefficients from several
>             models.
>
>
> Re: more mature. arm's coefplot() is more flexible in certain
> respects, mine is more convenient in others. The overlay functionality
> is something arm's coefplot() is better in and it also as some further
> options (vertical vs. horizontal etc.). My coefplot() has the
> advantage that it does not need any modification as long as coef() and
> vcov() methods are available. Furthermore, "level" can specify the
> significance level (instead of always using one and two standard
> errors, respectively).
> But it shouldn't be too hard to create a superset of all options.
>
>       I updated the post I published on the subject, so at the
>       end of it I give an
>       example of comparing the coef of several models:
> http://www.r-statistics.com/2010/07/visualization-of-regression-coefficient
>
>       s-in-r/
>
>
> As Allan pointed out in his reply, something fully reproducible would
> be nice. Also, if you keep the example with quasi-complete separation,
> it would be worth pointing this out. (Because the maximum likelihood
> estimator is Infinity in this case.)
>
> Finally, the Poisson model in comparison with the binomial models does
> not make much sense, I guess.
>
> Best,
> Z
>
> Thanks again for the pointer.
>
> Best,
> Tal
>
>
>
>
> ----------------Contact
> Details:-------------------------------------------------------
> Contact me: [hidden email] |  972-52-7275845
> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il
> (Hebrew) |
> www.r-statistics.com (English)
> ---------------------------------------------------------------------------
>
> -------------------
>
>
>
>
> On Wed, Jul 7, 2010 at 12:02 AM, David Atkins
> <[hidden email]>
> wrote:
>
>
>      FYI, there is already a function coefplot in the arm
> package;
>      for example, compare:
>
>      > library(arm)
>      Loading required package: MASS
>      Loading required package: Matrix
>      [snip]
>      Attaching package: 'arm'
>
>      The following object(s) are masked from 'package:coda':
>
>         traceplot
>
>      > data("Mroz", package = "car")
>      > fm <- glm(lfp ~ ., data = Mroz, family = binomial)
> > coefplot(fm)
>
> with version below.
>
> cheeres, Dave
>
> >
> > detach("package:arm")
>
> > coefplot <- function(object, df = NULL, level = 0.95, parm =
> NULL,
> +    labels = TRUE, xlab = "Coefficient confidence intervals",
> ylab =
> "",
> +    xlim = NULL, ylim = NULL,
> +    las = 1, lwd = 1, lty = c(1, 2), pch = 19, col = 1,
> +    length = 0, angle = 30, code = 3, ...)
> + {
> +    cf <- coef(object)
> +    se <- sqrt(diag(vcov(object)))
> +    if(is.null(parm)) parm <- seq_along(cf)
> +    if(is.numeric(parm) | is.logical(parm)) parm <-
> names(cf)[parm]
> +    if(is.character(parm)) parm <- which(names(cf) %in% parm)
> +    cf <- cf[parm]
> +    se <- se[parm]
> +    k <- length(cf)
> +
> +    if(is.null(df)) {
> +      df <- if(identical(class(object), "lm"))
> df.residual(object)
> else 0
> +    }
> +
> +    critval <- if(df > 0 & is.finite(df)) {
> +      qt((1 - level)/2, df = df)
> +    } else {
> +      qnorm((1 - level)/2)
> +    }
> +    ci1 <- cf + critval * se
> +    ci2 <- cf - critval * se
> +
> +    lwd <- rep(lwd, length.out = 2)
> +    lty <- rep(lty, length.out = 2)
> +    pch <- rep(pch, length.out = k)
> +    col <- rep(col, length.out = k)
> +
> +    if(is.null(xlim)) xlim <- range(c(0, min(ci1), max(ci2)))
> +    if(is.null(ylim)) ylim <- c(1 - 0.05 * k, 1.05 * k)
> +
> +    if(isTRUE(labels)) labels <- names(cf)
> +    if(identical(labels, FALSE)) labels <- ""
> +    labels <- rep(labels, length.out = k)
> +
> +    plot(0, 0, xlim = xlim, ylim = ylim, xlab = xlab, ylab =
> ylab,
> +      axes = FALSE, type = "n", las = las, ...)
> +    arrows(ci1, 1:k, ci2, 1:k, lty = lty[1], lwd = lwd[1], col
> = col,
> +      length = length, angle = angle, code = code)
> +    points(cf, 1:k, pch = pch, col = col)
> +    abline(v = 0, lty = lty[2], lwd = lwd[2])
> +    axis(1)
> +    axis(2, at = 1:k, labels = labels, las = las)
> +    box()
> + }
> >
> >
> > coefplot(fm, parm = -1)
>
>
>
>
> Achim Zeileis wrote:
>
> I've thought about adding a plot() method for the coeftest()
> function
> in
> the "lmtest" package. Essentially, it relies on a coef() and a
> vcov()
> method being available - and that a central limit theorem holds.
> For
> releasing it as a general function in the package the code is
> still
> too
> raw, but maybe it's useful for someone on the list. Hence, I've
> included
> it below.
>
> An example would be to visualize all coefficients except the
> intercept
> for
> the Mroz data:
>
> data("Mroz", package = "car")
> fm <- glm(lfp ~ ., data = Mroz, family = binomial)
> coefplot(fm, parm = -1)
>
> hth,
> Z
>
> coefplot <- function(object, df = NULL, level = 0.95, parm =
> NULL,
>   labels = TRUE, xlab = "Coefficient confidence intervals", ylab
> = "",
>   xlim = NULL, ylim = NULL,
>   las = 1, lwd = 1, lty = c(1, 2), pch = 19, col = 1,
>   length = 0, angle = 30, code = 3, ...)
> {
>   cf <- coef(object)
>   se <- sqrt(diag(vcov(object)))
>   if(is.null(parm)) parm <- seq_along(cf)
>   if(is.numeric(parm) | is.logical(parm)) parm <-
> names(cf)[parm]
>   if(is.character(parm)) parm <- which(names(cf) %in% parm)
>   cf <- cf[parm]
>   se <- se[parm]
>   k <- length(cf)
>
>   if(is.null(df)) {
>     df <- if(identical(class(object), "lm")) df.residual(object)
> else
> 0
>   }
>
>   critval <- if(df > 0 & is.finite(df)) {
>     qt((1 - level)/2, df = df)
>   } else {
>     qnorm((1 - level)/2)
>   }
>   ci1 <- cf + critval * se
>   ci2 <- cf - critval * se
>
>   lwd <- rep(lwd, length.out = 2)
>   lty <- rep(lty, length.out = 2)
>   pch <- rep(pch, length.out = k)
>   col <- rep(col, length.out = k)
>
>   if(is.null(xlim)) xlim <- range(c(0, min(ci1), max(ci2)))
>   if(is.null(ylim)) ylim <- c(1 - 0.05 * k, 1.05 * k)
>
>   if(isTRUE(labels)) labels <- names(cf)
>   if(identical(labels, FALSE)) labels <- ""
>   labels <- rep(labels, length.out = k)
>
>   plot(0, 0, xlim = xlim, ylim = ylim, xlab = xlab, ylab = ylab,
>     axes = FALSE, type = "n", las = las, ...)
>   arrows(ci1, 1:k, ci2, 1:k, lty = lty[1], lwd = lwd[1], col =
> col,
>     length = length, angle = angle, code = code)
>   points(cf, 1:k, pch = pch, col = col)
>   abline(v = 0, lty = lty[2], lwd = lwd[2])
>   axis(1)
>   axis(2, at = 1:k, labels = labels, las = las)
>   box()
> }
>
>
> On Fri, 2 Jul 2010, Tal Galili wrote:
>
> > Specifically this link:
> >
> http://tables2graphs.com/doku.php?id=04_regression_coefficients
> >
> > Great reference Bernd, thank you.
> >
> > Tal
> >
> >
> > ----------------Contact
> >
> Details:-------------------------------------------------------
> > Contact me: Tal.Galili at gmail.com |  972-52-7275845
> > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il
> (Hebrew) |
> > www.r-statistics.com (English)
> >--------------------------------------------------------------------------
> -
> -------------------
> >
> >
> >
> >
> > On Fri, Jul 2, 2010 at 10:31 AM, Bernd Weiss <bernd.weiss at
> uni-koeln.de>wrote:
> >
> >> Am 02.07.2010 08:10, schrieb Wincent:
> >>> Dear all,
> >>>
> >>> I try to show a subset of coefficients in my presentation.
> It
> seems
> >>> that a "standard" table is not a good way to go. I found
> figure 9
> >>> (page 9) in this file (
> >>>
> >>http://www.destatis.de/jetspeed/portal/cms/Sites/destatis/Internet/DE/Con
> te
> nt/Wissenschaftsforum/Kolloquien/VisualisierungModellierung__Beitrag,proper
>
> ty=file.pdf
> >>>
> >>>
> >> ) looks pretty good. I wonder if there is any function for
> such
> plot?
> >>> Or any suggestion on how to present statistical models in a
> >>> presentation?
> >>
> >> Hi Wincent,
> >>
> >> I guess you are looking for "Using Graphs Instead of Tables
> in
> Political
> >> Science" by Kastellec/Leoni
> <http://tables2graphs.com/doku.php>.
> >>
> >> HTH,
> >>
> >> Bernd
> >>
> >> ______________________________________________
> >> R-help at r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible
> code.
> >>
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible
> code.
> >
>
> --
> Dave Atkins, PhD
> Research Associate Professor
> Department of Psychiatry and Behavioral Science
> University of Washington
> [hidden email]
>
> Center for the Study of Health and Risk Behaviors (CSHRB)      
>      
>  
> 1100 NE 45th Street, Suite 300  
> Seattle, WA  98105      
> 206-616-3879    
> http://depts.washington.edu/cshrb/
> (Mon-Wed)      
>
> Center for Healthcare Improvement, for Addictions, Mental
> Illness,
>  Medically Vulnerable Populations (CHAMMP)
> 325 9th Avenue, 2HH-15
> Box 359911
> Seattle, WA 98104
> http://www.chammp.org
> (Thurs)
>
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible
> code.
>
>
>
>
>
>
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Visualization of coefficients

Tal Galili
I Achim,
I retained the example (so to illustrate the use of the function) - but
pointed out to it's nonsensical nature.
Credit was mentioned to both you and Allan.

Thanks,
Tal

----------------Contact
Details:-------------------------------------------------------
Contact me: [hidden email] |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
----------------------------------------------------------------------------------------------




On Wed, Jul 7, 2010 at 12:31 PM, Achim Zeileis <[hidden email]>wrote:

> On Wed, 7 Jul 2010, Tal Galili wrote:
>
>  Hi Achim and Allan,I updated the post with Allan's example (thanks Allan).
>>
>
> Thanks!
>
>
>  Achim, you wrote:
>> "Finally, the Poisson model in comparison with the binomial models does
>> not
>> make much sense, I guess."
>> I agree.  I wanted something to showcase the function on 3 models (with
>> the
>> same predictors), and that's the easiest I could think of.  If you'd think
>> of a smarter example I'd be happy to incorporate it.
>>
>
> You could generate Poisson data and then fit the binomial model to the
> threshold version of the response.
>
> But I guess that would be a bit over the top. Also, one could argue in that
> case that a complementary log-log link should be employed.
>
> Hence, I would simply "say" (verbally) that it works for baysglm, glm, lm,
> polr objects and that a default method is available which takes pre-computed
> coefficients and associated standard errors from any suitable model.
>
> Best,
>
> Z
>
>  Best,
>> Tal
>>
>>
>>
>> ----------------Contact
>> Details:-------------------------------------------------------
>> Contact me: [hidden email] |  972-52-7275845
>> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
>> www.r-statistics.com (English)
>>
>> ---------------------------------------------------------------------------
>> -------------------
>>
>>
>>
>>
>> On Wed, Jul 7, 2010 at 12:10 PM, Achim Zeileis <[hidden email]>
>> wrote:
>>      On Wed, 7 Jul 2010, Tal Galili wrote:
>>
>>            Hello David,
>>            Thanks to your posting I started looking at the
>>            function in the arm package.
>>             It appears this function is quite mature, and
>>            offers (for example) the
>>            ability to easily overlap coefficients from several
>>            models.
>>
>>
>> Re: more mature. arm's coefplot() is more flexible in certain
>> respects, mine is more convenient in others. The overlay functionality
>> is something arm's coefplot() is better in and it also as some further
>> options (vertical vs. horizontal etc.). My coefplot() has the
>> advantage that it does not need any modification as long as coef() and
>> vcov() methods are available. Furthermore, "level" can specify the
>> significance level (instead of always using one and two standard
>> errors, respectively).
>> But it shouldn't be too hard to create a superset of all options.
>>
>>      I updated the post I published on the subject, so at the
>>      end of it I give an
>>      example of comparing the coef of several models:
>>
>> http://www.r-statistics.com/2010/07/visualization-of-regression-coefficient
>>
>>      s-in-r/
>>
>>
>> As Allan pointed out in his reply, something fully reproducible would
>> be nice. Also, if you keep the example with quasi-complete separation,
>> it would be worth pointing this out. (Because the maximum likelihood
>> estimator is Infinity in this case.)
>>
>> Finally, the Poisson model in comparison with the binomial models does
>> not make much sense, I guess.
>>
>> Best,
>> Z
>>
>> Thanks again for the pointer.
>>
>> Best,
>> Tal
>>
>>
>>
>>
>> ----------------Contact
>> Details:-------------------------------------------------------
>> Contact me: [hidden email] |  972-52-7275845
>> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il
>> (Hebrew) |
>> www.r-statistics.com (English)
>>
>> ---------------------------------------------------------------------------
>>
>> -------------------
>>
>>
>>
>>
>> On Wed, Jul 7, 2010 at 12:02 AM, David Atkins
>> <[hidden email]>
>> wrote:
>>
>>
>>      FYI, there is already a function coefplot in the arm
>> package;
>>      for example, compare:
>>
>>      > library(arm)
>>      Loading required package: MASS
>>      Loading required package: Matrix
>>      [snip]
>>      Attaching package: 'arm'
>>
>>      The following object(s) are masked from 'package:coda':
>>
>>         traceplot
>>
>>      > data("Mroz", package = "car")
>>      > fm <- glm(lfp ~ ., data = Mroz, family = binomial)
>> > coefplot(fm)
>>
>> with version below.
>>
>> cheeres, Dave
>>
>> >
>> > detach("package:arm")
>>
>> > coefplot <- function(object, df = NULL, level = 0.95, parm =
>> NULL,
>> +    labels = TRUE, xlab = "Coefficient confidence intervals",
>> ylab =
>> "",
>> +    xlim = NULL, ylim = NULL,
>> +    las = 1, lwd = 1, lty = c(1, 2), pch = 19, col = 1,
>> +    length = 0, angle = 30, code = 3, ...)
>> + {
>> +    cf <- coef(object)
>> +    se <- sqrt(diag(vcov(object)))
>> +    if(is.null(parm)) parm <- seq_along(cf)
>> +    if(is.numeric(parm) | is.logical(parm)) parm <-
>> names(cf)[parm]
>> +    if(is.character(parm)) parm <- which(names(cf) %in% parm)
>> +    cf <- cf[parm]
>> +    se <- se[parm]
>> +    k <- length(cf)
>> +
>> +    if(is.null(df)) {
>> +      df <- if(identical(class(object), "lm"))
>> df.residual(object)
>> else 0
>> +    }
>> +
>> +    critval <- if(df > 0 & is.finite(df)) {
>> +      qt((1 - level)/2, df = df)
>> +    } else {
>> +      qnorm((1 - level)/2)
>> +    }
>> +    ci1 <- cf + critval * se
>> +    ci2 <- cf - critval * se
>> +
>> +    lwd <- rep(lwd, length.out = 2)
>> +    lty <- rep(lty, length.out = 2)
>> +    pch <- rep(pch, length.out = k)
>> +    col <- rep(col, length.out = k)
>> +
>> +    if(is.null(xlim)) xlim <- range(c(0, min(ci1), max(ci2)))
>> +    if(is.null(ylim)) ylim <- c(1 - 0.05 * k, 1.05 * k)
>> +
>> +    if(isTRUE(labels)) labels <- names(cf)
>> +    if(identical(labels, FALSE)) labels <- ""
>> +    labels <- rep(labels, length.out = k)
>> +
>> +    plot(0, 0, xlim = xlim, ylim = ylim, xlab = xlab, ylab =
>> ylab,
>> +      axes = FALSE, type = "n", las = las, ...)
>> +    arrows(ci1, 1:k, ci2, 1:k, lty = lty[1], lwd = lwd[1], col
>> = col,
>> +      length = length, angle = angle, code = code)
>> +    points(cf, 1:k, pch = pch, col = col)
>> +    abline(v = 0, lty = lty[2], lwd = lwd[2])
>> +    axis(1)
>> +    axis(2, at = 1:k, labels = labels, las = las)
>> +    box()
>> + }
>> >
>> >
>> > coefplot(fm, parm = -1)
>>
>>
>>
>>
>> Achim Zeileis wrote:
>>
>> I've thought about adding a plot() method for the coeftest()
>> function
>> in
>> the "lmtest" package. Essentially, it relies on a coef() and a
>> vcov()
>> method being available - and that a central limit theorem holds.
>> For
>> releasing it as a general function in the package the code is
>> still
>> too
>> raw, but maybe it's useful for someone on the list. Hence, I've
>> included
>> it below.
>>
>> An example would be to visualize all coefficients except the
>> intercept
>> for
>> the Mroz data:
>>
>> data("Mroz", package = "car")
>> fm <- glm(lfp ~ ., data = Mroz, family = binomial)
>> coefplot(fm, parm = -1)
>>
>> hth,
>> Z
>>
>> coefplot <- function(object, df = NULL, level = 0.95, parm =
>> NULL,
>>   labels = TRUE, xlab = "Coefficient confidence intervals", ylab
>> = "",
>>   xlim = NULL, ylim = NULL,
>>   las = 1, lwd = 1, lty = c(1, 2), pch = 19, col = 1,
>>   length = 0, angle = 30, code = 3, ...)
>> {
>>   cf <- coef(object)
>>   se <- sqrt(diag(vcov(object)))
>>   if(is.null(parm)) parm <- seq_along(cf)
>>   if(is.numeric(parm) | is.logical(parm)) parm <-
>> names(cf)[parm]
>>   if(is.character(parm)) parm <- which(names(cf) %in% parm)
>>   cf <- cf[parm]
>>   se <- se[parm]
>>   k <- length(cf)
>>
>>   if(is.null(df)) {
>>     df <- if(identical(class(object), "lm")) df.residual(object)
>> else
>> 0
>>   }
>>
>>   critval <- if(df > 0 & is.finite(df)) {
>>     qt((1 - level)/2, df = df)
>>   } else {
>>     qnorm((1 - level)/2)
>>   }
>>   ci1 <- cf + critval * se
>>   ci2 <- cf - critval * se
>>
>>   lwd <- rep(lwd, length.out = 2)
>>   lty <- rep(lty, length.out = 2)
>>   pch <- rep(pch, length.out = k)
>>   col <- rep(col, length.out = k)
>>
>>   if(is.null(xlim)) xlim <- range(c(0, min(ci1), max(ci2)))
>>   if(is.null(ylim)) ylim <- c(1 - 0.05 * k, 1.05 * k)
>>
>>   if(isTRUE(labels)) labels <- names(cf)
>>   if(identical(labels, FALSE)) labels <- ""
>>   labels <- rep(labels, length.out = k)
>>
>>   plot(0, 0, xlim = xlim, ylim = ylim, xlab = xlab, ylab = ylab,
>>     axes = FALSE, type = "n", las = las, ...)
>>   arrows(ci1, 1:k, ci2, 1:k, lty = lty[1], lwd = lwd[1], col =
>> col,
>>     length = length, angle = angle, code = code)
>>   points(cf, 1:k, pch = pch, col = col)
>>   abline(v = 0, lty = lty[2], lwd = lwd[2])
>>   axis(1)
>>   axis(2, at = 1:k, labels = labels, las = las)
>>   box()
>> }
>>
>>
>> On Fri, 2 Jul 2010, Tal Galili wrote:
>>
>> > Specifically this link:
>> >
>> http://tables2graphs.com/doku.php?id=04_regression_coefficients
>> >
>> > Great reference Bernd, thank you.
>> >
>> > Tal
>> >
>> >
>> > ----------------Contact
>> >
>> Details:-------------------------------------------------------
>> > Contact me: Tal.Galili at gmail.com |  972-52-7275845
>> > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il
>> (Hebrew) |
>> > www.r-statistics.com (English)
>>
>> >--------------------------------------------------------------------------
>> -
>> -------------------
>> >
>> >
>> >
>> >
>> > On Fri, Jul 2, 2010 at 10:31 AM, Bernd Weiss <bernd.weiss at
>> uni-koeln.de>wrote:
>> >
>> >> Am 02.07.2010 08:10, schrieb Wincent:
>> >>> Dear all,
>> >>>
>> >>> I try to show a subset of coefficients in my presentation.
>> It
>> seems
>> >>> that a "standard" table is not a good way to go. I found
>> figure 9
>> >>> (page 9) in this file (
>> >>>
>> >>
>> http://www.destatis.de/jetspeed/portal/cms/Sites/destatis/Internet/DE/Con
>> te
>>
>> nt/Wissenschaftsforum/Kolloquien/VisualisierungModellierung__Beitrag,proper
>>
>> ty=file.pdf
>> >>>
>> >>>
>> >> ) looks pretty good. I wonder if there is any function for
>> such
>> plot?
>> >>> Or any suggestion on how to present statistical models in a
>> >>> presentation?
>> >>
>> >> Hi Wincent,
>> >>
>> >> I guess you are looking for "Using Graphs Instead of Tables
>> in
>> Political
>> >> Science" by Kastellec/Leoni
>> <http://tables2graphs.com/doku.php>.
>> >>
>> >> HTH,
>> >>
>> >> Bernd
>> >>
>> >> ______________________________________________
>> >> R-help at r-project.org mailing list
>> >> https://stat.ethz.ch/mailman/listinfo/r-help
>> >> PLEASE do read the posting guide
>> >> http://www.R-project.org/posting-guide.html
>> >> and provide commented, minimal, self-contained, reproducible
>> code.
>> >>
>> >
>> >       [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > R-help at r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible
>> code.
>> >
>>
>> --
>> Dave Atkins, PhD
>> Research Associate Professor
>> Department of Psychiatry and Behavioral Science
>> University of Washington
>> [hidden email]
>>
>> Center for the Study of Health and Risk Behaviors (CSHRB)
>>
>>
>> 1100 NE 45th Street, Suite 300
>> Seattle, WA  98105
>> 206-616-3879
>> http://depts.washington.edu/cshrb/
>> (Mon-Wed)
>>
>> Center for Healthcare Improvement, for Addictions, Mental
>> Illness,
>>  Medically Vulnerable Populations (CHAMMP)
>> 325 9th Avenue, 2HH-15
>> Box 359911
>> Seattle, WA 98104
>> http://www.chammp.org
>> (Thurs)
>>
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible
>> code.
>>
>>
>>
>>
>>
>>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Visualization of coefficients

Michael Friendly
In reply to this post by Tal Galili
Tal Galili wrote:

> Hello David,
> Thanks to your posting I started looking at the function in the arm package.
>  It appears this function is quite mature, and offers (for example) the
> ability to easily overlap coefficients from several models.
>
> I updated the post I published on the subject, so at the end of it I give an
> example of comparing the coef of several models:
> http://www.r-statistics.com/2010/07/visualization-of-regression-coefficients-in-r/
>
> Thanks again for the pointer.
>
> Best,
> Tal

Achim Zeileis wrote:
> Re: more mature. arm's coefplot() is more flexible in certain respects, mine is more convenient in others. The overlay functionality is something arm's coefplot() is better in and it also as some further options (vertical vs. horizontal etc.). My coefplot() has the advantage that it does not need any modification as long as coef() and vcov() methods are available. Furthermore, "level" can specify the significance level (instead of always using one and two standard errors, respectively).
> But it shouldn't be too hard to create a superset of all options.


@Tal:
For the example using library(arm) and the Mroz data, you posted the
wrong image.  And loose the intercept in the example.

@Achim:
It would be worthwhile combining the generality of your version with the
overlay capability of the arm version, which is extremely useful for
model comparison.  However, the arm version uses S4 methods.

-Michael


--
Michael Friendly     Email: friendly AT yorku DOT ca
Professor, Psychology Dept.
York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street    Web:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Visualization of coefficients

Tal Galili
Thanks Michael - I now inserted the correct image for Achim example code.


----------------Contact
Details:-------------------------------------------------------
Contact me: [hidden email] |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
----------------------------------------------------------------------------------------------




On Wed, Jul 7, 2010 at 5:19 PM, Michael Friendly <[hidden email]> wrote:

> Tal Galili wrote:
>
>> Hello David,
>> Thanks to your posting I started looking at the function in the arm
>> package.
>>  It appears this function is quite mature, and offers (for example) the
>> ability to easily overlap coefficients from several models.
>>
>> I updated the post I published on the subject, so at the end of it I give
>> an
>> example of comparing the coef of several models:
>>
>> http://www.r-statistics.com/2010/07/visualization-of-regression-coefficients-in-r/
>>
>> Thanks again for the pointer.
>>
>> Best,
>> Tal
>>
>
> Achim Zeileis wrote:
>
>> Re: more mature. arm's coefplot() is more flexible in certain respects,
>> mine is more convenient in others. The overlay functionality is something
>> arm's coefplot() is better in and it also as some further options (vertical
>> vs. horizontal etc.). My coefplot() has the advantage that it does not need
>> any modification as long as coef() and vcov() methods are available.
>> Furthermore, "level" can specify the significance level (instead of always
>> using one and two standard errors, respectively).
>> But it shouldn't be too hard to create a superset of all options.
>>
>
>
> @Tal:
> For the example using library(arm) and the Mroz data, you posted the wrong
> image.  And loose the intercept in the example.
>
> @Achim:
> It would be worthwhile combining the generality of your version with the
> overlay capability of the arm version, which is extremely useful for model
> comparison.  However, the arm version uses S4 methods.
>
> -Michael
>
>
> --
> Michael Friendly     Email: friendly AT yorku DOT ca
> Professor, Psychology Dept.
> York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
> 4700 Keele Street    Web:   http://www.datavis.ca
> Toronto, ONT  M3J 1P3 CANADA
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Visualization of coefficients

David Winsemius
In reply to this post by Michael Friendly

On Jul 7, 2010, at 10:19 AM, Michael Friendly wrote:

> Tal Galili wrote:
>> Hello David,
>> Thanks to your posting I started looking at the function in the arm  
>> package.
>> It appears this function is quite mature, and offers (for example)  
>> the
>> ability to easily overlap coefficients from several models.
>> I updated the post I published on the subject, so at the end of it  
>> I give an
>> example of comparing the coef of several models:
>> http://www.r-statistics.com/2010/07/visualization-of-regression-coefficients-in-r/
>> Thanks again for the pointer.
>> Best,
>> Tal
>
> Achim Zeileis wrote:
>> Re: more mature. arm's coefplot() is more flexible in certain  
>> respects, mine is more convenient in others. The overlay  
>> functionality is something arm's coefplot() is better in and it  
>> also as some further options (vertical vs. horizontal etc.). My  
>> coefplot() has the advantage that it does not need any modification  
>> as long as coef() and vcov() methods are available. Furthermore,  
>> "level" can specify the significance level (instead of always using  
>> one and two standard errors, respectively).
>> But it shouldn't be too hard to create a superset of all options.
>
>
> @Tal:
> For the example using library(arm) and the Mroz data, you posted the  
> wrong image.  And loose the intercept in the example.
>
> @Achim:
> It would be worthwhile combining the generality of your version with  
> the
> overlay capability of the arm version, which is extremely useful for  
> model comparison.  However, the arm version uses S4 methods.

To my reading coefplot <somehow> collects parameters from a list of  
model objects using S4 methods, but then passes these to  
coefplot.default which uses base graphics. There seems to be an  
implicit loop, ... perhaps some sort of S4 magic? ... that accumulates  
like-named coefficients in a .local(...) (function?) object until they  
all get reduced to class "numeric", at which point they are passed to  
coefplot.default() which does not appear to be an S4 method.

(I am not particularly knowledgeable about S4 functions and  
dispatching, so any corrections or applifications to this account  
would be welcome.)

--
David.


>
> -Michael
>
>
> --
> Michael Friendly     Email: friendly AT yorku DOT ca
> Professor, Psychology Dept.
> York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
> 4700 Keele Street    Web:   http://www.datavis.ca
> Toronto, ONT  M3J 1P3 CANADA
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Visualization of coefficients

Achim Zeileis-4
In reply to this post by Michael Friendly
On Wed, 7 Jul 2010, Michael Friendly wrote:

> Tal Galili wrote:
>> Hello David,
>> Thanks to your posting I started looking at the function in the arm
>> package.
>>  It appears this function is quite mature, and offers (for example) the
>> ability to easily overlap coefficients from several models.
>>
>> I updated the post I published on the subject, so at the end of it I give
>> an
>> example of comparing the coef of several models:
>> http://www.r-statistics.com/2010/07/visualization-of-regression-coefficients-in-r/
>>
>> Thanks again for the pointer.
>>
>> Best,
>> Tal
>
> Achim Zeileis wrote:
>> Re: more mature. arm's coefplot() is more flexible in certain respects,
>> mine is more convenient in others. The overlay functionality is something
>> arm's coefplot() is better in and it also as some further options (vertical
>> vs. horizontal etc.). My coefplot() has the advantage that it does not need
>> any modification as long as coef() and vcov() methods are available.
>> Furthermore, "level" can specify the significance level (instead of always
>> using one and two standard errors, respectively).
>> But it shouldn't be too hard to create a superset of all options.
>
>
> @Tal:
> For the example using library(arm) and the Mroz data, you posted the wrong
> image.  And loose the intercept in the example.
>
> @Achim:
> It would be worthwhile combining the generality of your version with the
> overlay capability of the arm version, which is extremely useful for model
> comparison.

Yes, that's what Thomas Lumley already suggested as well.

> However, the arm version uses S4 methods.

Yes. If I do get round to fully implement this, I would take the same
approach as with the coeftest() function. That is: Having a default method
that typically works out of the box, and a thin layer of S3 methods, in
case it needs adaption. The latter is necessary for example for "multinom"
objects where the coef() method returns a matrix whose elements need to be
matched to the elements of the matrix returned by vcov().

Best,
Z

> -Michael
>
>
> --
> Michael Friendly     Email: friendly AT yorku DOT ca
> Professor, Psychology Dept.
> York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
> 4700 Keele Street    Web:   http://www.datavis.ca
> Toronto, ONT  M3J 1P3 CANADA
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.