首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R上的loess.smooth插值

R上的loess.smooth插值
EN

Stack Overflow用户
提问于 2018-02-22 19:25:28
回答 1查看 524关注 0票数 1

在运行样条线方法之后,我正在运行loess.smooth方法。下面给出的输入是我运行样条法后得到的数据。然而,我在使用loess.smooth方法时犯了错误。整个第一列都是以浮点格式返回输出,但我需要的是增量为1的整数格式。

任何帮助都将不胜感激。

谢谢

代码语言:javascript
复制
**input:** spline_file
1   0.157587435
2   0.146704412
3   0.129899285
4   0.138925582
5   0.104085676

out <- loess.smooth(spline_file$x, spline_file$y, span = 1, degree = 1, 
family = c("gaussian"), length.out = seq(1, max_exp, by = 1), surface= 
"interpolate", normalize = TRUE, method="linear") 

**OUTPUT:**
0           0.150404703
1.020408163 0.154413716
2.040816327 0.158458172
3.06122449  0.162515428
4.081632653 0.166562839
5.102040816 0.170577762

**OUTPUT REQUIRED:**
x   y
1   0.225926707
2   0.226026551
3   0.226241194
4   0.2265471
5   0.226920733
EN

回答 1

Stack Overflow用户

发布于 2018-02-22 20:27:39

我不确定下面的内容是否完全回答了你的问题,但也许它会有所帮助。下面是一些代码,演示图和一些解释/建议。

  1. 您不应该使用1的degree,您的数据需要更高的学位。
  2. 您应该通过?loess.smooth检查允许的参数。我认为您混淆了scatter.smoothloess.smooth的一些参数,并进一步使用了函数中不存在的一些参数(例如normalize -如果我监督了什么,请纠正我)。

在任何情况下,样条平滑函数的输出具有比原始数据更多的数据点都是有意义的。为了能够绘制一条平滑的曲线,通过平滑功能在数据点之间生成附加点。检查以下代码末尾生成的图。如果合适,那就是另一个问题了。

代码语言:javascript
复制
spline_file <- read.table(text = "
                   1   0.157587435
                   2   0.146704412
                   3   0.129899285
                   4   0.138925582
                   5   0.104085676
                   ", stringsAsFactors = FALSE)
colnames(spline_file) <- c("x", "y")

spline_loess <- loess.smooth(spline_file$x, spline_file$y, span = 1, degree = 2, 
             family = c("gaussian")
             ,surface= "interpolate"
             , statistics = "exact"
             ) 

spline_loess
# $x
# [1] 1.000000 1.081633 1.163265 1.244898 1.326531 1.408163 1.489796
# [8] 1.571429 1.653061 1.734694 1.816327 1.897959 1.979592 2.061224
# [15] 2.142857 2.224490 2.306122 2.387755 2.469388 2.551020 2.632653
# [22] 2.714286 2.795918 2.877551 2.959184 3.040816 3.122449 3.204082
# [29] 3.285714 3.367347 3.448980 3.530612 3.612245 3.693878 3.775510
# [36] 3.857143 3.938776 4.020408 4.102041 4.183673 4.265306 4.346939
# [43] 4.428571 4.510204 4.591837 4.673469 4.755102 4.836735 4.918367
# [50] 5.000000
# 
# $y
# [1] 0.1586807 0.1571512 0.1556485 0.1541759 0.1527367 0.1513344
# [7] 0.1499721 0.1486533 0.1473813 0.1461595 0.1449911 0.1438795
# [13] 0.1428280 0.1417881 0.1406496 0.1394364 0.1381783 0.1369053
# [19] 0.1356473 0.1344341 0.1332957 0.1322619 0.1313626 0.1306278
# [25] 0.1300873 0.1297791 0.1297453 0.1299324 0.1302747 0.1307066
# [31] 0.1311626 0.1315769 0.1318839 0.1320181 0.1319138 0.1315054
# [37] 0.1307273 0.1295270 0.1281453 0.1266888 0.1251504 0.1235232
# [43] 0.1218002 0.1199744 0.1180388 0.1159866 0.1138105 0.1115038
# [49] 0.1090594 0.1064704

plot(spline_file)
lines(spline_loess) 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48926265

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档