fit(depmixS4)
fit()所属R语言包:depmixS4
Fit 'depmix' or 'mix' models
飞度的depmix“或”混合“模式
译者:生物统计家园网 机器人LoveR
描述----------Description----------
fit optimizes parameters of depmix or mix models, optionally subject to general linear (in)equality constraints.
fit优化depmix或mix模型,可以选择一般线性(中)等式约束的参数。
用法----------Usage----------
## S4 method for signature 'depmix'
fit(object, fixed=NULL, equal=NULL, conrows=NULL,
conrows.upper=0, conrows.lower=0, method=NULL, emcontrol=em.control(), verbose=TRUE,...)
## S4 method for signature 'depmix.fitted'
summary(object,which="all")
## S4 method for signature 'mix'
fit(object, fixed=NULL, equal=NULL, conrows=NULL,
conrows.upper=0, conrows.lower=0, method=NULL, emcontrol=em.control(), verbose=TRUE,...)
## S4 method for signature 'mix.fitted'
summary(object,which="all")
参数----------Arguments----------
参数:object
An object of class (dep-)mix.
对象的类(dep-)mix。
参数:fixed
Vector of mode logical indicating which parameters should be fixed.
向量的模式逻辑指示哪些参数应该是固定的。
参数:equal
Vector indicating equality constraints; see Details.
向量表示等式约束,查看详细信息。
参数:conrows
Rows of a general linear constraint matrix; see Details.
一般线性约束矩阵的行详细。
参数:conrows.upper, conrows.lower
Upper and lower bounds for the linear constraints; see Details.
上界和下界的线性约束;详细。
参数:method
The optimization method; mostly determined by constraints.
优化方法,主要是由约束。
参数:emcontrol
Named list with control parameters for the EM algorithm (see em.control).
名为List的EM算法的控制参数(见em.control“)。
参数:verbose
Should optimization information be displayed on screen?
优化信息显示在屏幕上?
参数:which
Should summaries be provided for "all" submodels? Options are "prior", "response", and for fitted depmix models also "transition".
摘要提供“所有”子模型?选项是“事先”,“回应”,并装depmix模型也“转型”。
参数:...
Further arguments passed on to the optimization methods.
进一步传递参数的优化方法。
Details
详细信息----------Details----------
Models are fitted by the EM algorithm if there are no constraints on the parameters. Aspects of the EM algorithm can be controlled through the emcontrol argument; see details in em.control. Otherwise the general optimizers solnp, the default (from package Rsolnp) or donlp2 (from package Rdonlp2) are used which handle general linear (in-)equality constraints.
模型拟合EM算法的参数,如果没有任何限制。 emcontrol参数方面的EM算法,可以通过控制;请参阅在em.control的细节。否则,一般的优化solnp,默认(包Rsolnp)或donlp2(包Rdonlp2)是用来处理一般线性(中)等式约束。
Three types of constraints can be specified on the parameters: fixed, equality, and general linear (in-)equality constraints. Constraint vectors should be of length npar(object); note that this hence includes redundant parameters such as the base category parameter in multinomial logistic models which is always fixed at zero. See help on getpars and setpars about the ordering of parameters.
三种类型的约束,可以指定的参数:固定,平等,和一般线性(中)等式约束。约束的向量应该是长度npar(object);注意,这因此包括冗余参数,如基category参数总是固定在零多项式logistic模型。请参阅帮助getpars和setpars有关的参数顺序。
The equal argument is used to specify equality constraints: parameters that get the same integer number in this vector are estimated to be equal. Any integers can be used in this way except 0 and 1, which indicate fixed and free parameters, respectively.
equal参数用于指定等式约束:在此向量中得到相同的整数的参数估计是平等的。除了0和1,这表明固定和自由参数,分别以这种方式,可以使用任意整数。
Using solnp (or donlp2), a Newton-Raphson scheme is employed to estimate parameters subject to linear constraints by imposing:
使用solnp(donlp2),牛顿 - 拉夫逊计划受线性约束的参数估计,通过实施:
bl <= A*x <= bu,
BL <= A * x <= BU,
where x is the parameter vector, bl is a vector of lower bounds, bu is a vector of upper bounds, and A is the constraint matrix.
其中x是参数矢量,提单是一个向量的下界,bu是一个向量的上界,和A是约束矩阵。
The conrows argument is used to specify rows of A directly, and the conrows.lower and conrows.upper arguments to specify the bounds on the constraints. conrows must be a matrix of npar(object) columns and one row for each constraint (a vector in the case of a single constraint). Examples of these three ways of constraining parameters are provided below.
conrows参数用于指定行的一个直接,并conrows.lower和conrows.upper的参数指定的约束范围。 conrows必须NPAR(对象)列和一个行的每个约束(一个单一的约束的情况下中的一个向量)的矩阵。在下面的实施例中所提供的这三种方式的约束参数。
Note that when specifying constraints that these should respect the fixed constraints inherent in e.g. the multinomial logit models for the initial and transition probabilities. For example, the baseline category coefficient in a multinomial logit model is fixed on zero.
需要注意的是指定的限制时,这些应该尊重固定固有的局限性,在如多项Logit模型的初始和过渡的可能性。例如,多项式Logit模型的系数被固定在零基线类。
llratio performs a log-likelihood ratio test on two fit'ted models; the first object should have the largest degrees of freedom (find out by using freepars).
llratio执行两个fit特德模型的对数似然比检验的第一个对象应具有最大的自由度(使用freepars)找出。
值----------Value----------
fit returns an object of class depmix.fitted which contains the original depmix object, and further has slots:
fit将返回一个对象类depmix.fitted其中包含了原始的depmix对象,进一步插槽:
message: Convergence information.
message:收敛的信息。
conMat: The constraint matrix A, see Details.
conMat:约束矩阵A,查看详细信息。
posterior: The posterior state sequence (computed with the viterbi algorithm), and the posterior probabilities (delta
posterior:的后安装状态序列(与维特比算法计算),和的后验概率(δ
The print method shows the message along with the likelihood and AIC and BIC; the summary method prints the parameter estimates.
打印方法message的可能性和AIC和BIC,总结方法打印参数估计。
Posterior densities and the viterbi state sequence can be accessed through posterior.
可以通过posterior后的密度和维特比状态序列。
As fitted models are depmixS4 models, they can be used as starting values for new fits, for example with constraints added. Note that when refitting already fitted models, the constraints, if any, are not added automatically, they have to be added again.
作为拟合模型是depmixS4型号,它们可以被用来作为起始新的适合的值,例如带约束添加。请注意,当重新安装已经安装模式,约束,如果有的话,是不会自动添加,他们不得不再次添加。
(作者)----------Author(s)----------
Ingmar Visser & Maarten Speekenbrink
参考文献----------References----------
(2009). Hidden Markov Models for Invdividual Time Series. In: Jaan Valsiner, Peter C. M. Molenaar, M. C. D. P. Lyra, and N. Chaudhary (editors). Dynamic Process Methodology in the Social and Developmental Sciences, chapter 13, pages 269–289. New York: Springer.
实例----------Examples----------
data(speed)
# 2-state model on rt and corr from speed data set [状态RT和校正模型的高速数据集]
# with Pacc as covariate on the transition matrix[与降雨量统计上的转换矩阵]
# ntimes is used to specify the lengths of 3 separate series[ntimes用于指定3个独立系列的长度]
mod1 <- depmix(list(rt~1,corr~1),data=speed,transition=~Pacc,nstates=2,
family=list(gaussian(),multinomial("identity")),ntimes=c(168,134,137))
# fit the model[拟合模型]
set.seed(3)
fmod1 <- fit(mod1)
fmod1 # to see the logLik and optimization information[看到的logLik和最优化信息]
# to see the parameters[看到参数]
summary(fmod1)
# FIX SOME PARAMETERS[修正了一些参数]
# get the starting values of this model to the optimized [得到该模型的初始值的优化]
# values of the previously fitted model to speed optimization[以前的拟合模型的值,以加快优化]
pars <- c(unlist(getpars(fmod1)))
# constrain the initial state probs to be 0 and 1 [约束为0和1的初始状态probs]
# also constrain the guessing probs to be 0.5 and 0.5 [也制约了猜测probs为0.5和0.5]
# (ie the probabilities of corr in state 1)[(即在状态1的概率校正)]
# change the ones that we want to constrain[改变的,我们要限制]
pars[1]=0
pars[2]=1 # this means the process will always start in state 2[这意味着这个过程将一直从状态2]
pars[13]=0.5
pars[14]=0.5 # the corr parameters in state 1 are now both 0, corresponding the 0.5 prob[校正参数现在都在状态1 0,对应0.5的概率]
mod2 <- setpars(mod1,pars)
# fix the parameters by setting: [通过设置固定的参数:]
free <- c(0,0,rep(c(0,1),4),1,1,0,0,1,1,1,1)
# fit the model[拟合模型]
fmod2 <- fit(mod2,fixed=!free)
# likelihood ratio insignificant, hence fmod2 better than fmod1[似然比微不足道,因此fmod2比fmod1好]
llratio(fmod1,fmod2)
# NOW ADD SOME GENERAL LINEAR CONSTRAINTS[现在,添加一些一般的线性约束]
# set the starting values of this model to the optimized [该模型的初始值设置到优化]
# values of the previously fitted model to speed optimization[以前的拟合模型的值,以加快优化]
pars <- c(unlist(getpars(fmod2)))
pars[4] <- pars[8] <- -4
pars[6] <- pars[10] <- 10
mod3 <- setpars(mod2,pars)
# start with fixed and free parameters[从参数固定和自由]
conpat <- c(0,0,rep(c(0,1),4),1,1,0,0,1,1,1,1)
# constrain the beta's on the transition parameters to be equal[限制测试版的转换参数是相等的]
conpat[4] <- conpat[8] <- 2
conpat[6] <- conpat[10] <- 3
fmod3 <- fit(mod3,equal=conpat)
llratio(fmod2,fmod3)
# above constraints can also be specified using the conrows argument as follows[上述的限制,还可以指定使用conrows参数如下]
conr <- matrix(0,2,18)
# parameters 4 and 8 have to be equal, otherwise stated, their diffence should be zero,[参数4和8必须是相等的,另有说明外,它们的来由应该为零,]
# and similarly for parameters 6 & 10[同样的参数6和10]
conr[1,4] <- 1
conr[1,8] <- -1
conr[2,6] <- 1
conr[2,10] <- -1
# note here that we use the fitted model fmod2 as that has appropriate [注意,在这里,我们使用有适当的拟合模型fmod2]
# starting values[初始值]
fmod3b <- fit(mod3,conrows=conr,fixed=!free) # using free defined above[使用上面自由定义]
data(balance)
# four binary items on the balance scale task[四个二进制项目的资产负债规模任务]
mod4 <- mix(list(d1~1,d2~1,d3~1,d4~1), data=balance, nstates=2,
family=list(multinomial("identity"),multinomial("identity"),multinomial("identity"),multinomial("identity")))
set.seed(1)
fmod4 <- fit(mod4)
# add age as covariate on class membership by using the prior argument[通过使用已有的参数中添加类成员的年龄,结果]
mod5 <- mix(list(d1~1,d2~1,d3~1,d4~1), data=balance, nstates=2,
family=list(multinomial("identity"),multinomial("identity"),multinomial("identity"),multinomial("identity")),
prior=~age, initdata=balance)
set.seed(1)
fmod5 <- fit(mod5)
# check the likelihood ratio; adding age significantly improves the goodness-of-fit[检查的可能性比中加入年龄,显着提高了善良的拟合]
llratio(fmod5,fmod4)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|