找回密码
 注册
查看: 320|回复: 0

R语言 spBayes包 spGLM()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-9-30 14:24:15 | 显示全部楼层 |阅读模式
spGLM(spBayes)
spGLM()所属R语言包:spBayes

                                        Function for fitting univariate Bayesian generalized linear spatial regression models
                                         函数的拟合单变量贝叶斯广义线性空间的回归模型

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

The function spGLM fits univariate Bayesian generalized linear spatial regression models. Given a set of knots, spGLM will also fit a predictive process model (see references below).
的功能spGLM适合单变量贝叶斯广义线性空间回归模型。给定一组的结,spGLM也符合预测过程模型(请参阅下面的参考资料)。


用法----------Usage----------


spGLM(formula, family="binomial", weights, data = parent.frame(),
      coords, knots, amcmc, starting, tuning, priors, cov.model,
      modified.pp = TRUE, n.samples, sub.samples, verbose=TRUE,
      n.report=100, ...)



参数----------Arguments----------

参数:formula
a symbolic description of the regression model to be fit. See example below.  
一个象征性的回归模型的描述是合适的。见下面的例子。


参数:family
currently only supports binomial and poisson data using the logit and log link functions, respectively.
目前只支持binomial和poisson数据的Logit和log链接功能,分别使用。


参数:weights
an optional vector of weights to be used in the fitting process when family is binomial. Unless otherwise specified a vector of ones is assumed i.e., one trial at each location.
当family是binomial的嵌合过程中要使用可选的权重向量。除另有规定外,一个向量的假设,一项试验,即在每个位置。


参数:data
an optional data frame containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which spGLM is called.   
一个可选的数据框包含在模型中的变量。如果没有找到,数据,变量environment(formula),通常是spGLM被称为环境。


参数:coords
an n x 2 matrix of the observation coordinates in R^2 (e.g., easting and northing).  
n x 2R^2(例如,东向和北向)的观察坐标矩阵。


参数:knots
either a m x 2 matrix of the predictive process knot coordinates in R^2 (e.g., easting and northing) or a vector of length two or three with the first and second elements recording the number of columns and rows in the desired knot grid. The third, optional, element sets the offset of the outermost knots from the extent of the coords.  
m x 2矩阵的预测过程结坐标在R^2(例如,东向和北向)或长度的向量的记录的数目的列和行,在该第一和第二元件中的两个或三个与所需的结栅格。可选的第三个,元素设置的偏移量的最外结从coords的程度。


参数:amcmc
a list with tags n.batch, batch.length, and accept.rate. Specifying this argument invokes an adaptive MCMC sampler (see Roberts and Rosenthal, 2006 and adaptMetropGibbs function).
标签的列表n.batch,batch.length和accept.rate。指定此参数调用自适应MCMC采样器(见罗伯茨和Rosenthal,2006年和adaptMetropGibbs功能)。


参数:starting
a list with each tag corresponding to a parameter name. Valid list tags are beta, sigma.sq, phi, nu, and w.  The value portion of each tag is the parameter's starting value. If the predictive process is used then w must be of length m; otherwise, it must be of length n. Alternatively, w can be set as a scalar, in which case the value is repeated.
与每个标记对应的参数名称的列表。有效的列表标签是beta,sigma.sq,phi,nu,w。每个标签的值部分参数的初始值。如果预测过程中被使用,则w必须的长度m,否则,它必须是长度n。还有一种方法,w可以被设置为一个标量,在这种情况下,该值是重复的。


参数:tuning
a list with each tag corresponding to a parameter name. Valid list tags are beta, sigma.sq, phi, nu, w, and e. The value portion of each tag defines the variance of the Metropolis normal proposal distribution. The tuning value for beta can be a vector of length p or the lower-triangle of the pxp Cholesky square-root of the desired proposal variance matrix. If the predictive process is used then w must be of length m; otherwise, it must be of length n. Alternatively, w can be set as a scalar, in which the value is repeated.  If a modified predictive process is not used then e is ignored.
与每个标记对应的参数名称的列表。有效的列表标签是beta,sigma.sq,phi,nu,w,e。每个标签都会正常的提议分布的方差定义的值部分。 beta的调谐值可以是一个矢量长度p或pxp的Cholesky平方根所需的建议方差矩阵的下部三角。如果预测过程中被使用,则w必须的长度m,否则,它必须是长度n。或者,w可以被设置为一个标量,在该值是重复的。如果不使用,那么修改后的预测过程e被忽略。


