使用mvtnorm程序包构建自己的多项式概率模型

时间:2019-12-31 04:33:06

标签: regression probability-density unordered

我正在尝试使用optmixmvtnorm软件包构建多项式概率模型。没有使用MNP的现有库,因为稍后我将其扩展到多变量模型。

为简单起见,我正在尝试构建一个具有三个替代方案的模型。例如,汽车,公共汽车和火车是替代选择。每个人都选择这三种选择之一。

以下是我定义模型的方式。我最初从仅常量模型开始。

# defining the utilities of each alternative (assuming only constants), pars[1] and pars[2] are the coefficients to be estimated #
  ucar    <<- 0
  ubus   <<- parm[1]
  utrain   <<- parm[2]

# defining the variance-covariance matrix, initially assuming correlations are zero and variances are of unit magnitude #
  cormat <<- matrix(c(1,0,0,0,1,0,0,0,1), nrow = 3, ncol = 3)

# determining the probabilities of choosing car, bus and train #
  pcar    <<- pmvnorm(lower = c(-Inf, -Inf, -Inf), upper = c(ucar,-ubus,-utrain), mean = c(0,0,0), sigma = cormat)
  pbus   <<- pmvnorm(lower = c(-Inf, -Inf, -Inf), upper = c(-ucar,ubus,-utrain), mean = c(0,0,0), sigma = cormat)
  ptrain   <<- pmvnorm(lower = c(-Inf, -Inf, -Inf), upper = c(-ucar,-ubus,utrain), mean = c(0,0,0), sigma = cormat)

# extracting only the probabilities from mvtnorm and finding out the log of probabilities #
  pcar_1  <<- pcar[[1]]
  pbus_1 <<- pbus[[1]]
  ptrain_1 <<- ptrain[[1]]

  lpcar   <<- log(pcar_1)
  lpbus  <<- log(pbus_1)
  lptrain  <<- log(ptrain_1)

# defining the log-likelihood function, where car, bus and train are dummy indicators for chosen alternatives #
  ll  = -1*(car*lpcar + bus*lpbus + train*lptrain)

我使用optmix最大化上述ll以获取参数。 上面的模型工作正常。当我在模型中添加自变量时,问题就来了。我收到一个错误“无法在初始参数处评估功能”。我在代码中做错什么了?

0 个答案:

没有答案
相关问题