Hatena::ブログ(Diary)

Triad sou. このページをアンテナに追加 RSSフィード Twitter

2013-01-24 RcmdrPlugin.KMggplot2_0.2-0 is on CRAN now

RcmdrPlugin.KMggplot2_0.2-0 is on CRAN now

I posted a new version of the "RcmdrPlugin.KMggplot2" package, which is an Rcmdr plug-in for a "ggplot2" GUI front-end.

This package assists you to make "ggplot2" graphics.


NEWS

Changes in version 0.2-0 (2013-01-23)
  • Added themes: classic, minimal (ggplot2-0.9.3).
  • Added themes: tufte, economist, solarized, stata, excel, igray, few, wsj (ggthemes).
  • Kaplan-Meier plot: added a option to show a p-value of the log-rank test (Thanks to Sharma Vivek).
  • Kaplan-Meier plot: added a option to draw a line at median survival (Thanks to Sharma Vivek).
  • Scatter plot matrix: fixed bugs and reimplemented, because the ggplot2::plotmatrix() is deprecated.
  • Scatter plot matrix: added stratified plots.
  • Modified start-up for the problem that Commander window open twice when a plug-in is loaded via library() (see Rcmdr 1.9-3 NEWS). In RcmdrPlugin.KMggplot2 0.2-0, you can directly load by library(RcmdrPlugin.KMggplot2).

themes
  • theme_classic (ggplot2)

f:id:triadsou:20130124110741p:image

  • theme_minimal (ggplot2)

f:id:triadsou:20130124110748p:image

  • theme_tufte (ggthemes)

f:id:triadsou:20130124110751p:image

  • theme_economist (ggthemes)

f:id:triadsou:20130124110742p:image

  • theme_solarized (ggthemes)

f:id:triadsou:20130124110749p:image

  • theme_stata (ggthemes)

f:id:triadsou:20130124110750p:image

  • theme_excel (ggthemes)

f:id:triadsou:20130124110743p:image

  • theme_igray (ggthemes)

f:id:triadsou:20130124110745p:image

  • theme_few (ggthemes)

f:id:triadsou:20130124110744p:image

  • theme_wsj (ggthemes)

f:id:triadsou:20130124110753p:image


Kaplan-Meier plot: log-rank p-value and lines at median survival

f:id:triadsou:20130124110746p:image


Scatter plot matrix: stratified plots

f:id:triadsou:20130124110747p:image


Related Posts

2012-12-22 Firefox のタブが接続中のままになるエラー

Firefox のタブが接続中のままになるエラー

エラー: ReferenceError: oldSetTabTitle is not defined
ソースファイル: chrome://tabmixplus/content/utils.js
行: 347

こんなエラーがでてタブの名前が全部接続中に・・・

Tab Mix Plus をオフにするとなおるけどどうしたもんか。



アドオンのソースを調べると IE Tab 2 と干渉していたらしい事が分かった。

IE Tab 2 の方はあまり使わないので切っておくことにしたら無事解決した。

IE Tab 2 修正版 (4.12.22.2) にアップデートしてもなおるみたいです。


エラーが起きた環境

2012-11-22 Time-dependent (varying) covariate / effect

Time-dependent (varying) covariate / Time-dependent (varying) effect

比例ハザードモデルとその拡張のちょっとしたメモ。

  • 色々調べると、time-dependent と time-varying は特に区別していない文献ばかりだった
  • 当然 covariate と effect では意味が違うので注意
    • Proportional hazard
    • Time-dependent covariate
    • Time-dependent effect
    • Time-dependent covariate + effect

2012-09-26 Recoding a factor variable in a data.frame by the levels() funct

Recoding a factor variable in a data.frame by the levels() function

When you want to change the coding of a factor variable in R, you can use the levels() function.

Recoding z as 1 = A, 2-6 = B, 7 = C

d <- data.frame(z = gl(7, 1, 14))
d$zc <- factor(d$z)
levels(d$zc) <- list(A = 1, B = 2:6, C = 7)
d
Result
> levels(d$zc) <- list(A = 1, B = 2:6, C = 7)
> d
   z zc
1  1  A
2  2  B
3  3  B
4  4  B
5  5  B
6  6  B
7  7  C
8  1  A
9  2  B
10 3  B
11 4  B
12 5  B
13 6  B
14 7  C

Recoding z as 1 = "1", 2-6 = "2-6", 7 = "7"

levels(d$zc) <- list("1" = 1, "2-6" = 2:6, "7" = 7)
d
Result
> levels(d$zc) <- list("1" = 1, "2-6" = 2:6, "7" = 7)
> d
   z  zc
1  1   1
2  2 2-6
3  3 2-6
4  4 2-6
5  5 2-6
6  6 2-6
7  7   7
8  1   1
9  2 2-6
10 3 2-6
11 4 2-6
12 5 2-6
13 6 2-6
14 7   7

2012-09-01 Penalized quasi-likelihood

Penalized quasi-likelihood について

GLMM の推定アルゴリズムに Penalized quasi-likelihood (PQL) という方法があるのですが、整理のためメモを書くことにしました。


PQL

混合効果モデルのパラメータ推定において、周辺尤度の積分を必要とする方法があることはよく知られていると思います。

GLMM ではリンク関数が非線形なものを扱うが故に、この積分が非常に大変でした (現代の計算機では苦労せず解けるものも多い)。

一昔前はこの積分が大変だったため、非線形な関数を線形な関数に近似してあげて、LMM の範疇で扱えるようにした方法が PQL です。


GLMM として、確率変数 の期待値が、変量効果 を与えた下で、


  


とモデル化された一般的なものを考えます (, はデザイン行列、 は固定効果のパラメータベクトル、 はリンク関数の逆関数)。


PQL では の関数である に対して , の周りの一次の Taylor 展開、


  


を考えます、ただし、


  


とします ( 次元行列)。


これを整理すると、


  


が得られます。

左辺をよく見ると、これは、 の期待値になっていることが分かります。確率変数 以外は全て定数なので、新しい作業確率変数 を定義しています。

また、同じく 以外が全て定数なので、 が簡単に分かります。

そして、右辺からは非線形なリンク関数がうまく消去できていて、線形化することができました。


以上の近似を使って、LMM、


  


を当てはめたものが、PQL と呼ばれる方法です。


また、類似の Marginal quasi-likelihood (MQL) という方法では、変量効果の方を母集団平均で置き換えるため、 を用います。

ただし、MQL は変量効果が非常に小さい場合でないとうまくいかないことが知られています。


また、アウトカムが二項分布に従う場合は、PQL と MQL による近似は特にうまくいかないケースがあることが知られています。


感想

とまあ、一次の Taylor 展開を使ったシンプルな方法だという事が分かります。

計算は早くなりますが、デメリットもあるでしょう。

作業確率変数 に置き換えるため、 に基づく正しい尤度が定義できない事はデメリットの一つでしょう。

どこかに quasi-likelihood だから良くないと書いてあった気がしますが、そういう事ではなさそうですね (結局 LMM で計算しているし・・・)。

本質的な部分は作業確率変数を使った近似に関係していると思われます。


よって、利用可能であれば、適応型ガウス–エルミート求積法などの周辺尤度を直接計算するような方法が望ましいでしょう。


ちなみに SAS 9.3 の GLIMMIX Procedure は METHOD = RSPL (PQL で REML 推定) がデフォルトです。


参考文献

[1] Breslow N. Whither PQL? UW Biostatistics Working Paper Series. Working Paper 192. http://biostats.bepress.com/uwbiostat/paper192