run.jags(runjags)
run.jags()所属R语言包:runjags
Run a User Specified Bayesian MCMC Model in JAGS from Within R
运行用户指定的贝叶斯MCMC模型在R在JAGS从
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Runs a user specified JAGS (similar to WinBUGS) model from within R, returning a list of the MCMC chain(s) along with convergence diagnostics, autocorrelation diagnostics and monitored variable summaries. Data and initial values can either be supplied in the R dump format (see dump.format() for an easy way to do this), or as a named list. A character vector of variables to monitor must also be supplied.
运行一个用户指定的模型从在R JAGS(类似于WinBUGS类),返回一个列表的MCMC链(),沿与的收敛诊断,自相关的诊断和监视的变量摘要。可以提供数据和初始值的R转储文件格式(见dump.format()的一个简单的方法来做到这一点),或命名列表。监视的变量,必须同时提供一个字符向量。
Requires Just Another Gibbs Sampler (JAGS), see http://www-fis.iarc.fr/~martyn/software/jags/. The GUI interface for R in Windows may not continually refresh the output window, making it difficult to track the progress of the simulation (if silent.jags is FALSE). To avoid this, you can run the function from the terminal version of R (located in the Program Files/R/bin/ folder).
只是另一个需要吉布斯的采样(JAGS)中,看到http://www-fis.iarc.fr/~:马丁/软件/ JAGS /。在Windows的GUI界面的R可能不会持续刷新输出窗口,使其难以跟踪的仿真(如果silent.jags是FALSE)的进展情况。为了避免这种情况,你可以运行的功能和终端版本的R(在Program Files / R / BIN /文件夹)。
用法----------Usage----------
run.jags(model=stop("No model supplied"),
monitor = stop("No monitored variables supplied"), data=NA, n.chains=2,
inits = replicate(n.chains, NA), burnin = 5000*thin,
sample = 10000*thin, adapt=if(burnin<200) 100 else 0, jags = findjags(),
silent.jags = FALSE, check.conv = TRUE, plots = TRUE,
psrf.target = 1.05, normalise.mcmc = TRUE, check.stochastic = TRUE,
modules=c(""), factories=c(""), thin = 1, monitor.deviance = FALSE,
monitor.pd = FALSE, monitor.pd.i = FALSE, monitor.popt = FALSE,
keep.jags.files = FALSE, tempdir=TRUE, method=if(.Platform$OS.type=='unix'
& .Platform$GUI!="AQUA" & Sys.info()['user']!='nobody') 'interruptible'
参数----------Arguments----------
参数:model
a character string of the model in the JAGS language. No default.
模型在JAGS语言的字符串。无默认值。
参数:monitor
a character vector of the names of variables to monitor. For all models, specifying 'deviance' as a monitored variable implies monitor.deviance, and 'dic' will calculate the Deviance Information Criterion (implies monitor.deviance/monitor.pd/monitor.popt and requires more than 1 chain). No default.
字符向量的变量名进行监控。对于所有型号,指定为被监视的变量的“越轨行为”意味着monitor.deviance,“DIC”,将计算的越轨行为标准(意味着monitor.deviance / monitor.pd / monitor.popt和需要超过1链)。无默认值。
参数:data
a character string in the R dump format (or a named list) containing the data. If left as NA, no external data is used in the model. Default NA.
在R转储文件格式的字符串(或命名列表)包含的数据。如果保留为NA,没有外部的数据在模型中使用。默认情况下不适用。
参数:n.chains
the number of chains to use for the simulation. Must be a positive integer. Default 2.
用于模拟的链的数目。必须是一个正整数。默认值2。
参数:inits
either a character vector with length equal to the number of chains the model will be run using, or a list of named lists representing names and corresponding values of inits for each chain. If a vector, each element of the vector must be a character string in the R dump format representing the initial values for that chain, or NA. If not all initialising variables are specified, the unspecified variables are sampled from the prior distribution by JAGS. Values left as NA result in all initial values for that chain being sampled from the prior distribution. The special variables '.RNG.seed', '.RNG.name', and '.RNG.state' are allowed for explicit control over random number generators in JAGS. Default NA.
长度等于链的数目可以是字符向量模型将使用运行,或命名列表代表每个链的初始化设置的名称和相应的值的列表。如果一个矢量,该矢量的每个元素必须是一个字符串在的R转储格式表示的初始值,该供应链,或NA。如果不是所有的初始化变量指定,未指定的变量进行采样,从先验分布JAGS。值,NA的结果,在所有的初始值链采样的先验分布。特殊的变量。RNG.seed,。RNG.name“,和”。RNG.state允许随机数生成器在JAGS明确的控制。默认情况下不适用。
参数:burnin
the number of burnin iterations (not sampled) to use (numeric). Default 5000 iterations.
燃尽的迭代数(不采样),使用(数字)。缺省值5000迭代。
参数:sample
the number of sampling iterations to use (numeric). Default 10000 iterations.
采样迭代使用的数量(数字)。缺省值10000迭代。
参数:adapt
advanced option to control the length of the adaptive phase directly, which is otherwise half the length of the burnin period. Default is 0, unless burnin is less than 200 in which case 100 adapitve iterations are used.
的自适应相位控制的长度直接否则燃尽的期间的长度的一半,这是的高级选项。缺省值是0,除非燃尽的是小于200,在这种情况下,使用100 adapitve迭代。
参数:jags
the system call or path for activating JAGS. Default calls findjags() to attempt to locate JAGS on your system.
用于激活JAGS的系统调用或路径。默认调用findjags()到试图找到JAGS,在您的系统上。
参数:silent.jags
should the JAGS output be suppressed? (logical) If TRUE, no indication of the progress of individual models is supplied. Default FALSE.
的JAGS输出被抑制? (逻辑)如果为true,没有迹象显示个别型号的进展提供。默认为false。
参数:check.conv
should the convergence be assessed after the model has completed? If TRUE, each monitored variable will be assessed for a potential scale reduction factor of the Gelman Rubin statistic of less than 1.05, which indicates adequate convergence. 2 or more chains are required to assess convergence. Default TRUE.
应该收敛后的模型进行评估,已完成?如果是TRUE,每个被监视的变量将被评估的潜在规模减少的因素格尔曼·鲁宾统计小于1.05,这表明适当的收敛。需要2个或更多的链,以评估收敛。默认为true。
参数:plots
should traceplots and density plots be produced for each monitored variable? If TRUE, the returned list will include elements 'trace' and 'density' which consist of a list of lattice objects. The alternative is to use plot(results$mcmc) to look at the density and traceplots for each variable using the traditional graphics system. Default TRUE.
traceplots和密度图应该为每个受监控的变量?如果是TRUE,返回的列表将包含元素的“跟踪”和“密度”,其中包括格对象的列表。另一种方法是使用图(结果$ MCMC)看的的密度和traceplots为每个变量使用传统的图形系统。默认为true。
参数:psrf.target
the value of the point estimate for the potential scale reduction factor of the Gelman Rubin statistic below which the chains are deemed to have converged (must be greater than 1). Ignored if check.conv==FALSE. Default 1.05.
格尔曼·鲁宾统计的潜在规模折减系数的点估计值,低于该链被视为融合(必须大于1)。如果忽略check.conv == FALSE。默认值是1.05。
参数:normalise.mcmc
the Gelman Rubin statistic is based on the assumption that the posterior distribution of monitored variables is roughly normal. For very skewed posterior distributions, it may help to log/logit transform the posterior before calculating the Gelman Rubin statistic. If normalise.mcmc == TRUE, the normality of the untransformed and log/logit transformed posteriors are compared for each monitored variable and the least skewed is used to calculate the Gelman Rubin statistic. If FALSE, the data are left untransformed (this may give problems calculating the statistic in extreme cases). Ignored if check.conv==FALSE. Default TRUE.
格尔曼鲁宾统计是根据的假设上,被监视的变量的后验分布大约是正常。对于非常倾斜的后验分布,它可能会帮助,登录/罗吉特改造后,然后再计算格尔曼·鲁宾统计。如果normalise.mcmc == TRUE,的正常的未转化的和对数/罗吉特变换后验相比,对于每个被监视的变量和至少歪斜被用来计算吉尔曼鲁宾统计。如果为FALSE,数据被留下未转化的(这可能会在极端的情况下,计算的统计量的问题)。如果忽略check.conv == FALSE。默认为true。
参数:check.stochastic
non-stochastic monitored variables will cause errors when calculating the Gelman-Rubin statistic, if check.stochastic==TRUE then all monitored variables will be checked to ensure they are stochastic beforehand. This has a computational cost, and can be bypassed if check.stochastic==FALSE. Default TRUE.
非随机监视的变量时,将导致错误计算的格尔曼鲁宾统计,如果check.stochastic == TRUE,那么所有被监视的变量进行检查,以确保它们是随机的事先。这有一个计算成本,并且可以被旁路如果check.stochastic == FALSE。默认为true。
参数:modules
external modules to be loaded into JAGS. More than 1 module can be used. Default none.
被加载到JAGS外部模块。模块可用于超过1。默认没有。
参数:factories
factory modules to be loaded into JAGS. More than 1 factory can be used. Entried should be in the format '"<facname>" <status>, type(<factype>)', for example: factories='"mix::TemperedMix" off, type(sampler)'. Default none.
工厂模块要被装入到JAGS。工厂可用于超过1。 Entried应该是在格式“<facname>”<状态>,的类型(<factype>)“,例如:工厂=的”混合:: TemperedMix“关,类型(取样)”。默认没有。
参数:thin
the thinning interval to be used in JAGS. Increasing the thinning interval may reduce autocorrelation, and therefore reduce the number of samples required, but will increase the time required to run the simulation. Default 1.
中要使用JAGS变薄间隔。增加变薄间隔可能减少自相关,并因此减少了所需的样本数,但会增加所需要的时间来运行仿真。默认值1。
参数:monitor.deviance
option to monitor the total deviance of the model using the DIC module in JAGS. If TRUE, an additional monitor called 'deviance' is added to the MCMC objects returned, representing the deviance of the model for each iteration and each chain. This option requires JAGS version 2 or greater. For more information see the JAGS user manual. Default FALSE.
总偏差的模型中使用的DIC模块JAGS选项来监控。如果是TRUE,称为越轨被添加到一个附加的监视器的MCMC返回的对象,表示为每次迭代的模型和每个链越轨。此选项需要JAGS版本2或更高。欲了解更多信息,请参阅用户手册的JAGS。默认为false。
参数:monitor.pd
option to monitor the total effective number of parameters in the model using the DIC module for JAGS. If TRUE, a 'pd' element is returned representing the total effective number of parameters at each iteration. This option requires JAGS version 2 or greater and at least 2 chains. For more information see the JAGS user manual. Default FALSE.
选项来监控模型中使用的DIC模块JAGS总有效数中的参数。如果是TRUE,PD元素返回的参数在每次迭代总有效数。此选项需要JAGS版本为2或更大和至少2个链。欲了解更多信息,请参阅用户手册的JAGS。默认为false。
参数:monitor.pd.i
option to monitor the contribution of each parameter towards the total effective number of parameters using the DIC module for JAGS. If TRUE, a 'pd.i' element is returned representing the mean value for each parameter. This option requires JAGS version 2 or greater and at least 2 chains. For more information see the JAGS user manual. Default FALSE.
选项来监控各参数对总有效数的参数使用DIC模块JAGS的贡献。如果是TRUE,pd.i元素被表示为每个参数的平均值返回。此选项需要JAGS版本为2或更大和至少2个链。欲了解更多信息,请参阅用户手册的JAGS。默认为false。
参数:monitor.popt
option to monitor the optimism of the expected deviance using the DIC module for JAGS. If TRUE, a 'popt' element is returned representing the mean value for each parameter. This option requires JAGS version 2 or greater and at least 2 chains. For more information see the JAGS user manual. Default FALSE.
选项监控乐观的预期偏差DIC模块JAGS。如果设置为TRUE,返回一个POPT元素表示为每个参数的平均值。此选项需要JAGS版本为2或更大和至少2个链。欲了解更多信息,请参阅用户手册的JAGS。默认为false。
参数:keep.jags.files
option to keep the folder with files needed to call JAGS, rather than deleting it. May be useful for attempting to bug fix models. Default FALSE.
选择保持文件的文件夹,需要调用,而不是删除它JAGS。可能是有益的尝试错误修正模型。默认为false。
参数:tempdir
option to use the temporary directory as specified by the system rather than creating files in the working directory. If keep.jags.files==TRUE then the folder is copied to the working directory after the job has finished (with a unique folder name based on 'runjagsfiles'). Any files created in the temporary directory are removed when the function exits for any reason. Default TRUE.
选项使用指定的临时目录,而不是建立在工作目录中的文件系统。如果keep.jags.files == TRUE,然后将文件夹复制到工作目录后的工作已经完成了一个独特的文件夹名称根据“runjagsfiles”。在临时目录中创建的任何文件被删除,退出函数时的任何理由。默认为true。
参数:method
the method with which to call JAGS; one of 'simple', 'interruptible' or 'parallel'. The former runs JAGS as a foreground process (the default behaviour for runjags < 0.9.6), 'interruptible' allows the JAGS process to be terminated immediately using the interrupt signal 'control-c' (terminal/console versions of R only), and 'parallel' runs each chain as a separate process on a separate core. Note that the latter uses separate JAGS instances to speed up execution of models with multiple chains (at the expense of using more RAM), but cannot be used with monitor.pd, monitor.pd.i or monitor.popt. Each chain is specified using a different random number generator (.RNG.name) for up to 4 chains (the number of different RNG available in JAGS), unless .RNG.name is specified in the initial values. Because each chain uses a separate JAGS instance, JAGS has no way of ensuring independence between multiple chains using the same random number generator (as would normally be done when calling a single JAGS instance with multiple chains). Using more than 4 chains with the 'parallel' method without the use of new RNG factories may therefore produce dependence between chains, and is not recommended (a warning is given if trying to do so). Only the 'simple' method is available for Windows. On machines running Mac OS X and with access to an Apple Xgrid cluster, the method may be a list with an element 'xgrid.method="simple"' (see xgrid.run.jags for more information). Default 'interruptible' on terminal/console versions of R, or 'simple' on GUI versions of R or when running over xgrid (methods other than 'simple' require the use of 'ps' which is not available when running jobs as 'nobody' via xgrid).
打检测JAGS的方法,一个简单,中断或水货。前者运行JAGS作为一个前台进程(runjags <0.9.6的默认行为),“中断”允许的JAGS过程将立即终止使用的中断信号的控制C(仅R的终端/主机版本) ,水货运行的每一条链作为一个单独的进程在一个单独的核心。请注意,后者使用单独JAGS的实例来加快执行速度的模型与多个链(在使用更多的RAM的费用),但不能用于与monitor.pd,monitor.pd.i或monitor.popt。每个链指定使用一个不同的随机数发生器(。RNG.name)最多至4个链(的RNG在JAGS提供不同数量的),,除非。RNG.name指定在初始值。因为每个链使用一个单独的JAGS实例,JAGS有没有办法确保多个链,使用相同的随机数发生器(如时,通常会通过调用一个单一JAGS实例与多个链)之间的独立性。使用超过4链水货的方法,而无需使用新的RNG工厂可能会因此产生依赖关系链,不推荐(警告如果试图这样做)。只有“简单”的方法,是适用于Windows。机器上运行Mac OS X和一个苹果利用Xgrid聚类,该方法可能是一个列表元素xgrid.method =“简单”(见xgrid.run.jags的详细信息)。终端/主机版本的R默认的中断“,或”简单“的GUI版本的R或运行时超过XGRID(需要使用其他方法比”简单“的”PS“,这是不是正在运行的作业时,”人“通过XGRID)。
参数:batch.jags
option to call JAGS in batch mode, rather than using input redirection. On JAGS >= 3.0.0, this suppresses output of the status which may be useful in some situations. Default TRUE if silent.jags is TRUE, or FALSE otherwise.
选项打检测JAGS在批处理模式下,而不是使用输入重定向。论JAGS> = 3.0.0,这抑制输出的状态,在某些情况下,这可能是有用的。默认为true,如果silent.jags是TRUE,否则返回FALSE。
值----------Value----------
The results of the simulation are returned as list including the following items (omitting some items if check.conv==FALSE):
仿真结果包括以下项目(忽略了一些项目,如果check.conv == FALSE)返回的列表:
<table summary="R valueblock"> <tr valign="top"><td>mcmc</td> <td> an MCMC list of MCMC objects representing the chains. Each MCMC object represents the value of each monitored variable (including the deviance, if specified) for that chain at each iteration.</td></tr>
<table summary="R valueblock"> <tr valign="top"> <TD>mcmc</ TD> <TD> MCMC列表中的的MCMC对象代表的链。每个的MCMC对象代表每个被监视的变量(包括越轨行为,如果指定的话),在每次迭代链的价值。</ TD> </ TR>
<tr valign="top"><td>end.state</td> <td> a character vector of length equal to the number of chains representing a description of the model state in the R dump format for each chain at the last iteration. This can be used as an initial values vector to restart a new simulation in the same place as the previous simulation ended.</td></tr>
<tr valign="top"> <TD> end.state </ TD> <td>一个字符向量的长度等于每个链链表示在R模型的状态转储文件格式的描述数在最后一次迭代。这可以被用来作为一个初始值向量重新启动一个新的仿真,在同一个地方,作为以前的模拟结束。</ TD> </ TR>
<tr valign="top"><td>burnin</td> <td> number of burnin iterations discarded before sampling.</td></tr>
<tr valign="top"> <TD> burnin </ TD> <TD>数量的燃尽的迭代之前丢弃采样。</ TD> </ TR>
<tr valign="top"><td>sample</td> <td> number of sampled iterations.</td></tr>
<tr valign="top"> <TD> sample </ TD>的采样迭代<TD>数。</ TD> </ TR>
<tr valign="top"><td>thin</td> <td> the thinning interval in JAGS used for the chains.</td></tr>
<tr valign="top"> <TD> thin</ TD> <TD>的间伐间隔在JAGS使用的枷锁。</ TD> </ TR>
<tr valign="top"><td>summary</td> <td> the summary of each monitored variable from the combined chains, equivalent to summary(combine.mcmc(mcmc, collapse.chains=TRUE)).</td></tr>
<tr valign="top"> <TD> summary </ TD> <TD>总结每个被监视的变量合并链,相当于总结(combine.mcmc(MCMC,collapse.chains“= TRUE) )</ TD> </ TR>
<tr valign="top"><td>HPD</td> <td> the 95% highest posterior density and median value of each monitored variable from the combined chains.</td></tr>
<tr valign="top"> <TD> HPD </ TD> <TD> 95%的最高后验概率密度和每个被监视的变量中值的组合链。</ TD> </ TR>
<tr valign="top"><td>psrf</td> <td> the output of the Gelman Rubin dignostic (similar [but not exactly equivalent] to gelman.diag(mcmc)).</td></tr>
<tr valign="top"> <TD> psrf </ TD> <TD>的输出的格尔曼·鲁宾dignostic(类似[但不完全等同]到gelman.diag(MCMC))。</ TD > </ TR>
<tr valign="top"><td>autocorr</td> <td> the output of the autocorrelation diagnostic (equivalent to autocorr.diag(mcmc)).</td></tr>
<tr valign="top"> <TD> autocorr </ TD> <TD>输出的自相关诊断(相当于autocorr.diag(MCMC))。</ TD> </ TR>
<tr valign="top"><td>trace</td> <td> a list of lattice objects representing traceplots for each monitored variable, of class 'plotindpages'. Calling each individual element will result in the traceplot for that variable being shown, calling the entire list will result in all traceplots being shown in new windows (which may cause problems with your R session if there are several monitored variables). To override the individual window plotting behaviour (to combine plots and/or save the plots to a file), either change the class of each object using for(i in 1:nvar(results$mcmc)) class(results$trace[[i]]) <- 'trellis' and then combine using the c.trellis method in the latticeExtra package, or simply re-generate the plots using the raw mcmc output. Not produced if plots==FALSE.</td></tr>
<tr valign="top"> <TD>trace</ TD> <td>一个列表格对象,为每个受监控的变量,traceplots类的plotindpages“。调用每个元素正在显示该变量的traceplot,将导致调用的完整列表,将导致在新的Windows(R会话可能会产生问题,如果有几个监视的变量)显示所有traceplots。要覆盖各个窗口绘制的行为(结合图和/或保存到一个文件中的图),可以更改类的每个对象(我在1 nvar的(结果$ MCMC))类(结果$跟踪[ ]])< - “网格”,然后使用c.trellis在latticeExtra包的方法相结合,或简单地重新使用的原料MCMC输出生成的图。不生产,如果图== FALSE。</ TD> </ TR>
<tr valign="top"><td>density</td> <td> a list of lattice objects representing density plots for each monitored variable, of class 'plotindpages'. Calling each individual element will result in the density plot for that variable being shown, calling the entire list will result in all density plots being shown in new windows (which may cause problems with your R session if there are several monitored variables). To override the individual window plotting behaviour (to combine plots and/or save the plots to a file), either change the class of each object using for(i in 1:nvar(results$mcmc)) class(results$density[[i]]) <- 'trellis' and then combine using the c.trellis method in the latticeExtra package, or simply re-generate the plots using the raw mcmc output. Not produced if plots==FALSE.</td></tr>
<tr valign="top"> <TD> density</ TD> <TD>密度图中每个被监视的变量,类的plotindpages“格对象的列表。调用每个元素将导致该变量的密度图的显示,呼叫将导致整个列表密度图显示在新的Windows(R会话可能会产生问题,如果有几个监视的变量)。要覆盖各个窗口绘制的行为(结合图和/或保存到一个文件中的图),可以更改每个对象类的使用(I:1 nvar的(结果$ MCMC))类($密度[ ]])< - “网格”,然后使用c.trellis在latticeExtra包的方法相结合,或简单地重新使用的原料MCMC输出生成的图。不生产,如果图== FALSE。</ TD> </ TR>
<tr valign="top"><td>pd</td> <td> the total effective number of parameters in the model calculated using the DIC module for JAGS. Returned only if monitor.pd=TRUE is supplied to the function (or if 'dic' is specified as a monitored variable).</td></tr>
<tr valign="top"> <TD>pd</ TD> <TD>总有效使用DIC模块JAGS计算模型中的参数数目。仅返回如果monitor.pd = TRUE,被提供给的函数(或如果“DIC”被指定为被监视的变量)。</ TD> </ TR>
<tr valign="top"><td>pd.i</td> <td> the contribution of each parameter towards the total effective number of parameters calculated using the DIC module for JAGS. Returned only if monitor.pd.i=TRUE is supplied to the function.</td></tr>
<tr valign="top"> <TD> pd.i </ TD> <TD>对总有效使用DIC模块JAGS计算的参数,每个参数的贡献。 ,只返回,如果monitor.pd.i = TRUE提供的功能。</ TD> </ TR>
<tr valign="top"><td>popt</td> <td> the optimism of the expected deviance calculated using the DIC module for JAGS. Returned only if monitor.popt=TRUE is supplied to the function (or if 'dic' is specified as a monitored variable).</td></tr>
<tr valign="top"> <TD> popt </ TD> <TD>乐观的预期偏差的计算使用DIC模块JAGS。仅返回如果monitor.popt = TRUE,被提供给的函数(或如果“DIC”被指定为被监视的变量)。</ TD> </ TR>
<tr valign="top"><td>dic</td> <td> The Deviance Information Criterion (DIC) model fit statistics. Returned only if 'dic' is specified as a monitored variable. The default print method displays the DIC calculated using both pd (dic) and popt (ped), using the deviance from the combined chains and for each individual chain. Separate values for the mean pd, sum popt and mean deviance is also listed. For more information on the types of DIC calculated, see the JAGS manual. </td></tr>
<tr valign="top"> <TD> dic </ TD> <TD>越轨信息准则(DIC)模型拟合统计。 “DIC”如果只返回被指定为被监视的变量。的默认打印方法,显示计算使用概率pd(DIC)和POPT(PED认证),使用偏差从合并的链和为每个单独的链的DIC。还列出了独立的平均PD,POPT总和和平均偏差值。对于DIC计算的类型的更多信息,请参阅JAGS手册。 </ TD> </ TR>
</table>
</ TABLE>
(作者)----------Author(s)----------
Matthew Denwood <a href="mailto:matthew.denwood@glasgow.ac.uk">matthew.denwood@glasgow.ac.uk</a>
参见----------See Also----------
autorun.jags,
autorun.jags,
run.jagsfile,
run.jagsfile,
combine.mcmc,
combine.mcmc,
testjags,
testjags,
dump.format,
dump.format,
summary.mcmc,
summary.mcmc,
gelman.diag,
gelman.diag,
autocorr.diag
autocorr.diag
实例----------Examples----------
# run a model to calculate the intercept and slope of the expression [运行模型计算的截距和斜率的表达]
# y = m x + c, assuming normal observation errors for y:[为y = mx + C,假设正常观测误差为y:]
## Not run: [#不运行:]
# Simulate the data[模拟数据]
X <- 1:100
Y <- rnorm(length(X), 2*X + 10, 1)
# Model in the JAGS format[模型的JAGS格式]
model <- "model {
for(i in 1 : N){
Y[i] ~ dnorm(true.y[i], precision);
true.y[i] <- (m * X[i]) + c;
}
m ~ dunif(-1000,1000);
c ~ dunif(-1000,1000);
precision ~ dexp(1);
}"
# Use dump.format to convert the data and initial values files [使用dump.format转换的数据和初始值文件]
# into the R dump format, with explicit control over the random [到R的转储文件格式,在随机进行显式控制]
# number generator used for each chain (optional): [每个链数发生器(可选):]
data <- dump.format(list(X=X, Y=Y, N=length(X)))
inits1 <- dump.format(list(m=1, c=1, precision=1,
.RNG.name="base::Super-Duper", .RNG.seed=1))
inits2 <- dump.format(list(m=0.1, c=10, precision=1,
.RNG.name="base::Wichmann-Hill", .RNG.seed=2))
# Run the model and produce plots [运行模式和生产图]
results <- run.jags(model=model, monitor=c("m", "c", "precision"),
data=data, n.chains=2, inits=c(inits1,inits2), plots = TRUE)
# Density plots of the monitored variables: [被监视的变量的密度图:]
results$density
# Analyse the results [分析结果]
results$summary
## End(Not run)[#(不执行)]
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|