此 NA 處理程序確保那些支持 na.action
參數的模型不會默默地刪除缺失值。它環繞stats::na.exclude()
,以便輸入行有一個預測/殘差。要全局應用它,請運行 options(na.action = na.warn)
。
例子
df <- tibble::tibble(
x = 1:10,
y = c(5.1, 9.7, NA, 17.4, 21.2, 26.6, 27.9, NA, 36.3, 40.4)
)
# Default behaviour is to silently drop
m1 <- lm(y ~ x, data = df)
resid(m1)
#> 1 2 4 5 6 7
#> -0.59214286 0.14500000 0.11928571 0.05642857 1.59357143 -0.96928571
#> 9 10
#> -0.29500000 -0.05785714
# Use na.action = na.warn to warn
m2 <- lm(y ~ x, data = df, na.action = na.warn)
#> Warning: Dropping 2 rows with missing values
resid(m2)
#> 1 2 3 4 5 6
#> -0.59214286 0.14500000 NA 0.11928571 0.05642857 1.59357143
#> 7 8 9 10
#> -0.96928571 NA -0.29500000 -0.05785714
相關用法
- R modelr typical 求典型值
- R modelr resample “惰性”重采樣。
- R modelr crossv_mc 生成測試訓練對以進行交叉驗證
- R modelr model_matrix 構建設計矩陣
- R modelr model-quality 計算給定數據集的模型質量
- R modelr permute 生成 n 個排列重複。
- R modelr fit_with 擬合公式列表
- R modelr add_residuals 將殘差添加到 DataFrame
- R modelr data_grid 生成數據網格。
- R modelr formulas 創建公式列表
- R modelr add_predictions 將預測添加到 DataFrame
- R modelr seq_range 生成向量範圍內的序列
- R modelr resample_partition 生成數據幀的獨占分區
- R modelr add_predictors 將預測變量添加到公式中
- R modelr bootstrap 生成 n 個引導程序重複。
- R modelr resample_bootstrap 生成 boostrap 複製
- R vcov.gam 從 GAM 擬合中提取參數(估計器)協方差矩陣
- R gam.check 擬合 gam 模型的一些診斷
- R matrix轉list用法及代碼示例
- R as 強製對象屬於某個類
- R null.space.dimension TPRS 未懲罰函數空間的基礎
- R language-class 表示未評估語言對象的類
- R gam.reparam 尋找平方根懲罰的穩定正交重新參數化。
- R className 類名包含對應的包
- R extract.lme.cov 從 lme 對象中提取數據協方差矩陣
注:本文由純淨天空篩選整理自Hadley Wickham等大神的英文原創作品 Handle missing values with a warning。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。