参数:priors
a list with each tag corresponding to a parameter name. Valid list tags are beta.flat, beta.normal, sigma.sq.ig, phi.unif, and nu.unif. simga.sq is assumed to follow an inverse-Gamma distribution, whereas the spatial decay phi and smoothness nu parameters are assumed to follow Uniform distributions. If beta.normal then covariate specific mean and variance hyperparameters are passed as the first and second list elements, respectively. The hyperparameters of the inverse-Gamma are passed as a vector of length two, with the first and second elements corresponding to the shape and scale, respectively. The hyperparameters of the Uniform are also passed as a vector of length two with the first and second elements corresponding to the lower and upper support, respectively.  
与每个标记对应的参数名称的列表。有效的列表标签是beta.flat,beta.normal,sigma.sq.ig,phi.unif,nu.unif。 simga.sq假定服从逆Gamma分布,而在空间衰减phi和平滑nu参数的假设为均匀分布。如果beta.normal协变量的均值和方差的超传递的第一和第二个列表元素,分别。的超反伽马传递作为一个向量的长度为2,第一和第二元件与对应的形状和规模,分别。也通过分别与第一和第二元件的下部和上部的支持对应的长度为2的向量,均匀的超。


参数:cov.model
a quoted key word that specifies the covariance function used to model the spatial dependence structure among the observations.  Supported covariance model key words are: "exponential", "matern", "spherical", and "gaussian".  See below for details.   
一个带引号的关键字,指定的协方差函数用于模拟空间之间的依赖结构的观察。支持的协方差模型的关键词是:"exponential","matern","spherical"和"gaussian"。有关详细信息,请参见下文。


参数:modified.pp
a logical value indicating if the modified predictive process should be used (see references below for details). Note, if a predictive process model is not used (i.e., knots is not specified) then this argument is ignored.  
一逻辑值,如果修改后的预测过程中应使用(有关详细信息,请参阅下面的参考资料)。请注意,如果预测过程模型是不使用(即,knots没有指定),那么这个参数将被忽略。


参数:n.samples
the number of MCMC iterations. This is ignored if amcmc is specified.  
MCMC中的迭代数。这是忽略,如果amcmc指定。


参数:sub.samples
a vector of length 3 that specifies start, end, and thin, respectively, of the MCMC samples. The default is c(1, n.samples, 1) (i.e., all samples).  
一个向量的长度为3,指定起点,终点,又瘦,分别MCMC样本。默认值是c(1, n.samples, 1)(即,所有样品)。


参数:verbose
if TRUE, model specification and progress of the sampler is printed to the screen. Otherwise, nothing is printed to the screen.   
如果TRUE,型号规格和进步的取样打印到屏幕上。否则,一切都被打印到屏幕上。


参数:n.report
the interval to report Metropolis acceptance and MCMC progress.   
报告的时间间隔都会接受和MCMC进步。


参数:...
currently no additional arguments.   
目前没有任何额外的参数。


Details

详细信息----------Details----------

If a binomial model is specified the response vector is the number of successful trials at each location. Note, this is different from the glm argument which is passed as a rate.
如果binomial模型指定的响应向量的数量在每个位置的成功试验。请注意,这是从glm参数传递的速度不同。


值----------Value----------

An object of class spGLM, which is a list with the following tags:
类的一个对象spGLM,这是一个与下面的标签列表:


参数:coords
the n x 2 matrix specified by coords.   
n x 2的矩阵指定coords。


参数:knot.coords
the m x 2 matrix as specified by knots.   
m x 2矩阵指定的knots。


参数:p.samples
a coda object of posterior samples for the defined parameters.  
一个coda对象定义的参数后样品。


参数:acceptance
the Metropolis sampling acceptance rate. If amcmc is used then this will be a matrix of each parameter's acceptance rate at the end of each batch. Otherwise, the sampler is a Metropolis with a joint proposal of all parameters, and the acceptance rate is the average over all proposals.
Metropolis抽样验收合格率。如果amcmc被使用,那么这将是一个矩阵的每个参数的录取率在每个批处理结束。否则,采样器是一个国际大都会,一个联合提案的所有参数,平均合格率为提出的所有提案。


参数:acceptance.w
If this is a non-predictive process model and amcmc is used then this will be a matrix of each random spatial effects acceptance rate at the end of each batch.  
如果这是一个非预测的过程模型和amcmc被使用,那么这将是一个矩阵的每个随机空间效果接受率在每个批处理结束。


参数:acceptance.w.str
If this is a predictive process model and amcmc is used then this will be a matrix of each random spatial effects acceptance rate at the end of each batch.  
如果这是一个预测的过程模型和amcmc使用,那么这将是一个矩阵的每个随机空间效果接受率在每个批处理结束。


参数:sp.effects
a matrix that holds samples from the posterior distribution of the spatial random effects. The rows of this matrix correspond to the n point observations and the columns are the posterior samples.  
一个矩阵保存样本的空间随机效应的后验分布。这个矩阵的行对应的n点的观测和列后的样品。

