How to do Topological FDR

Many ask “how to do Topological FDR” in SPM ML. Below are the posts I found useful.

Originally Guillaume Flandin showed how to do that.
https://www.jiscmail.ac.uk/cgi-bin/webadmin?A2=SPM;44838216.0904

The height threshold you define during the Results procedure is the feature-inducing threshold (used to define local maxima and clusters).
For topological FDR, I would typically choose “none” and a small T-value, for example 3.
The MIP will display all voxels whose T-value is above 3 and the Results table will display all local maxima whose T-value is above 3 (actually, at most 3 local maxima per cluster, more than 8mm apart) and the corresponding FWE p-values and FDR q-values for peaks and clusters.

If you want to threshold the MIP to a particular significance level, go through the Results procedure again and enter the corresponding height and extent thresholds (the 0.05 critical thresholds are indicated at the bottom left of the Results table):
(height) FWEp and FDRp for peak-FWE and -FDR.
(extent) FWEc amd FDRc for cluster-FWE and -FDR.

Jonathan Peele also gave a detail instruction of how to do that. This time he focused more on cluster-thresholded FDR.
https://www.jiscmail.ac.uk/cgi-bin/webadmin?A2=SPM;6f4e0139.1110

> How can I see images with a threshold at the cluster-level instead of the peak level with the graphical user interface?

I’m not aware of a way to set a cluster-level threshold when running results the first time (i.e., “show everything that is cluster-level corrected p < .05").  What I would do is this: 1) Run results using some voxelwise threshold.  This threshold defines your clusters, and it's fine to use an uncorrected threshold (e.g., p< .001, uncorrected). 2) In the results table, for each cluster you will see the cluster extent (i.e. how many voxels) and the cluster-corrected p value.  In SPM8 you will see 2 cluster-corrected p values, one for topological FDR (Chumbley & Friston, 2009), one for random field theory (labeled FWE).  You can then look at the size of those clusters, and figure out the cluster extent  that divides p < .05 from the others.  For example, if a cluster of 300 voxels is p = .10, and a cluster of 400 voxels is p = .04, then you know that any cluster 400 voxels or larger would be p < .05. 3) Re-run the results, selecting the same voxelwise threshold. But now, in the minimum cluster extent, specify the cluster size you just figured out—in the above example, you could specify 400.

4) Now all of the displayed results should be cluster-level corrected.

5) If you want to save this thresholded image for displaying with another program, just click the “save” button, and you can write out a thresholded t map as a nifti file.

In practice this is actually fairly quick to do once you’ve done it a couple of times.

Note the difference between these two. Two-step approach is the same, but Guillaume’s way deals with peak and cluster threshold and Jonathan’s way deals with cluster threshold.

Lin4NeuroをUSBメモリから起動する方法

普段Windowsを使っているけれども、Linuxを使ってみたい。そんな人はある程度いると思います。特に、画像解析をする人は特にそうかもしれません。
そんなとき、3つのオプションがあります。

  1. WindowsにVMware playerやVirtualboxなどの仮想化ソフトをインストールし、その中にLinuxをインストールする。
  2. これはなかなか便利です。私も普段、これで仕事をしています。Lin4Neuroの開発はVMware上で行なっています。何度も試行錯誤がきくからです。具体的な方法はこちらに記載しましたので、そちらを御覧ください。

  3. USBメモリにインストール
  4. これが今から示す方法です。これが便利なのは、自分のPCでなく、手元に転がっているPCで同じ環境を再現できるということです。もしくは、チュートリアルなどで人に何かを伝えたい場合に、自分で環境を準備しておいて、USBメモリを準備することで他の人が全く同一の環境を再現することができます。

  5. Macに乗り換える
  6. Mac OSXはBSDベースで、Bシェルが普通に走ります。これは結構便利で、最近、Macに乗り換えようかどうか真剣に考えています。でも、一つのことに傾倒しすぎるのはどうかなとも思っているので、MacBookProを持ってはいますが、まだメインマシンとはなっていません…。

LinuxをUSBメモリにインストールする方法は知っておくと何かと役に立つことがあります。Windowsのファイルが壊れてしまい、Windowsが立ち上がらなくなった時、LinuxブートのUSBメモリを持っておけば、それから起動してPCから多くのファイルを救出することができます。なので、Lin4Neuroに限ったことではないのですが、便利なのでその起動方法をPDFドキュメントにまとめてみました。下のリンクからどうぞ。

