當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


R ppr 投影尋蹤回歸

R語言 ppr 位於 stats 包(package)。

說明

擬合投影尋蹤回歸模型。

用法

ppr(x, ...)

## S3 method for class 'formula'
ppr(formula, data, weights, subset, na.action,
    contrasts = NULL, ..., model = FALSE)

## Default S3 method:
ppr(x, y, weights = rep(1, n),
    ww = rep(1, q), nterms, max.terms = nterms, optlevel = 2,
    sm.method = c("supsmu", "spline", "gcvspline"),
    bass = 0, span = 0, df = 5, gcvpen = 1, trace = FALSE, ...)

參數

formula

指定一個或多個數字響應變量和解釋變量的公式。

x

解釋變量的數字矩陣。行代表觀察值,列代表變量。不接受缺失值。

y

響應變量的數字矩陣。行代表觀察值,列代表變量。不接受缺失值。

nterms

最終模型中包含的項數。

data

一個數據幀(或類似的:參見 model.frame ),優先從中獲取 formula 中指定的變量。

weights

每種情況的權重向量w_i

ww

每個響應的權重向量,因此擬合標準是 w_i ww_j (y_ij - fit_ij)^2 的案例 i 和響應 j 的總和除以 w_i 的總和。

subset

指定訓練樣本中使用的情況的索引向量。 (注意:如果給出,則必須命名該參數。)

na.action

一個函數,用於指定找到 NA 時要采取的操作。默認操作由 getOption("na.action") 給出。 (注意:如果給出,則必須命名該參數。)

contrasts

對任何因子解釋變量進行編碼時要使用的對比。

max.terms

構建模型時可選擇的最大項數。

optlevel

0 到 3 之間的整數,決定 SMART 程序中優化例程的徹底性。請參閱“詳細信息”部分。

sm.method

用於平滑嶺函數的方法。默認是使用 Friedman 的超級平滑器 supsmu 。替代方案是使用 smooth.spline 底層的平滑樣條代碼,或者為每個脊函數指定(等效)自由度,或者允許 GCV 選擇平滑度。

可以縮寫。

bass

超平滑的低音音調控製與自動跨度選擇一起使用(參見supsmu);值的範圍是 0 到 10,值越大,平滑度越高。

span

超級平滑的跨度控製(參見supsmu)。默認值 0 會導致通過本地交叉驗證自動選擇跨度。 span 也可以采用 (0, 1] 中的值。

df

如果 sm.method"spline" 通過請求的等效自由度指定每個脊項的平滑度。

gcvpen

如果sm.method"gcvspline",這是在GCV 選擇中使用的每個自由度的懲罰。

trace

邏輯指示每個樣條擬合是否應產生診斷輸出(關於 lambdadf ),以及 SUPSMU 擬合其步驟。

...

要傳遞給其他方法或從其他方法傳遞的參數。

model

合乎邏輯的。如果為 true,則返回模型框架。

細節

基本方法由 Friedman (1984) 給出,本質上與 S-PLUS 的 ppreg 使用的代碼相同。該代碼對所使用的編譯器極其敏感。

該算法首先將 max.terms 嶺項一次相加;如果它無法找到一個可以產生足夠差異的術語來添加,它將使用更少的內容。然後,它會在每一步中刪除最不重要的術語,直到留下 nterms 術語。

優化級別(參數 optlevel )的不同之處在於在此過程中模型重新擬合的徹底程度。在 0 級,現有的山脊項不會進行改裝。在級別 1,投影方向不會重新擬合,但嶺函數和回歸係數會重新擬合。 2 級和 3 級重新調整了所有術語,並且對於一個響應來說是等效的;第 3 級更仔細地重新平衡每個步驟中每個回歸量的貢獻,因此不太可能收斂到平方和標準的鞍點。

包含以下組件的列表,其中許多組件供方法函數使用。

call

匹配的調用

p

解釋變量的數量(任何編碼後)

q

響應變量的數量

mu

參數nterms

ml

參數max.terms

gof

所選模型的總體殘差(加權)平方和

gofn

相對於項數的總體殘差(加權)平方和,最多 max.terms 。小於 nterms 時將無效(且為零)。

df

參數df

edf

如果sm.method"spline""gcvspline",則使用每個脊項的等效自由度數。

xnames

解釋變量的名稱

ynames

響應變量的名稱

alpha

投影方向矩陣,每個脊項有一列

beta

適用於嶺項的每個響應的係數矩陣:行是響應,列是嶺項

yb

每個響應的加權平均值

ys

使用的總體比例因子:在內部將響應除以 ys 以獲得單位總加權平方和。

fitted.values

擬合值,作為矩陣 if q > 1

residuals

殘差,作為矩陣 if q > 1

smod

內部工作數組,其中包括在訓練設定點評估的嶺函數。

model

(僅當 model = TRUE )模型框架。

例子

require(graphics)

# Note: your numerical values may differ
attach(rock)
area1 <- area/10000; peri1 <- peri/10000
rock.ppr <- ppr(log(perm) ~ area1 + peri1 + shape,
                data = rock, nterms = 2, max.terms = 5)
rock.ppr
# Call:
# ppr.formula(formula = log(perm) ~ area1 + peri1 + shape, data = rock,
#     nterms = 2, max.terms = 5)
#
# Goodness of fit:
#  2 terms  3 terms  4 terms  5 terms
# 8.737806 5.289517 4.745799 4.490378

summary(rock.ppr)
# .....  (same as above)
# .....
#
# Projection direction vectors ('alpha'):
#       term 1      term 2
# area1  0.34357179  0.37071027
# peri1 -0.93781471 -0.61923542
# shape  0.04961846  0.69218595
#
# Coefficients of ridge terms:
#    term 1    term 2
# 1.6079271 0.5460971

par(mfrow = c(3,2))   # maybe: , pty = "s")
plot(rock.ppr, main = "ppr(log(perm)~ ., nterms=2, max.terms=5)")
plot(update(rock.ppr, bass = 5), main = "update(..., bass = 5)")
plot(update(rock.ppr, sm.method = "gcv", gcvpen = 2),
     main = "update(..., sm.method=\"gcv\", gcvpen=2)")
cbind(perm = rock$perm, prediction = round(exp(predict(rock.ppr)), 1))
detach()

來源

Friedman (1984):由 B. D. Ripley 轉換為雙精度並添加平滑樣條接口,最初用於 MASS 包。

參考

Friedman, J. H. and Stuetzle, W. (1981). Projection pursuit regression. Journal of the American Statistical Association, 76, 817-823. doi:10.2307/2287576.

Friedman, J. H. (1984). SMART User's Guide. Laboratory for Computational Statistics, Stanford University Technical Report No. 1.

Venables, W. N. and Ripley, B. D. (2002). Modern Applied Statistics with S. Springer.

也可以看看

plot.ppr , supsmu , smooth.spline

相關用法


注:本文由純淨天空篩選整理自R-devel大神的英文原創作品 Projection Pursuit Regression。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。