The return object might include additional data used for subsequent prediction and/or model fit evaluation.
返回的对象可能包括额外的数据,用于以后的预测和/或模型拟合的评价。


(作者)----------Author(s)----------



Andrew O. Finley <a href="mailto:finleya@msu.edu">finleya@msu.edu</a>, <br>
Sudipto Banerjee <a href="mailto:baner009@umn.edu">baner009@umn.edu</a>




参考文献----------References----------



the performance of predictive process modeling for large datasets. Computational Statistics and Data Analysis, DOI: 10.1016/j.csda.2008.09.008   



参见----------See Also----------

spGGT, spMvLM, spMvGLM
spGGT,spMvLM,spMvGLM


实例----------Examples----------


## Not run: [#不运行:]

library(MASS)
library(MBA)
library(fields)

################################[###############################]
##Spatial binomial[#空间二项式]
################################[###############################]

##Generate binary data[#生成的二进制数据。]
coords <- as.matrix(expand.grid(seq(0,100,length.out=8), seq(0,100,length.out=8)))
n <- nrow(coords)

phi <- 3/50
sigma.sq <- 2

R <- sigma.sq*exp(-phi*as.matrix(dist(coords)))
w <- mvrnorm(1, rep(0,n), R)

x <- as.matrix(rep(1,n))
beta <- 0.1
p <- 1/(1+exp(-(x%*%beta+w)))

weights <- rep(1, n)
weights[coords[,1]>mean(coords[,1])] <- 10

y <- rbinom(n, weights, prob=p)

##Collect samples[#样品采集]
fit <- glm((y/weights)~x-1, weights=weights, family="binomial")
beta.starting <- coefficients(fit)
beta.tuning <- t(chol(vcov(fit)))

n.batch <- 500
batch.length <- 50
n.samples <- n.batch*batch.length

m.1 <- spGLM(y~1, family="binomial", coords=coords, weights=weights,
             starting=
             list("beta"=beta.starting, "phi"=0.06,"sigma.sq"=1, "w"=0),
             tuning=
             list("beta"=beta.tuning, "phi"=0.5, "sigma.sq"=0.1, "w"=0.01),
             priors=
             list("beta.Normal"=list(0,10), "phi.Unif"=c(0.03, 0.3),
                  "sigma.sq.IG"=c(2, 1)),
             amcmc=
             list("n.batch"=n.batch,"batch.length"=batch.length,
                  "accept.rate"=0.43),
             cov.model="exponential",
             n.samples=n.samples, sub.samples=c(1000,n.samples,10),
             verbose=TRUE, n.report=10)

print(summary(mcmc(m.1$p.samples)))

beta.hat <- m.1$p.samples[,"(Intercept)"]
w.hat <- m.1$sp.effects

y.hat <- 1/(1+exp(-(x%*%beta.hat+w.hat)))

y.hat.mu <- apply(y.hat,1,mean)
y.hat.var <- apply(y.hat,1,var)

##Take a look[#看一看]
par(mfrow=c(1,2))
surf <- mba.surf(cbind(coords,y.hat.mu),no.X=100, no.Y=100, extend=TRUE)$xyz.est
image.plot(surf, main="Interpolated mean of posterior rate\n(observed rate)")
text(coords, label=paste("(",y/weights,")",sep=""))

surf <- mba.surf(cbind(coords,y.hat.var),no.X=100, no.Y=100, extend=TRUE)$xyz.est
image.plot(surf, main="Interpolated variance of posterior rate\n(observed # of trials)")[试验)“)]
text(coords, label=paste("(",weights,")",sep=""))

###########################[##########################]
##Spatial poisson[#空间泊松]
###########################[##########################]
##Generate count data[#生成的计数数据。]
set.seed(1)

n <- 100

coords <- cbind(runif(n,1,100),runif(n,1,100))

phi <- 3/50
sigma.sq <- 2

R <- sigma.sq*exp(-phi*as.matrix(dist(coords)))
w <- mvrnorm(1, rep(0,n), R)

x <- as.matrix(rep(1,n))
beta <- 0.1
y <- rpois(n, exp(x%*%beta+w))

##Collect samples[#样品采集]
beta.starting <- coefficients(glm(y~x-1, family="poisson"))
beta.tuning <- t(chol(vcov(glm(y~x-1, family="poisson"))))

n.batch <- 500
batch.length <- 50
n.samples <- n.batch*batch.length

##Note tuning list is now optional[#注意调整名单现在是可选的]