Lin4Neuro_USB.pdfをダウンロード

VMware player上でのLin4Neuroの使い方

画像解析に特化したカスタマイズOSのLin4Neuro。一定の需要があるようで、便利という声をいただいております。
画像解析のためだけにWindowsからLinuxに乗り換えることを躊躇している人も多いと思います。正直、私も画像解析のメインマシンはLinuxですが、日頃の雑多な仕事はまだWindows上で行なっています。Linuxは基本いいのですが、つまずいたときにすぐにトラブルシューティングできるだけの能力がまだないからです。

64bitでメモリもたくさんのっかる世の中、仮想環境がずいぶん充実してきました。Lin4Neuroも仮想環境でけっこういい感じで動きます。めちゃくちゃメモリを使う仕事でなければ、ノートPCに8GBのメモリを載せ、そのうち4GBを仮想に割り当ててそこでLin4Neuroを走らせれば、けっこういい感じで解析ができます。

ということで、VMware player(無償で入手できます)上でのLin4Neuroの動かし方をPDFドキュメントにしてみました。必要な方はダウンロードしてください。

Lin4Neuro_VMwareのダウンロード

Voxel-wise FDR and Topological FDR

In SPM8, voxel-wise FDR was hidden and Topological FDR was introduced. What is Topological FDR? I find some useful notes from SPM8 Release Notes and a post by Tom Nichols to SPM-ML. I quote these two.

SPM8 Release Notes

Topological False Discovery Rate (FDR)

FDR control is an alternative to the more conservative “family-wise error” control for multiple comparisons. Historically, SPM has aimed to control FDR on voxels (the
expected fraction of false-positive/total-positive decisions made about individual voxels in an image). This is now superseded by FDR control of topological properties of the signal (i.e. control of properties that pertain to the spatial organization of activations – e.g. height and extent – and are not reducible to individual voxels). SPM is now able to identify significantly voluminous blobs according to a decision procedure that controls spatial-extent FDR. Thus, on average, the fraction of blobs falsely deemed to have significant spatial extent is controlled beneath say 5/100 = .05 or 1/100 = .01. More recent work is examining FDR control over local maxima.

A post to SPM-ML by Tom Nichols

In SPM8 FDR topological inference was introduced, and voxel-wise FDR inference hidden. Topological inference means inference on peaks and clusters; voxel-wise inference is based on every individual voxel in the image (instead of spatial features of the image). Thus “Topological FDR” means inference on clusters based on cluster size (or local peaks based on peak height), controlling the fraction of false positive clusters among all clusters (or false positive peaks among all peaks) on average, over many experiments.

While topological FDR results may be easier to interpret, in my experience it is is generally not very sensitivity and yields similar results to FWE-corrected inferences.

If you would like to use voxel-wise FDR in SPM8, edit spm_defaults, changing “topoFDR” line to read
defaults.stats.topoFDR = 0;
(quit and re-start SPM to take effect).

References
Chumbley, J., Worsley, K., Flandin, G., & Friston, K. (2010). Topological FDR for neuroimaging. NeuroImage, 49(4), 3057-64. doi: 10.1016/j.neuroimage.2009.10.090.

Chumbley, J. R., & Friston, K. J. (2009). False discovery rate revisited: FDR and topological inference using Gaussian random fields. Neuroimage, 44(1), 62–70. doi: 10.1016/j.neuroimage.2008.05.021.

Files generated in VBM statistics

When you do VBM analysis, you see many files are generated in your stats directory. Suppose you are doing a two sample t-test. You see files like below.

  • beta_0001
  • beta_0002
  • con_0001
  • mask
  • ResMS
  • RPV
  • spmT_001

Ged Ridgway made a clear explanation of these files in NITRC discussion forum. http://www.nitrc.org/forum/message.php?msg_id=6483
It is important to know what these files are, so I quote his post with some modification.

  • beta
  • The estimated linear model parameters at each voxel. In a two-sample design, these are just the two group mean images. beta_0001 is a mean image of group A, and beta_0002 is a mean image of group B.

  • con
  • The contrasts of the parameters. If one makes a contrast of [-1 1], the con_0001 will simply be beta_0002 – beta_0001

  • mask
  • A binary image indicating which voxels were considered in the analysis. If this mask is too small, you may miss the region you are interested in. If too big, it is less likely to survive multiple comparison. So it is worth checking the mask image before you draw some conclusion from your analysis.

  • ResMS
  • The estimated variance (residual mean squares), from which the above-mentioned standard error is derived.
    In more detail, the standard error is proportional to the square root of ResMS and a term that relates to the design matrix X and contrast c as sqrt(c’*pinv(X’*X)*c), which (in two sample t-test) roughly reflects the fact that the standard error is inversely proportional to the number of subjects one has.

  • RPV
  • The resels-per-voxel image related to the smoothness (roughness)
    estimate needed for random field theory.

  • spmT
  • The t-statistic maps formed by dividing the contrast image by its estimated standard error.

