我使用R构建一个基于代理的模型,使用蒙特卡罗过程.这意味着我有许多使用某种随机引擎的函数.为了获得可重复的结果,我必须修复种子.但是,据我所知,我必须在每个随机抽签或样本之前设置种子.这是一个真正的痛苦.有没有办法修理种子?
set.seed(123)
print(sample(1:10,3))
# [1] 3 8 4
print(sample(1:10,3))
# [1] 9 10 1
set.seed(123)
print(sample(1:10,3))
# [1] 3 8 4
Run Code Online (Sandbox Code Playgroud) 错误: Error in predmat[which, seq(nlami)] = preds : replacement has length zero
上下文:数据用二进制y模拟,但有n
编码器true y
.数据是叠加的n
时间,并且模型已经安装,试图获得true y
.
收到错误
L2
罚款,但不是L1
罚款.更新:错误是针对1.9-8之后的版本.1.9-8不会失败.
library(glmnet)
rm(list=ls())
set.seed(123)
num_obs=4000
n_coders=2
precision=.8
X <- matrix(rnorm(num_obs*20, sd=1), nrow=num_obs)
prob1 <- plogis(X %*% c(2, -2, 1, -1, rep(0, 16))) # yes many zeros, ignore
y_true <- rbinom(num_obs, 1, prob1)
dat <- data.frame(y_true = y_true, X = X)
Run Code Online (Sandbox Code Playgroud)
classify <- function(true_y,precision){
n=length(true_y) …
Run Code Online (Sandbox Code Playgroud) 这可能与类似的问题有点相反。我希望R在代码中的任何位置中止\警告,如果函数在父环境中使用了变量。是否有一些基本的选择可以实现?我想要一个会话通用的解决方案,而不是特定的检查。谢谢。