m.1 <- spGLM(y~1, family="poisson", coords=coords,
             starting=
             list("beta"=beta.starting, "phi"=0.06,"sigma.sq"=1, "w"=0),
             tuning=
             list("beta"=0.1, "phi"=0.5, "sigma.sq"=0.1, "w"=0.1),
             priors=
             list("beta.Flat", "phi.Unif"=c(0.03, 0.3), "sigma.sq.IG"=c(2, 1)),
             amcmc=
             list("n.batch"=n.batch,"batch.length"=batch.length,
                  "accept.rate"=0.43),
             cov.model="exponential",
             n.samples=n.samples, sub.samples=c(1000,n.samples,10),
             verbose=TRUE, n.report=10)

##Just for fun check out the progression of the acceptance[#只是为了好玩的进展,接受检查]
##as it moves to 43% (same can be seen for the random spatial effects).[#,因为它移动到43%(同样可以看到的随机空间效果)。]
plot(mcmc(t(m.1$acceptance)), density=FALSE, smooth=FALSE)

##Now parameter summaries, etc.[#现在,参数摘要等。]
m.1$p.samples[,"phi"] <- 3/m.1$p.samples[,"phi"]

plot(mcmc(m.1$p.samples))
print(summary(mcmc(m.1$p.samples)))

beta.hat <- mean(m.1$p.samples[,"(Intercept)"])
w.hat <- rowMeans(m.1$sp.effects)

y.hat <-exp(x%*%beta.hat+w.hat)

##Take a look[#看一看]
par(mfrow=c(1,2))
surf <- mba.surf(cbind(coords,y),no.X=100, no.Y=100, extend=TRUE)$xyz.est
image(surf, main="obs")
contour(surf, drawlabels=FALSE, add=TRUE)
text(coords, labels=y, cex=1, col="blue")

surf <- mba.surf(cbind(coords,y.hat),no.X=100, no.Y=100, extend=TRUE)$xyz.est
image(surf, main="Fitted counts")
contour(surf, drawlabels=FALSE, add=TRUE)
text(coords, labels=round(y.hat,0), cex=1, col="blue")

###########################[##########################]
##Spatial logistic[#空间MF]
###########################[##########################]

##Generate binary data[#生成的二进制数据。]
n <- 100

coords <- cbind(runif(n,1,100),runif(n,1,100))

phi <- 3/50
sigma.sq <- 2

R <- sigma.sq*exp(-phi*as.matrix(dist(coords)))
w <- mvrnorm(1, rep(0,n), R)

x <- as.matrix(rep(1,n))
beta <- 0.1
p <- 1/(1+exp(-(x%*%beta+w)))
y <- rbinom(n, 1, prob=p)

##Collect samples[#样品采集]
beta.starting <- coefficients(glm(y~x-1, family="binomial"))
beta.tuning <- t(chol(vcov(glm(y~x-1, family="binomial"))))
            
n.batch <- 500
batch.length <- 50
n.samples <- n.batch*batch.length

m.1 <- spGLM(y~1, family="binomial", coords=coords,
             starting=
             list("beta"=beta.starting, "phi"=0.06,"sigma.sq"=1, "w"=0),
             tuning=
             list("beta"=beta.tuning, "phi"=0.5, "sigma.sq"=0.1, "w"=0.01),
             priors=
             list("beta.Normal"=list(0,10), "phi.Unif"=c(0.03, 0.3),
                  "sigma.sq.IG"=c(2, 1)),
             amcmc=
             list("n.batch"=n.batch,"batch.length"=batch.length,
                  "accept.rate"=0.43),
             cov.model="exponential",
             n.samples=n.samples, sub.samples=c(1000,n.samples,10),
             verbose=TRUE, n.report=10)

m.1$p.samples[,"phi"] <- 3/m.1$p.samples[,"phi"]

print(summary(mcmc(m.1$p.samples)))

beta.hat <- mean(m.1$p.samples[,"(Intercept)"])
w.hat <- rowMeans(m.1$sp.effects)

y.hat <- 1/(1+exp(-(x%*%beta.hat+w.hat)))

##Take a look[#看一看]
par(mfrow=c(1,2))
surf <- mba.surf(cbind(coords,y),no.X=100, no.Y=100, extend=TRUE)$xyz.est
image(surf, main="Observed")
contour(surf, add=TRUE)
points(coords[y==1,], pch=19, cex=1)
points(coords[y==0,], cex=1)

surf <- mba.surf(cbind(coords,y.hat),no.X=100, no.Y=100, extend=TRUE)$xyz.est
image(surf, main="Fitted probabilities")
contour(surf, add=TRUE)
points(coords[y==1,], pch=19, cex=1)
points(coords[y==0,], cex=1)


## End(Not run)[#(不执行)]

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-6-17 02:45 , Processed in 0.022467 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表