中的值不是有限的

中的值不是有限的

本文介绍了R中的MLE错误:非有限的有限差分值/'vmmin'中的值不是有限的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究R(初学者)中的损失厌恶模型,并希望从具有3列(损失/收益值(连续的和决策编码为0或1(二进制)的列)的数据集中估算一些参数)dropbox.com/s/fpw3obrqcx8ld1q/GrandAverage.RData?dl=0下面给出了我必须使用的部分代码:

I am working on a loss aversion model in R (beginner) and want to estimate some parameters, from a dataset with 3 columns (loss/gain values (both continous and a column with decisions coded as 0 or 1 (binary))dropbox.com/s/fpw3obrqcx8ld1q/GrandAverage.RData?dl=0The part of the code if have to use for this I am using is given below:

set <- GrandAverage[, 5:7];
  Beh.Parameters <- function (lambda, alpha, temp) {
 u = 0.5 * set$Gain^alpha + 0.5 * lambda * set$Loss^alpha
  GambleProbability <- 1 / (1 + exp(-temp * u))

  loglike <- set$Decision*log(GambleProbability) +
    (1- set$Decision)*log(1-GambleProbability)

  return(-sum(loglike))
 }

  temp_s <- 0.1 #runif(1, 0.1, 1)

  ML.estim1  <- mle(Beh.Parameters, start = list (lambda = 1, alpha = 1, temp = temp_s), nobs = length(set$Decision))
  ML.estim2  <- mle(Beh.Parameters, start = list(lambda = 0.1, alpha = 0.1,  temp = temp_s), nobs = length(set$Decision))

我使用mle函数来估计3个参数(lambda,alpha和temp),而没有alpha时,例如,我会收到以下输出:

I use the mle function in order to estimate the 3 parameters (lambda, alpha and temp), without the alpha i receive this output for example:

当我尝试在不使用alpha参数的情况下运行它时,它工作正常,但是当我包含它时,我收到了以下两个错误:

When I try to run it without the alpha parameter it works fine but when I include it I received these two errors:

我试图重新编码矩阵,奇异值分解,BFGS等.欢迎您提供任何帮助...谢谢.

I tried to recode the matrix, singular value decomposition, BFGS etc.Any help is welcome...thanks in advance.

推荐答案

您的Loss变量为负.在R中,将负值提高至小数幂(即set$Loss^alpha其中alpha为非整数)将返回NaN值. (唯一通用的选择是返回您可能不想要的复数值答案.)您是否要将Loss编码为正数而不是负数?还是您想要-abs(set$Loss^alpha)?

Your Loss variable is negative. In R, raising negative values to a fractional power (i.e. set$Loss^alpha where alpha is non-integer) returns NaN values. (The only general alternative is to return a complex-valued answer, which you probably don't want.) Did you mean to code Loss as positive rather than negative? Or maybe you want -abs(set$Loss^alpha) ?

作为通用调试技巧,它有助于添加

As a general purpose debugging tip, it helps to add

cat(lambda,alpha,temp,-sum(loglike),"\n")

作为目标函数的倒数第二行,因此您可以更好地了解正在发生的事情.

as the second-to-last-line of your objective function so you can better see what's going on.

这篇关于R中的MLE错误:非有限的有限差分值/'vmmin'中的值不是有限的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 07:25