1

概括:

我安装了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
4

2 回答 2

3

请测试这是否有效:

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

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

对我来说很好

于 2017-07-26T09:10:21.593 回答
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) 
于 2017-07-29T04:21:35.360 回答