s
位於 mgcv
包(package)。 說明
用於定義 gam
模型公式中的平滑項的函數。該函數不評估(樣條)平滑 - 它的存在純粹是為了幫助使用基於樣條的平滑建立模型。
用法
s(..., k=-1,fx=FALSE,bs="tp",m=NA,by=NA,xt=NULL,id=NULL,sp=NULL,pc=NULL)
參數
... |
變量列表,這些變量是該平滑函數的協變量。此處最好避免形式取決於數據值的轉換:例如 |
k |
用於表示平滑項的基維數。默認值取決於平滑函數的變量數量。 |
fx |
指示該項是否是固定 d.f。回歸樣條線 ( |
bs |
兩個字母的字符串,指示要使用的(懲罰)平滑基礎。 (例如, |
m |
該項的懲罰階數(例如,當使用默認 t.p.r.s 基礎時,具有二階導數的正態三次樣條懲罰為 2)。 |
by |
與每個協變量具有相同維度的數值或因子變量。在數值向量的情況下,元素乘以平滑值,並在相應的協變量值處進行評估(“變化係數模型”結果)。對於數字 |
xt |
建立特定基礎所需的任何額外信息。使用例如以 |
id |
標識該術語的標簽或整數,以便將其平滑參數鏈接到相同類型的其他參數。如果兩個或多個術語具有相同的 |
sp |
為此項提供的任何平滑參數。必須是與此平滑的懲罰數長度相同的數組。正或零元素被視為固定平滑參數。負元素表示自動初始化。將 |
pc |
如果不是 |
細節
該函數不計算變量參數。要使用此函數來指定使用您自己的平滑,請注意輸入和輸出對象之間的關係,並參閱 smooth.construct
中的示例。
值
類 xx.smooth.spec
對象,其中 xx
是 s
的 bs
參數給出的基礎標識代碼。這些smooth.spec
對象定義平滑,並通過smooth.construct
方法函數轉換為基數和懲罰。
返回的對象包含以下項目:
term |
文本字符串數組,給出該項作為函數的協變量的名稱。 |
bs.dim |
用於表示平滑的基礎尺寸。 |
fixed |
如果該項被視為純回歸樣條(具有固定自由度),則為 TRUE;如果將其視為懲罰回歸樣條則為 FALSE |
dim |
平滑器的維度 - 即它作為函數的協變量的數量。 |
p.order |
t.p.r.s 的順序懲罰,或懲罰順序的 auto-selection 為 0。 |
by |
是任何 |
label |
適合這個平滑術語的文本標簽。 |
xt |
作為參數傳入的對象 |
id |
平滑的識別標簽或編號,將其與其他平滑鏈接起來。默認為 |
sp |
項的平滑參數數組(auto-estimation 為負值)。默認為 |
例子
# example utilising `by' variables
library(mgcv)
set.seed(0)
n<-200;sig2<-4
x1 <- runif(n, 0, 1);x2 <- runif(n, 0, 1);x3 <- runif(n, 0, 1)
fac<-c(rep(1,n/2),rep(2,n/2)) # create factor
fac.1<-rep(0,n)+(fac==1);fac.2<-1-fac.1 # and dummy variables
fac<-as.factor(fac)
f1 <- exp(2 * x1) - 3.75887
f2 <- 0.2 * x1^11 * (10 * (1 - x1))^6 + 10 * (10 * x1)^3 * (1 - x1)^10
f<-f1*fac.1+f2*fac.2+x2
e <- rnorm(n, 0, sqrt(abs(sig2)))
y <- f + e
# NOTE: smooths will be centered, so need to include fac in model....
b<-gam(y~fac+s(x1,by=fac)+x2)
plot(b,pages=1)
作者
Simon N. Wood simon.wood@r-project.org
參考
Wood, S.N. (2003) Thin plate regression splines. J.R.Statist.Soc.B 65(1):95-114
Wood S.N. (2017) Generalized Additive Models: An Introduction with R (2nd edition). Chapman and Hall/CRC Press.
https://www.maths.ed.ac.uk/~swood34/
也可以看看
相關用法
- R scat 用於重尾數據的 GAM 縮放 t 係列
- R smooth.construct.cr.smooth.spec GAM 中的懲罰三次回歸樣條
- R smooth.construct.bs.smooth.spec GAM 中的懲罰 B 樣條
- R smooth.construct GAM 中平滑項的構造函數
- R smooth.construct.sz.smooth.spec GAM 中的約束因子平滑交互
- R smooth.construct.re.smooth.spec GAM 中的簡單隨機效應
- R slanczos 計算對稱矩陣的截斷特征分解
- R single.index 具有 mgcv 的單指數模型
- R smooth.info 提供有關平滑規範的額外信息的通用函數
- R smooth2random 將平滑轉換為適合估計隨機效應的形式
- R smooth.construct.mrf.smooth.spec 馬爾可夫隨機場平滑
- R smooth.construct.gp.smooth.spec 低階高斯過程平滑
- R smooth.construct.tp.smooth.spec GAM 中的懲罰薄板回歸樣條
- R smooth.construct.ad.smooth.spec GAM 中的自適應平滑
- R smooth.construct.so.smooth.spec 皂膜平滑劑
- R smooth.construct.ds.smooth.spec 低階 Duchon 1977 樣條
- R sp.vcov 從 (RE)ML GAM 擬合中提取平滑參數估計器協方差矩陣
- R smooth.construct.fs.smooth.spec GAM 中平滑交互的因子
- R smooth.construct.ps.smooth.spec GAM 中的 P 樣條
- R smooth.construct.sos.smooth.spec 球體上的樣條線
- R smooth.construct.tensor.smooth.spec 張量積平滑構造函數
- R shash Sinh-arcsinh 位置比例和形狀模型族
- R smooth.construct.t2.smooth.spec 張量積平滑構造函數
- R smoothCon GAM 平滑項的預測/構造包裝函數
- R step.gam step.gam 的替代品
注:本文由純淨天空篩選整理自R-devel大神的英文原創作品 Defining smooths in GAM formulae。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。