首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于示例数据集的r包(基线)应用程序

用于示例数据集的r包(基线)应用程序
EN

Stack Overflow用户
提问于 2016-05-20 12:38:30
回答 1查看 1.2K关注 0票数 1

我正在尝试使用我所拥有的样本数据集上的R基线包来测试和评估我所拥有的当前基线算法。

我想应用填充峰算法作为趋势线进行比较。

代码语言:javascript
复制
bc.fillPeaks <- baseline(milk$spectra[1, drop=FALSE], lambda=6,
                         hwi=50, it=10, int=2000, method="fillPeaks")
plot(bc.fillPeaks)

但我的问题是,我所拥有的样本数据不符合本例中使用的矩阵结构。当我看这个例子所用的data.frame时,我不明白

代码语言:javascript
复制
'data.frame':   45 obs. of  2 variables
 $ cow    : num  0 0.25 0.375 0.875 0.5 0.75 0.5 0.125 0 0.125 ...
 $ spectra: num [1:45, 1:21451] 1029 371 606 368 554 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr  "4999.94078628963" "5001.55954267662" "5003.17856106153" "5004.79784144435" ...
 - attr(*, "terms")=Classes 'terms', 'formula' length 3 cow ~ spectra
  .. ..- attr(*, "variables")= language list(cow, spectra)
  .. ..- attr(*, "factors")= int [1:2, 1] 0 1
  .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. ..$ : chr [1:2] "cow" "spectra"
  .. .. .. ..$ : chr "spectra"
  .. ..- attr(*, "term.labels")= chr "spectra"
  .. ..- attr(*, "order")= int 1
  .. ..- attr(*, "intercept")= int 1
  .. ..- attr(*, "response")= int 1
  .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv> 
  .. ..- attr(*, "predvars")= language list(cow, spectra)
  .. ..- attr(*, "dataClasses")= Named chr [1:2] "numeric" "nmatrix.21451"
  .. .. ..- attr(*, "names")= chr [1:2] "cow" "spectra"

因此,我的问题是,你们中的任何人是否有使用基准包和数据集(牛奶)的经验,以及如何转换我的数据集,这些数据集是结构化的:日期、访问、Old_baseline_visits来拟合和测试R-包中的基线算法。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-20 16:01:14

我使用了基线,一开始我发现它有点混乱,特别是示例数据。正如它在帮助文件中所说的那样,基线期望得到一个矩阵,其中的谱是行的。即使只有一个“谱”,它也需要以单行矩阵的形式出现。试试这个:

代码语言:javascript
复制
foo <- data.frame(Date=seq.Date(as.Date("1957-01-01"), by = "day", 
                            length.out = ncol(milk$spectra)),
              Visits=milk$spectra[1,],
              Old_baseline_visits=milk$spectra[1,], row.names = NULL)
foo.t <- t(foo$Visits) # Visits in a single row matrix 
bc.fillPeaks <- baseline(foo.t, lambda=6,
                     hwi=50, it=10, int=2000, method='fillPeaks')
plot(bc.fillPeaks)

如果要将基线和校正后的光谱返回到原始数据框架中,请尝试如下:

代码语言:javascript
复制
foo$New_baseline <- c(getBaseline(bc.fillPeaks))
foo$New_corrected <- c(getCorrected(bc.fillPeaks))
plot(foo$Date, foo$New_corrected, "l")

或者,如果您不需要基线对象,可以使用baseline.fillPeaks(),它返回一个列表。

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

https://stackoverflow.com/questions/37346967

复制
相关文章

相似问题

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