readRDS(file.rds)出错

时间:2017-07-26 07:28:01

标签: r bayesian rstan

要点:

我安装了 rstan 包,现在我遇到了这个错误:

  

readRDS(file.rds)出错:未知输入格式

说明

> traceback()
5: readRDS(file.rds)
4: is(obj <- readRDS(file.rds), "stanmodel")
3: stan_model(file, model_name = model_name, model_code = model_code,
stanc_ret = NULL, boost_lib = boost_lib, eigen_lib = eigen_lib,
save_dso = save_dso, verbose = verbose)
2: stan(file = fName, data = datalist, init = list(inlist), chains = 1,
iter = n.it, pars = c("f", "tau"), warmup = n.warm, seed = computerID +
1000) at functions.r#131
1: RunModel(11, myT, nu, lambda, rho, BDRi, Pars, computerID, n.it,
n.warm, getwd())

环境:

  • RStan版本:2.16.2
  • R版本3.4.1(2017-06-30)
  • 操作系统:Windows 10

2 个答案:

答案 0 :(得分:1)

请测试这是否有效:

install.packages('rstan')
library(rstan)

saveRDS(mtcars, file = 'test.rds')
readRDS('test.rds')

适合我的工作

答案 1 :(得分:0)

我的问题解决了。我使用 writeLines 命令。

library(rstan)
scode <- "
     parameters {
       real y[2]; 
     } 
     model {
       y[1] ~ normal(0, 1);
       y[2] ~ double_exponential(0, 2);
     } 
     "
writeLines(scode, "mymodel.stan")

mymodel <- stan("mymodel.stan", iter = 10, verbose = FALSE)