Knitr(Rstudio)中的文本字符串:解析时出错

时间:2016-03-01 14:18:39

标签: r knitr r-markdown winbugs

我正在尝试使用knitr槽Rstudio来记录将文本字符串保存到* txt文件的模型。

执行此操作时,我收到此R markdown错误消息:

*Error in parse(text = x, srcfile = src) : <text>:2:24: unexpected 
INCOMPLETE_STRING 14: var.m <- 1/tau.m # between-trial variance 15: 
Calls: <Anonymous> ... <Anonymous> -> parse_all -> parse_all.character -> parse*

有人知道解决这个问题吗?

这个字符串工作正常:

  Modelstring.baseline = " Text goes here "

这个字符串工作正常:

Modelstring.baseline =  "

# Binomial likelihood, logit link, MTC
# Fixed effect model
#CV mortality

model{                                                                          # *** PROGRAM STARTS
  for(i in 1:ns){                                                                 # LOOP THROUGH STUDIES
    mu[i] ~ dnorm(0,.0001)                                                          # vague priors for all trial baselines
    for (k in 1:na[i]) {                                                            # LOOP THROUGH ARMS
      r[i,k] ~ dbin(p[i,k],n[i,k])                                                    # binomial likelihood
      logit(p[i,k]) <- mu[i] + d[t[i,k]]-d[t[i,1]]                                    # model for linear predictor
      rhat[i,k] <- p[i,k] * n[i,k]                                                    # expected value of the numerators
      dev[i,k] <- 2 * (r[i,k] * (log(r[i,k])-log(rhat[i,k]))                          # Deviance contribution
                       + (n[i,k]-r[i,k]) * (log(n[i,k]-r[i,k]) - log(n[i,k]-rhat[i,k])))
    }
    resdev[i] <- sum(dev[i,1:na[i]])                                                # summed residual deviance contribution for this trial
  }
  totresdev <- sum(resdev[])                                                          # Total Residual Deviance
  d[1]<- 0                                                                                # treatment effect is zero for reference treatment
  for (k in 2:nt)  { d[k] ~ dnorm(0,.0001) }                                      # vague priors for treatment effects
 "

Whiles此字符串生成解析器错误:

Modelstring.baseline = "

model{                                                                        # *** PROGRAM STARTS
  for (i in 1:ns)
    {                                                                   # LOOP THROUGH STUDIES
      r[i] ~ dbin(p[i],n[i])                                            # Likelihood
      logit(p[i]) <- mu[i]                                              # Log-odds of response
      mu[i] ~ dnorm(m,tau.m)                                          # Random effects model
    }

  mu.new ~ dnorm(m,tau.m)                                           # predictive dist. (log-odds)
  m ~ dnorm(0,.0001)                                                    # vague prior for mean
  var.m <- 1/tau.m                                                    # between-trial variance

#---Non-informative prior
  #tau.m <- pow(sd.m,-2)                                            
  #sd.m ~ dunif(0,5)

#---Vaguely informative prior
  #tau.m ~ dgamma(0.001,.001)                                           
  #sd.m ~ pow(tau.m,-0.5)

#---Informative prior R.M Turner et al LN(-3.95, 1.79)
  tau.m <- 1/tausq
  tausq ~ dlnorm(-3.95, 0.31) #0.31 = 1/(1.79*1.79)
} 
" 

0 个答案:

没有答案