我正在寻找一种 RAM 有效的方法来在 data.table 的帮助下计算补集的中位数。
对于来自不同组的一组观察结果,我对“其他组”的中位数的实现感兴趣。即,如果一个 data.table 有一个值列和一个分组列,我想为每个组计算除当前组之外的所有其他组中值的中位数。例如,对于第 1 组,我们计算除属于第 1 组的值以外的所有值的中位数,依此类推。
一个具体的例子 data.table
dt <- data.table(value = c(1,2,3,4,5), groupId = c(1,1,2,2,2))
dt
# value groupId
# 1: 1 1
# 2: 2 1
# 3: 3 2
# 4: 4 2
# 5: 5 2
Run Code Online (Sandbox Code Playgroud)
我希望将medianOfAllTheOtherGroups 定义为第2 组的1.5 并定义第1 组的4,对同一data.table 中的每个条目重复:
dt <- data.table(value = c(1,2,3,4,5), groupId = c(1,1,2,2,2), medianOfAllTheOtherGroups = c(4, 4, 1.5, 1.5, 1.5))
dt
# value groupId medianOfAllTheOtherGroups …
Run Code Online (Sandbox Code Playgroud) 我在使用小鼠对缺失值进行插补后对纵向数据进行统计分析时遇到问题。在宽数据格式中对缺失进行插补后,我将提取的数据转换为长格式。由于纵向数据参与者有重复的行(3 个时间点),这会在将长格式数据集转换为类型 mids 对象时出现问题。有谁知道如何在插补后创建一个 mids 对象或其他合适的东西?之后我想使用 lmer,lme 来合并固定效果。我尝试了很多不同的东西,但仍然无法弄清楚。
提前致谢并查看以下代码:
# minimal reproducible example
## Make up some data
set.seed(2)
# ID Variable, Group, 3 Timepoints outcome measure (X1-X3)
Data <- data.frame(
ID = sort(sample(1:100)),
GROUP = sample(c(0, 1), 100, replace = TRUE),
matrix(sample(c(1:5,NA), 300, replace=T), ncol=3)
)
# install.packages("mice")
library(mice)
# Impute the data in wide format
m.out <- mice(Data, maxit = 5, m = 2, seed = 9, pred=quickpred(Data, mincor = 0.0, exclude = c("ID","GROUP"))) # ignore group here …
Run Code Online (Sandbox Code Playgroud) I have a dataset with survival data and a few missing covariates. I've successfully applied the mice-package to imputate m-numbers of datasets using the mice()
function, created an imputationList
object and applied a Cox PH model on each m-dataset. Subsequently I'ved pooled the results using the MIcombine()
function. This leads to my question:
How can I get a p-value for the pooled estimates for each covariate? Are they hidden somewhere within the MIcombine
object?
我知道 p 值并不是一切,但报告估计值和置信区间而没有相应的 p 值对我来说似乎很奇怪。我能够计算一个近似值。使用例如Altman …
我正在尝试使用 MICE 包在 R 中创建多个插补,但 kepp 内存不足。这是我收到的错误消息:
Error: cannot allocate vector of size 219 Kb
In addition: Warning messages:
1: In unlist(vlist, recursive = FALSE, use.names = FALSE) :
Reached total allocation of 6500Mb: see help(memory.size)
2: In unlist(vlist, recursive = FALSE, use.names = FALSE) :
Reached total allocation of 6500Mb: see help(memory.size)
Run Code Online (Sandbox Code Playgroud)
我使用 64 位 R 和 Windows 7 和 8 Gb ram。我试过增加 fysical 内存,并且允许内存大小 R 分别使用到 8 Gb 和 6.5 Gb,但它仍然不起作用。目前,我正在尝试对包含 27 000 行和 17 列的数据集进行插补,但我希望在具有 1 600 …
我有一个嵌套列表,看起来像这样:
characlist<-list(list(c(1,2,3,4)),c(1,3,2,NA))
Run Code Online (Sandbox Code Playgroud)
接下来,我想用NA替换所有等于1的值.我尝试了以下,但它产生了一个错误:
lapply(characlist,function(x) ifelse(x==1,NA,x))
Error in ifelse(x == 1, NA, x) :
(list) object cannot be coerced to type 'double'
Run Code Online (Sandbox Code Playgroud)
有人能告诉我代码有什么问题吗?
我有包中mod
的类变量,我需要向该类添加一个新属性:unmarkedFitPCount
unmarked
mod@new_attr <- 1
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
“new_attr”不是“unmarkedFitPCount”类中的插槽
我需要添加这个新属性而不创建新的派生类,因为我需要所有这些函数来处理这个对象。这应该只是一个非常轻量级的临时黑客。我怎样才能做到这一点?
我正在研究如何使用多重插补结果。以下是我的理解,如有错误请指出。
假设您有一个包含缺失值的数据集,并且您想要进行回归分析。您可以对 m = 5 次执行多重插补,并且对于每个插补数据集(现在有 5 个插补数据集)运行回归分析,然后通过 Rubin 规则(或使用 R)“汇集”这些 m = 5 模型的系数估计值包“池”)。
我的问题是,在小鼠中你有一个函数complete()
,并且手册说你可以使用 提取完整的数据集complete(object)
。
但是如果我使用 mouse m = 5 次,那么使用是否仍然有意义complete()
?complete()
我会得到哪些插补结果?
另外,如果我只使用 m = 1 的小鼠,这有意义吗?谢谢。
I have to do a topic modeling based on pieces of texts containing emojis with R. Using the replace_emoji()
and replace_emoticon
functions let me analyze them, but there is a problem with the results.
A red heart emoji is translated as "red heart ufef". These words are then treated separately during the analysis and compromise the results.
Terms like "heart" can have a very different meaning as can be seen with "red heart ufef" and "broken heart"
The function replace_emoji_identifier() …
我有这样的数据:
set.seed(1)
a <- pnorm(seq(-2, 2, 0.05))
a[7] <- NA
a[19:24] <- NA
a
# [1] 0.02275013 0.02558806 0.02871656 0.03215677 0.03593032 0.04005916
# [7] NA 0.04947147 0.05479929 0.06057076 0.06680720 0.07352926
#[13] 0.08075666 0.08850799 0.09680048 0.10564977 0.11506967 0.12507194
#[19] NA NA NA NA NA NA
#[25] 0.21185540 0.22662735 0.24196365 0.25784611 0.27425312 0.29115969
#[31] 0.30853754 0.32635522 0.34457826 0.36316935 0.38208858 0.40129367
#[37] 0.42074029 0.44038231 0.46017216 0.48006119 0.50000000 0.51993881
#[43] 0.53982784 0.55961769 0.57925971 0.59870633 0.61791142 0.63683065
#[49] 0.65542174 0.67364478 0.69146246 0.70884031 0.72574688 0.74215389
#[55] …
Run Code Online (Sandbox Code Playgroud) compute()
从neuralnet
R中的包运行时获取错误
它是否因为数据大小而发生?我无法弄清楚确切的问题.
df2 <- read.csv("data.csv")
train_df <- df2[1:3200,]
test_df <- df2[3201:4004,]
n <- names(train_df)
f <- as.formula(paste("tenure ~", paste(n[!n %in% "tenure"], collapse =
"+")))
model2 <- neuralnet(f,train_df, hidden=3, threshold=0.01, linear.output=T)
summary(model2)
#Output
Length Class Mode
call 6 -none- call
response 3200 -none- numeric
covariate 4118400 -none- numeric
model.list 2 -none- list
err.fct 1 -none- function
act.fct 1 -none- function
linear.output 1 -none- logical
data 1288 data.frame list
net.result 1 -none- list
weights 1 -none- list
startweights 1 …
Run Code Online (Sandbox Code Playgroud) r ×10
r-mice ×4
data.table ×1
emoji ×1
imputation ×1
median ×1
ram ×1
split ×1
statistics ×1
vector ×1