复现步骤
age <- c(
40, 38, 40, 35, 36, 37, 41, 40, 37, 38, 40, 38,
40, 36, 40, 38, 42, 39, 40, 37, 36, 38, 39, 40
)
birthw <- c(
2968, 2795, 3163, 2925, 2625, 2847, 3292, 3473, 2628, 3176,
3421, 2975, 3317, 2729, 2935, 2754, 3210, 2817, 3126, 2539,
2412, 2991, 2875, 3231
)
sex <- gl(2, 12, labels = c("M", "F"))
BirthWeight <- data.frame(age = age, birthw = birthw, sex = sex)
library(ggplot2)
ggplot(aes(x = age, y = birthw, group = sex, color = sex),
data = BirthWeight) + geom_point() +
geom_smooth(method = "loess")
lowess(age[sex == "M"], birthw[sex == "M"])
$x
[1] 35 36 37 37 38 38 38 40 40 40 40 41
$y
[1] 2760.981 2791.348 2823.453 2823.453 2981.416 2981.416 2981.416 3262.513
[9] 3262.513 3262.513 3262.513 3292.000
lowess(age[sex == "F"], birthw[sex == "F"])
$x
[1] 36 36 37 38 38 39 39 40 40 40 40 42
$y
[1] 2535.244 2535.244 2658.669 2775.027 2775.027 2846.000 2846.000 3162.843
[9] 3162.843 3162.843 3162.843 3248.897
经查 ?loess
和 ?lowess
,前者是后者的 的扩展版,二者默认设置有所不同。现在的问题是我没办法对应二者在参数设置上的关系,求助各位?
附上 ggplot2 和运行环境
xfun::session_info('ggplot2')
R Under development (unstable) (2019-10-24 r77329)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8.1 x64 (build 9600)
Locale:
LC_COLLATE=Chinese (Simplified)_China.936
LC_CTYPE=Chinese (Simplified)_China.936
LC_MONETARY=Chinese (Simplified)_China.936
LC_NUMERIC=C
LC_TIME=Chinese (Simplified)_China.936
Package version:
assertthat_0.2.1 backports_1.1.5 cli_1.1.0
colorspace_1.4.1 crayon_1.3.4 digest_0.6.22
ellipsis_0.3.0 fansi_0.4.0 ggplot2_3.2.1.9000
glue_1.3.1 graphics_4.0.0 grDevices_4.0.0
grid_4.0.0 gtable_0.3.0 labeling_0.3
lattice_0.20.38 magrittr_1.5 MASS_7.3.51.4
Matrix_1.2.17 methods_4.0.0 mgcv_1.8.30
munsell_0.5.0 nlme_3.1.141 pillar_1.4.2
pkgconfig_2.0.3 plyr_1.8.4 R6_2.4.0
RColorBrewer_1.1.2 Rcpp_1.0.2 reshape2_1.4.3
rlang_0.4.1 scales_1.0.0 splines_4.0.0
stats_4.0.0 stringi_1.4.3 stringr_1.4.0
tibble_2.1.3 tools_4.0.0 utf8_1.1.4
utils_4.0.0 vctrs_0.2.0 viridisLite_0.3.0
withr_2.1.2 zeallot_0.1.0
输出警告信息
Warning messages:
1: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric, ... :
pseudoinverse used at 38
2: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric, ... :
neighborhood radius 2
3: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric, ... :
reciprocal condition number 5.3401e-017
4: In predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x else if (is.data.frame(newdata)) as.matrix(model.frame(delete.response(terms(object)), ... :
pseudoinverse used at 38
5: In predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x else if (is.data.frame(newdata)) as.matrix(model.frame(delete.response(terms(object)), ... :
neighborhood radius 2
6: In predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x else if (is.data.frame(newdata)) as.matrix(model.frame(delete.response(terms(object)), ... :
reciprocal condition number 5.3401e-017
7: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric, ... :
pseudoinverse used at 40
8: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric, ... :
neighborhood radius 2
9: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric, ... :
reciprocal condition number 0
10: In predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x else if (is.data.frame(newdata)) as.matrix(model.frame(delete.response(terms(object)), ... :
pseudoinverse used at 40
11: In predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x else if (is.data.frame(newdata)) as.matrix(model.frame(delete.response(terms(object)), ... :
neighborhood radius 2
12: In predLoess(object$y, object$x, newx = if (is.null(newdata)) object$x else if (is.data.frame(newdata)) as.matrix(model.frame(delete.response(terms(object)), ... :
reciprocal condition number 0