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


R splineDesign B 樣條的設計矩陣

R語言 splineDesign 位於 splines 包(package)。

說明

根據 x 中的值評估 knots 定義的 B-splines 的設計矩陣。

用法

splineDesign(knots, x, ord = 4, derivs, outer.ok = FALSE,
             sparse = FALSE)
spline.des  (knots, x, ord = 4, derivs, outer.ok = FALSE,
             sparse = FALSE)

參數

knots

結位置的數字向量(如果需要,將按順序遞增排序)。

x

用於評估 B-spline 函數或導數的數值向量。除非 outer.ok 為 true,否則 x 中的值必須位於 “inner” 結 knots[ord]knots[ length(knots) - (ord-1)] 之間。

ord

給出樣條函數階數的正整數。這是每個分段多項式段中的係數數量,因此三次樣條的階數為 4。默認為 4。

derivs

值介於 0ord - 1 之間的整數向量,概念上回收到 x 的長度。給定階數的導數在 x 位置進行計算。默認為零(或與 x 長度相同的零向量)。

outer.ok

邏輯指示是否應允許 x 位於內部結之外,請參閱 x 參數。

sparse

邏輯指示結果是否應從類 "sparseMatrix" 繼承(來自包 Matrix )。

具有 length(x) 行和 length(knots) - ord 列的矩陣。矩陣的第 i 行包含由 knot 向量定義的 B-splines(或 B-splines 的指示導數)的係數,並在 x 的第 i 個值處進行評估。每個B-spline 由一組ord 連續結定義,因此B-splines 的總數為length(knots) - ord

注意

舊的 spline.des 函數采用相同的參數,但返回一個包含多個組件的列表,包括 knotsordderivsdesigndesign 組件與splineDesign 函數的值相同。

例子

require(graphics)
splineDesign(knots = 1:10, x = 4:7)
splineDesign(knots = 1:10, x = 4:7, derivs = 1)
## visualize band structure
Matrix::drop0(zapsmall(6*splineDesign(knots = 1:40, x = 4:37, sparse = TRUE)))

knots <- c(1,1.8,3:5,6.5,7,8.1,9.2,10)  # 10 => 10-4 = 6 Basis splines
x <- seq(min(knots)-1, max(knots)+1, length.out = 501)
bb <- splineDesign(knots, x = x, outer.ok = TRUE)

plot(range(x), c(0,1), type = "n", xlab = "x", ylab = "",
     main =  "B-splines - sum to 1 inside inner knots")
mtext(expression(B[j](x) *"  and "* sum(B[j](x), j == 1, 6)), adj = 0)
abline(v = knots, lty = 3, col = "light gray")
abline(v = knots[c(4,length(knots)-3)], lty = 3, col = "gray10")
lines(x, rowSums(bb), col = "gray", lwd = 2)
matlines(x, bb, ylim = c(0,1), lty = 1)

作者

Douglas Bates and Bill Venables

相關用法


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