Aterm WM3600Rで無線LANの接続が頻繁に切れる場合の対策

私は普段WiMAXを使っているのですが、最近手に入れたAterm WM3600Rは非常に無線LANの接続が切れていました。
これでは、意味がないじゃん!と思っていましたが、検索すると多くの人が同じ症状で苦しんでいました。

NECが公式に対策を発表しているので、それを備忘録も含めて下に書きます。

出典はこちら

  1. クイック設定Webを開きます。
  2. http://aterm.me  で開きます。

  3. 左メニューから『無線LAN設定』-『無線LAN設定』を選択します。
  4. 『無線LAN設定』画面が開きますので、【高度な設定を表示】ボタンを押して「拡張設定」を表示させます。
  5. ここで以下の設定を行います。
    メーカーのページには以下のように書かれています。

    いずれかの設定を行うのみで改善される場合や、複数の設定を行うことで改善される場合があります。記載された内容を1つずつお試しください。また、これらの設定を行っても原因が別にある場合は、改善されない場合もあります。

    1. [無線LAN端末(子機)との通信設定]で【省電力優先】を選択する。
    2. ※上記設定を行うと、スループット(実行速度)が低下する場合があります。

    3. [無線優先制御機能]で【使用する】に入っているチェックを外す。
    4. ※上記設定を行うと、11bまたは11gでの通信となり、11nテクノロジーでの通信は行えません。

    5. [送信出力]で【100%】を選択する。
    6. ※上記設定を行うと、他の通信機器が近くにある場合は、電波の干渉が受けやすくなります。

    どうもいろんな人のブログを見ると、一番最初にある無線LAN端末との通信設定で省電力優先を選択することがよいようです。
    実際、その設定で切断が圧倒的に減りました。
    通信速度よりも接続の安定の方がずっと大事なので、そちらでしばらくやってみます。

Shell script to replace a part of filenames

I came across a situation I want to change a part of filenames.
I have many nvXXXX.nii files, and I want to change it to n1vXXXX.nii.
Below is the shell script I came up with.
The point is using sed.

#!/bin/bash
# A script to change a part of filenames.
for FILE in $*
do
  echo $FILE | sed -e "s/nv/n1v/" # This is optional. I just want to display the filenames on the monitor.
  mv $FILE `echo $FILE | sed -e "s/nv/n1v/"`
done

The below might be better if I want to use the new filenames as some variables.

#!/bin/bash
# A script to change a part of filenames.
for FILE in $*
do
  echo $FILE | sed -e "s/nv/n1v/"
  NEWFILE=`echo $FILE | sed -e "s/nv/n1v/"`
  mv $FILE $NEWFILE
done

openSuse 11.1 で Scan Snap S510は使えるか?

*昔に書いた内容ですが、検索でひっかかることが多いようなので、再度アップします。

確定申告の時期で、いろいろな書類のコピーをとるためにScansnapが大活躍しています。

Scansnapを導入したとき、Windowsマシンに様々なドライバをインストールしなければいけなかったので、Linuxでは使えないだろうなぁと勝手に思っていました。

しかし、何気なく”scansnap Linux”でググってみたところ、ubuntuでXSANEを使うとできちゃうみたいなことが書いてある記事を発見しました。

そこで、opensuse 11.1でできるかどうか確認。

xsaneのインストールの確認
YAST -> ソフトウェアの管理 -> xsaneで検索してみると、自分のマシンにはインストールされていました。

scansnap S510をつないでみる。
WindowsマシンにつながれていたS510のUSBコードをLinuxマシンに差し替えます。

どのように認識されるか確認
lsusb でUSBデバイスのリストを一覧で表示できます。

こんな出力がされました。

$lsusb

Bus 005 Device 002: ID 04c5:1155 Fujitsu, Ltd

対応の確認
次の2通りの方法があるかと。

