4Manuals

  • PDF Cloud HOME

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

    R中具有边际效应的OLS 嵌套交叉验证对不同回归变量的使用

我正在尝试使用optmix和mvtnorm软件包构建多项式概率模型。没有使用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 个答案:

没有答案



Similar searches
    在Stackblitz上将MapBoxDirections添加到Angular Application中不起作用 错误:serve命令需要在Angular项目中运行,但是找不到项目定义 调整页面大小时图像向左或向右移动 简单的屏幕/监视器设备使用哪种linux驱动程序子系统/ api? SyntaxError:在Node.js中使用EJS时出现意外标识符