2

I am currently exploring the gbm functions in the package dismo to create boosted regression trees for species distribution modeling. I have been using the dismo vignettes as well as the 2008 paper "A working guide to boosted regression trees" by Elith et al., published in the Journal of Animal Ecology. On page 808:809 of the Elith et al. article, the authors explain partial dependence plots and give an example at the bottom of page 809 (Fig. 6). According to the dismo vignette "Boosted Regression Trees for ecological modeling", gbm.plot "Plots the partial dependence of the response on one or more predictors".

Gbm.plot creates plots that look almost exactly like the example in Elith et al.. However, there are a few parameters I cannot figure out how to set to achieve a figure the exact same as in the paper.

  1. The y-axes in the paper are on the logit scale and are centered to have a zero mean over the data distribution. The y-axes in gbm.plot represent the fitted function.

  2. The rug in the paper is on the top of the plots, gbm.step the rug is on the bottom.

  3. Gbm.plot uses the variable name as the x-axis label. The paper has meaningful axis labels.

Here is the figure from the Elith paper compared to one produced with gbm.plot

Figure 6 from Elith et al., 2009 Figure 6 from Elith et al., 2009

From gbm.plot From gbm.plot

My solutions

While looking for solutions I came across this question and it gave me the idea to look at the source code (a first for me). From the source, I was able to get a good idea of how the function is put together, but there is still much I don't understand.

  1. I am not sure what to change to transform the y-axes to the logit scale and center them to have a mean of zero.

  2. I was able to change the source to move the rug to the top of the plots. I found the command for the rug function and added an argument of side=3.

  3. For the variable names, I figure I need to make a list of appropriate variable names, attach it to the data, and somehow read it into the source code. Still over my head.

I will be thankful for any input. I also think that if other ecologists are using the Elith paper to guide them, they may run into the same problem.

Here is an example of the code I ran to produce the plots

gbm.plot(all.sum.tc4.lr001, rug=TRUE, smooth=TRUE, n.plots=9, common.scale=TRUE, write.title = FALSE, show.contrib=TRUE, plot.layout=c(2,3), cex.lab=1.5)

4

2 に答える 2

0

これは遅くなりましたが、問題 3 に対する回り道の解決策を提供できます: カスタム x ラベルを gbm.plot に追加します。もっと良い方法があると確信していますが、ここで私がやったことです。この方法は、大規模なデータセットがあり、頻繁に使用する変数を調整する場合に役立ちます。

ステップ 1. gbm.plot の dismo パッケージのソース コードを見つけます。すべてのコードを選択して新しいスクリプトを作成し、関数に gbm.plot2 という名前を付けます。「var.name」を検索します。var.name が変更されているインスタンスを置き換えます。例:

var.name <- gbm.call$predictor.names[k]
var.name <- x.label 

これに:

var.name <- labels[j]

スクリプトを保存して source() を使用して呼び出すか、スクリプト全体を実行して gbm.plot2 をグローバル環境に取得します。

ステップ 2. データフレームが「df」と呼ばれ、200 列あるとしましょう。gbm.step で呼び出したい列番号を選択します。

vars <- c(17, 175, 198)

ステップ 3. 2 つの列を持つデータフレームを作成します。1 つの列には、使用する可能性のあるすべての変数名が含まれ、もう 1 つの列には使用したいラベルが含まれます。ColumnNames が実際に "colnames(df)[vars]" にあるものと一致していることを確認してください。

ColumnNames <- c("HiHorAve", "Elev", "Type5")
Labels <- c("Hi Hello Avenue", "Probably Elevation", "Type 5 of Something")
labels <- data.frame(ColumnNames,Labels)

データフレームに表示される順序でラベルを並べ替えます。これは、多数の変数があり、データ フレームの形状が頻繁に変化する場合に役立ちます。

labels <- labels[match(colnames(df)[vars], labels$ColumnNames),]

ステップ 4. gbm.step 式を次のように実行します。

BRTmodel<- gbm.step(data=df, gbm.x=vars, gbm.y = 5, .....)

ステップ 5. モデルの要約を取得します -- 変数を相対的な重要度で並べ替えます。次に、ラベルを相対的な重要度で並べ替えます。

smry1<- summary(BRTmodel)

labels <- labels[order(match(names(df)[vars],smry1$var))]
labels <- labels$Labels #extract the labels to a vector

ステップ 6. 新しい gbm.plot スクリプトを実行します。

  gbm.plot2(BRTmodel, n.plots=3, y.label="")

素敵なラベルのみをプロットする必要があります。

于 2015-01-27T20:25:09.137 に答える