- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 R 的新手,我正在尝试将 smooth.spline()
应用于大型数据帧。我查看了相关线程(“将 n 个函数的列表应用于数据帧的每一行”,“如何应用样条基矩阵”,...)。这是我的数据框以及我迄今为止尝试过的内容:
> dim(mUnique)
[1] 4565 9
> str(mUnique)
'data.frame': 4565 obs. of 9 variables:
$ Group.1: Factor w/ 4565 levels "mal_mito_1","mal_mito_2",..: 1 2 3 4 5 6 7 8 9 10 ...
$ h0 : num 0.18 -0.025 0.212 0.015 0.12 ...
$ h6 : num -0.04 -0.305 -0.188 -0.185 -0.09 ...
$ h12 : num -0.86 -1.1 -1.01 -1.04 -0.91 ...
$ h18 : num -0.73 -1.215 -1.222 -0.355 -0.65 ...
$ h24 : num 0.04 0.025 -0.143 0.295 0.09 ...
$ h30 : num -0.14 1.275 0.732 -0.015 -0.27 ...
$ h36 : num 1.44 1.795 1.627 0.385 0.91 ...
$ h42 : num 1.49 1.385 1.397 0.305 1.12 ...
> head(mUnique)
ID h0 h6 h12 h18 h24 h30 h36 h42
1 mal_mito_1 0.1800 -0.0400 -0.8600 -0.7300 0.0400 -0.1400 1.4400 1.4900
2 mal_mito_2 -0.0250 -0.3050 -1.1050 -1.2150 0.0250 1.2750 1.7950 1.3850
3 mal_mito_3 0.2125 -0.1875 -1.0075 -1.2225 -0.1425 0.7325 1.6275 1.3975
4 mal_rna_10_rRNA 0.0150 -0.1850 -1.0450 -0.3550 0.2950 -0.0150 0.3850 0.3050
5 mal_rna_11_rRNA 0.1200 -0.0900 -0.9100 -0.6500 0.0900 -0.2700 0.9100 1.1200
6 mal_rna_14_rRNA 0.0200 -0.0200 -0.8400 -0.6600 0.1700 -0.0900 0.6200 0.0800
smooth.spline
,到目前为止它看起来不错(我想要 48 分。我稍后会弄清楚如何使用
spline()
smoooth.spline
):
> time <- c(0,6,12,18,24,30,36,42)
> plot(time, mUnique[1, 2:9])
> smooth <- smooth.spline(time, mUnique[1, 2:9])
> lines(smooth, col="blue")
> splin <-spline(time, mUnique[1, 2:9], n=48)
> lines(splin, col="blue")
spar
或
smooth.spline()
应用于整个数据帧,并返回一个矩阵 4565 * 49,其中我有平滑样条曲线的每个节点的坐标?我真的不在乎绘制这些数据。
> smooth <- smooth.spline(time, mUnique[, 2:9]|factor(ID))
最佳答案
使用对象 dat
中的数据片段,我们可以做(我认为)你想做的事情。首先,我们编写了一个小包装函数,通过 smooth.spline()
拟合平滑样条,然后预测来自该样条的一组 n
位置的响应。您要求提供 n = 48
,因此我们将使用它作为默认值。
这是一个这样的包装函数:
SSpline <- function(x, y, n = 48, ...) {
## fit the spline to x, and y
mod <- smooth.spline(x, y, ...)
## predict from mod for n points over range of x
pred.dat <- seq(from = min(x), to = max(x), length.out = n)
## predict
preds <- predict(mod, x = pred.dat)
## return
preds
}
> res <- SSpline(time, dat[1, 2:9])
> res
$x
[1] 0.000000 0.893617 1.787234 2.680851 3.574468 4.468085 5.361702
[8] 6.255319 7.148936 8.042553 8.936170 9.829787 10.723404 11.617021
[15] 12.510638 13.404255 14.297872 15.191489 16.085106 16.978723 17.872340
[22] 18.765957 19.659574 20.553191 21.446809 22.340426 23.234043 24.127660
[29] 25.021277 25.914894 26.808511 27.702128 28.595745 29.489362 30.382979
[36] 31.276596 32.170213 33.063830 33.957447 34.851064 35.744681 36.638298
[43] 37.531915 38.425532 39.319149 40.212766 41.106383 42.000000
$y
[1] 0.052349585 0.001126837 -0.049851737 -0.100341294 -0.150096991
[6] -0.198873984 -0.246427429 -0.292510695 -0.336721159 -0.378381377
[11] -0.416785932 -0.451229405 -0.481006377 -0.505411429 -0.523759816
[16] -0.535714043 -0.541224748 -0.540251293 -0.532753040 -0.518689349
[21] -0.498019582 -0.470750611 -0.437182514 -0.397727107 -0.352796426
[26] -0.302802508 -0.248157388 -0.189272880 -0.126447574 -0.059682959
[31] 0.011067616 0.085850805 0.164713260 0.247701633 0.334851537
[36] 0.425833795 0.519879613 0.616194020 0.713982047 0.812448724
[41] 0.910799082 1.008296769 1.104781306 1.200419068 1.295380186
[46] 1.389834788 1.483953003 1.577904960
> plot(time, dat[1, 2:9])
> lines(res, col = "blue")
$y
返回的对象的
SSpline()
组件。为此,我们使用
apply()
:
> res2 <- apply(dat[, 2:9], 1,
+ function(y, x, ...) { SSpline(x, y, ...)$y },
+ x = time)
> head(res2)
1 2 3 4 5 6
[1,] 0.052349585 -0.02500000 0.21250000 -0.06117869 -0.02153366 -0.02295792
[2,] 0.001126837 -0.04293509 0.17175460 -0.10994988 -0.06538250 -0.06191095
[3,] -0.049851737 -0.06407856 0.12846458 -0.15838412 -0.10899505 -0.10074427
[4,] -0.100341294 -0.09168227 0.08005550 -0.20614476 -0.15213426 -0.13933920
[5,] -0.150096991 -0.12899810 0.02395291 -0.25289514 -0.19456304 -0.17757705
[6,] -0.198873984 -0.17927793 -0.04241763 -0.29829862 -0.23604434 -0.21533911
res2
包含 48 行 6 列,6 列是指这里使用的
dat
的每一行。如果你想反过来,只需转置
res2
:
t(res2)
。
matplot()
调用来查看已经完成的操作:
> matplot(x = seq(min(time), max(time), length = 48),
+ y = res2, type = "l")
关于r - 如何将 spline() 应用于大型数据帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5470983/
初学者 android 问题。好的,我已经成功写入文件。例如。 //获取文件名 String filename = getResources().getString(R.string.filename
我已经将相同的图像保存到/data/data/mypackage/img/中,现在我想显示这个全屏,我曾尝试使用 ACTION_VIEW 来显示 android 标准程序,但它不是从/data/dat
我正在使用Xcode 9,Swift 4。 我正在尝试使用以下代码从URL在ImageView中显示图像: func getImageFromUrl(sourceUrl: String) -> UII
我的 Ubuntu 安装 genymotion 有问题。主要是我无法调试我的数据库,因为通过 eclipse 中的 DBMS 和 shell 中的 adb 我无法查看/data/文件夹的内容。没有显示
我正在尝试用 PHP 发布一些 JSON 数据。但是出了点问题。 这是我的 html -- {% for x in sets %}
我观察到两种方法的结果不同。为什么是这样?我知道 lm 上发生了什么,但无法弄清楚 tslm 上发生了什么。 > library(forecast) > set.seed(2) > tts lm(t
我不确定为什么会这样!我有一个由 spring data elasticsearch 和 spring data jpa 使用的类,但是当我尝试运行我的应用程序时出现错误。 Error creatin
在 this vega 图表,如果我下载并转换 flare-dependencies.json使用以下 jq 到 csv命令, jq -r '(map(keys) | add | unique) as
我正在提交一个项目,我必须在其中创建一个带有表的 mysql 数据库。一切都在我这边进行,所以我只想检查如何将我所有的压缩文件发送给使用不同计算机的人。基本上,我如何为另一台计算机创建我的数据库文件,
我有一个应用程序可以将文本文件写入内部存储。我想仔细看看我的电脑。 我运行了 Toast.makeText 来显示路径,它说:/数据/数据/我的包 但是当我转到 Android Studio 的 An
我喜欢使用 Genymotion 模拟器以如此出色的速度加载 Android。它有非常好的速度,但仍然有一些不稳定的性能。 如何从 Eclipse 中的文件资源管理器访问 Genymotion 模拟器
我需要更改 Silverlight 中文本框的格式。数据通过 MVVM 绑定(bind)。 例如,有一个 int 属性,我将 1 添加到 setter 中的值并调用 OnPropertyChanged
我想向 Youtube Data API 提出请求,但我不需要访问任何用户信息。我只想浏览公共(public)视频并根据搜索词显示视频。 我可以在未经授权的情况下这样做吗? 最佳答案 YouTube
我已经设置了一个 Twilio 应用程序,我想向人们发送更新,但我不想回复单个文本。我只是想让他们在有问题时打电话。我一切正常,但我想在发送文本时显示传入文本,以确保我不会错过任何问题。我正在使用 p
我有一个带有表单的网站(目前它是纯 HTML,但我们正在切换到 JQuery)。流程是这样的: 接受用户的输入 --- 5 个整数 通过 REST 调用网络服务 在服务器端运行一些计算...并生成一个
假设我们有一个名为 configuration.js 的文件,当我们查看内部时,我们会看到: 'use strict'; var profile = { "project": "%Projec
这部分是对 Previous Question 的扩展我的: 我现在可以从我的 CI Controller 成功返回 JSON 数据,它返回: {"results":[{"id":"1","Sourc
有什么有效的方法可以删除 ios 中 CBL 的所有文档存储?我对此有疑问,或者,如果有人知道如何从本质上使该应用程序像刚刚安装一样,那也会非常有帮助。我们正在努力确保我们的注销实际上将应用程序设置为
我有一个 Rails 应用程序,它与其他 Rails 应用程序通信以进行数据插入。我使用 jQuery $.post 方法进行数据插入。对于插入,我的其他 Rails 应用程序显示 200 OK。但在
我正在为服务于发布请求的 API 调用运行单元测试。我正在传递请求正文,并且必须将响应作为帐户数据返回。但我只收到断言错误 注意:数据是从 Azure 中获取的 spec.js const accou
我是一名优秀的程序员,十分优秀!