SANEのサイトで確認
http://www.sane-project.org/sane-mfgs.html#Z-FUJITSU

ここには、

S510 USB 0x04c5/0×1155 Good workgroup, current, no TWAIN driver fujitsu
(1.0.55) sane-fujitsu
とかかれています。きちんと動きそうです。

/etc/sane.d/fujitsu.confを確認
$less /etc/sane.d/fujitsu.conf

最後の行にS510があります。

#scansnap S510
usb 0x04c5 0×1155

きちんと動きそうです。

xsaneの起動
メニューから、グラフィックの中にxsaneがあるので、それから起動。

感動したのが、ADFが両面も選べるようになっていること。

(ただし、その場合は、スキャン枚数(一番上の項目)を2以上に設定しなければいけません。)

ScanSnap本体の緑色ボタンは使えないものの、xsane経由で、普通にScansnapが使えるようになりました。

これで、Windowsに依存しなければいけない要素がまた一つ減りました。

それにしても、最近のLinuxは便利になりましたね。

Neurodebianのミラーサイト

このブログでも今までに紹介し、そしてLin4Neuroでも採用させていただいてきたNeurodebianですが、開発者のYarsolav Halchenkoといろいろやりとりした結果、日本でミラーサイトを立ち上げました。最近はファイルサイズの大きなものもありますので、日本からの場合、このミラーサイトを使っていただいたら、ダウンロード時間を短縮できる可能性があります。

方法を簡単に説明します。

まず、http://neuro.debian.netにいきます。

トップページにある、”How to use this repository”を見ます。

そこに、下図にあるような感じでDebianかUbuntuのリリースとダウンロードサイトを選ぶドロップダウンメニューが出てきます。

そこに出てくる2行を端末にコピペします。Ubuntu 12.04の場合は以下の2行になります。

wget -O- http://neuro.debian.net/lists/precise.jp | sudo tee etc/apt/sources.list.d/neurodebian.sources.list
sudo apt-key adv --recv-keys --keyserver pgp.mit.edu 2649A5A9

その後、apt-get updateと、apt-get upgradeを行い、さらにapt-get installで必要なソフトをインストールします。

それだけで設定はおしまいです。便利ですよね。

いろいろな画像解析関連ソフトが簡単にいれられますので、どうぞ利用してみてください。
日本語版Lin4Neuroでもこの日本のミラーサイトがデフォルトになっています。

How to install FSL on Ubuntu (up to 5.0.9)

N.B.: This is the old post. If you want to install the latest FSL (5.0.10 and later), you need to use fslinstaller.py.

If you use Debian or Ubuntu, you can install FSL easily using neurodebian repository.
Below is what you need to install FSL.

  1. Add the neurodebian repository
  2. Follow the guideline described here.

  3. update the sources.list
  4.         $ sudo apt-get update
            
  5. install FSL (and related packages)
  6.         $ sudo apt-get install fsl fsl-doc fslview fslview-doc fsl-atlases fsl-possum-data fsl-first-data fsl-feeds dicomnifti libvtk5-dev vtk-examples vtk-doc
            
  7. Add the following line to .bashrc
  8. This is the thing people often forget. Without this, you can’t run fsl from shell.

             . /etc/fsl/fsl.sh
             

    That’s it.

Windowsでコマンプロンプトが無効にされているときの裏ワザ

 知人にPCがおかしいから見てくれと相談され、見ました。コマンドプロンプトから確認しようと思ったところ、そのPCが管理されている職場のポリシーで、コマンドプロンプトが無効にされていました…。検索してもあまり方法はありませんでした。
 普通ならそこで諦めるところですが、なんか方法がないかなぁと思い、いろいろ試行錯誤してみました。
 非常に簡単な抜け穴がありました。

 それは、「ショートカットを作成する」という方法です。デスクトップ画面から右クリックで、「新規作成」→「ショートカット」とし、「項目の場所を入力して下さい」となっているところで、”cmd”とタイプします。そうすると、cmd.exeへのショートカットと出てきます。そこからコマンドプロンプトを立ち上げることができます。

 検索すると、Windowsには、コマンドプロンプト自体を無効にするというオプションもあるようですが、いろいろ抜け穴がありそうですね。逆にセキュリティ上はやはりもろいシステムということになるのでしょう。

 このブログでは、Windowsネタはほとんど扱わないと思いますが、気になったことだったのでアップしておきます。