Triad sou.

Penalized quasi-likelihood について

GLMM の推定アルゴリズムに Penalized quasi-likelihood (PQL) という方法があるのですが、整理のためメモを書くことにしました。 PQL 混合効果モデルのパラメータ推定において、周辺尤度の積分を必要とする方法があることはよく知られていると思います。 GL…

Log-gamma distribution

A log-gamma random variable, $Y$, is defined as, \[ Y=\exp(-X) \] where $X \in [0, \infty)$ follows a gamma distribution, and $Y \in (0, 1]$. The probability density function of the log-gamma distribution is \[ f_Y(y)=\frac{b^a\left\{\log(…

Java Compiler API を使って何かしてみよう

Java のバイナリから Java ソースコードをコンパイルするための API を使って、String 型の文字列をコンパイルし、クラスから static なメソッドを呼んで値を返す方法を模索していました。 以下のプログラムと解説を参考にしています Compiling from Memory …

R Commander による Kaplan-Meier プロットの作図手順

R

R のインストール バージョン 2.15.0 以上の R をインストールします。ソフトウェアのインストールをした経験がある方なら特に困ることはないでしょう。 Windows の場合 Download R-3.2.3 for Windows. The R-project for statistical computing. Mac の場合…

記号微分

R

deriv を利用して、R で記号微分してみます。 正規分布の対数尤度関数を記号微分してみよう 正規分布の対数尤度関数は、 \[ l(\mu, \s; x)=-\frac{\log(2\pi\s^2)}{2}-\frac{(x - \mu)^2}{2\s^2} \] ですので、これを偏微分すると、 \[ \begin{align*} \frac…

RcmdrPlugin.KMggplot2_0.1-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. RcmdrPlugin.KMggplot2 (CRAN) NEWS Changes in version 0.1-0 (2012-0…

"..count.. + facet_grid" の挙動について

追記 ggplot-0.9.1 で修正されていました! ggplot-0.9.1 での実行結果 メモ スクリプトの書き方が良くないのかもしれませんが、..count.. と facet_gridを併用したときの挙動をメモっておきます。 バージョンは R-2.15.0 + ggplot-0.9.0 です。 こう書くと…

行列のスカラー微分のメモ

$\mathbf{A}$, $\mathbf{B}$ について、スカラー $\theta$ で微分する場合を考える。 だたし、 \[ \mathbf{A}= \left\{ a_{ij} \right\}, \frac{\partial \mathbf{A}}{\partial \theta}= \left\{ \frac{\partial a_{ij}}{\partial \theta} \right\} \] とし…

色の反転

public Color invertColor(Color color) { return new Color( 255 - color.getRed(), 255 - color.getGreen(), 255 - color.getBlue() ); } サンプル

ちらつかない JEditorPane クラス の setText メソッド

JEditorPane クラス の setText メソッドは public void setText(String t) { try { Document doc = getDocument(); doc.remove(0, doc.getLength()); if (t == null || t.equals("")) { return; } Reader r = new StringReader(t); EditorKit kit = getEdit…

New 'ByteCompile' field in the DESCRIPTION file

R

R 2.14.0 から DESCRIPTION ファイルに 'ByteCompile' フィールドを指定できるようになったらしい。 パッケージ中の R コードを自動的にバイトコンパイルしてくれるため、ものによっては高速化が見込めるという感じ。 試してみようかな。 The `ByteCompile' …

JTextArea to JTable / JTable to JTextArea

Java Swing でテキストエリア テーブルの例を作ってみました。 csv っぽい形式で JTextArea 入力されているデータを JTable に読み込んだり、JTable のデータを csv っぽい形式に掃き出す事ができます。 ポイント 最初に作成した JTable クラス型のオブジェ…

任意の底の対数

SAS

proc fcmp outlib = sasuser.funcs.logbase; function logbase(x, base); return (log(x) / log(base)); endsub; run; options cmplib = sasuser.funcs; data test; a = logbase(48, 7); b = logbase(49, 7); proc print; run;OBS a b 1 1.98940 2

一般化線型モデルの復習

仮定 確率分布 確率変数 $Y_i$ が互いに独立に canonical form の指数型分布族、 \[ f_{Y_i}(y_i)=\exp\left\{ [y_i \theta_i - b(\theta_i)] / \phi^2 - c(y_i, \phi) \right\}, \] に従う事を仮定する ($Y_i \overset{\rm{i.i.d.}}{\sim} f_{Y_i}(y_i)$)。…

set end; データステップで最後のオブザベーションのみ出力する方法

SAS

これは覚えておくとお得かもしれません。 set data; by variable; if last.variable then output; の仲間ですね。 data sample; input x y z @@; cards; 1 2 3 4 5 6 7 8 9 ; data sample_final; retain xx xy xz yy yz zz 0; set sample end = final; xx = …

Reference class に roxygen2 用のコメントを入れる方法

R

先日 Reference class に roxygen 用のコメントを入れる方法 という記事を書いたのですが、実は全然ドキュメントを作れていなかったことに今更気づいたので、せっかくなので roxygen2 用の場合を作ってみました。 基本的には変わっていませんが、@section で…

箱ひげ図に横棒を追加する

以下のようにすると簡単に横棒付きの箱ヒゲ図を作成できます。 require("ggplot2") df <- data.frame( x = rep(1:5, each = 50), y = rt(2500, 3) ) ggplot(df, aes(x = factor(x), y = y)) + stat_boxplot(geom = "errorbar", stat_params = list(width = 0…

Rcmd Rd2dvi が失敗する

R TeX

Rcmd Rd2dvi で PDF マニュアルを作成することがあるのですが、いつの間にか失敗してしまうようになっていて困っていました。 しかし、単に Rcmd Rd2dvi の実行には MikTeX が必要 (推奨) だったようで、インストールすると問題無く PDF マニュアルを作れる…

コピペでデータ読み込み

R

R で Excel などに入力されたちょっとしたデータを読み込む時、データ整形に結構手間がかかってめんどくさいと思っていましたが、 How to read space delimited data into a data frame from your script/document file? (Stack Overflow) ではコピペだけで…

Error in including pdf figures with \includegraphics; no BoundingBox!

TeX

最近 TeX で文章を書いていて、pdf で作成したグラフを読み込もうとしたところ、bb ファイルをちゃんと作成してたはずが、 LaTeX Error: Cannot determine size of graphic in fig2.5.pdf (no BoundingBox). というエラーに見舞われました。 いろいろと試行…

Reference class に roxygen 用のコメントを入れる方法

R

お詫び 下記の内容は不十分だったため、roxygen2 について記事を書きました。 Reference class に roxygen2 用のコメントを入れる方法 内容 Reference class を用いたパッケージの R スクリプトに roxygen 用のコメントを入れる方法を模索してみました。 S4 …

Reference class の initialize メソッドについて

R

initialize メソッドの挙動 を調べていたら、R devel の ML (Ref Classes: bug with using '.self' within initialize methods?) と TractoR というパッケージのコードを見つけ、これを参考に uninitializedField に初期値を与えてみるコードを書きました。 …

About the RcmdrPlugin.KMggplot2

I aim to make a brief version of a ggplot2 GUI-frontend "with Japanese translation (I am Japanese)." I think that the Deducer and the yeroon.net/ggplot2 is pretty good software. Currently, I'm trying to find bugs and to restructure impleme…

RcmdrPlugin.KMggplot2 について

日本語化済みの ggplot2 用の GUI フロントエンドはたぶん無いと思うので、簡易版ですがパッケージを作ってみました。 Deducer や yeroon.net/ggplot2 の様に、もっとしっかりとした良いソフトもありますので、そちらもお試しください。 しばらくはバグ探し…

RcmdrPlugin.KMggplot2_0.0-3 is on CRAN now

RcmdrPlugin.KMggplot2 (CRAN) I posted an Rcmdr plug-in for a "ggplot2" GUI front-end on CRAN. This version supports Kaplan-Meier plot and other plots as follow: Kaplan-Meier plot Show no. at risk on inside Show no. at risk table on outside…

An alternative of the base:setdiff(x, y) for list objects

Using the base::unique(x), the base::setdiff(x, y) has the same problem as follow: > unique(list(a=1,b=2,c=3,a=1)) [[1]] [1] 1 [[2]] [1] 2 [[3]] [1] 3 So, I wrote an alternative of the base::setdiff(x, y) function, too. lsetdiff <- functio…

An alternative of the base:unique(x) for list objects

The base::unique(x) function returns a vector, data frame or array that were removed duplicate elements/rows. When the x is a list object, the base::unique(x) returns an unnamed list object as follow: > unique(list(a=1,b=2,c=3,a=1)) [[1]] …

リストを ... (dot-dot-dot) 引数に変換して関数を実行する方法

R

tkgrid にリストを投げるとエラーを頂戴するので、足掻いてみました。 この場合は単に do.call で OK、勉強不足でした。 require(tcltk) tt <- tktoplevel() b1 <- tkbutton(tt, text = "OK 1", command = function() tkdestroy(tt)) b2 <- tkbutton(tt, tex…

R の model.frame オブジェクトについて

R

model.frame オブジェクト model.frame オブジェクトは、R でデータとモデル式を統一的に扱うためのオブジェクトです。 実体は data.frame クラスのデータに、モデル式を含むいろいろな attributes が付加されたものです。 d <- e <- rep(1, 10) c <- 1:10 b …

コメント化・コメント解除のショートカット

SAS

小ネタ Windows 版 SAS の Enhanced Editor では、文字列を選択し "Ctrl + ?" を押すと 選択範囲をコメント化できる。 "Ctrl + Shift + ?" を押すと 選択範囲のコメントを解除できる。