简体   繁体   English

如何在 R 中创建 Tobit model?

[英]How do I create a Tobit model in R?

Fairly new to R, so please bear with me. R 相当新,所以请多多包涵。

I'm hoping to create a model where my outcome variable is only positive - number of conversions from Facebook ads.我希望创建一个 model,其中我的结果变量仅为正数 - 来自 Facebook 广告的转化次数。

Here's a sample of the data:以下是数据示例:

| Team            | Opp_Team             | Channel_Market | Week | Thuuz_Rating | Team_EloRating | Opp_Team_EloRating | Divisional | Spend   | Results_Total |
+-----------------+----------------------+----------------+------+--------------+----------------+--------------------+------------+---------+---------+
| Atlanta Falcons | Tampa Bay Buccaneers | Fox_In         | 1    | 46           | 1486           | 1412               | 1          | 4681.63 | 48      |
+-----------------+----------------------+----------------+------+--------------+----------------+--------------------+------------+---------+---------+
| Atlanta Falcons | Carolina Panthers    | Fox_In         | 4    | 68           | 1510           | 1604               | 1          | 5373.1  | 45      |
+-----------------+----------------------+----------------+------+--------------+----------------+--------------------+------------+---------+---------+
| Atlanta Falcons | Denver Broncos       | Fox_In         | 5    | 66           | 1541           | 1690               | 0          | 5339.04 | 15      |
+-----------------+----------------------+----------------+------+--------------+----------------+--------------------+------------+---------+---------+
| Atlanta Falcons | Seattle Seahawks     | Fox_In         | 6    | 68           | 1576           | 1654               | 0          | 6304.21 | 41      |

I have installed the AER package and tried this code:我已经安装了 AER package 并尝试了以下代码:

library(AER)
nfltobit = tobit(Results_Total ~ Team + Opp_Team + Channel_Market + Week + Spend + Team:Spend + Opp_Team:Spend + Channel_Market:Spend + Week:Spend, left = 0 , right = Inf, data = nfltrain)

For some reason I get an error: "unused arguments (left = 0, right = Inf, data = nfltrain)"出于某种原因,我收到一个错误:“未使用的 arguments(左 = 0,右 = Inf,数据 = nfltrain)”

Perhaps I'm not approaching this correctly, or the tobit function isn't the correct method.也许我没有正确解决这个问题,或者 tobit function 不是正确的方法。 I've tried looking everywhere for a solution, but I'm afraid I'm a bit stuck.我试过到处寻找解决方案,但恐怕我有点卡住了。 Thanks in advance for any help!提前感谢您的帮助!

The code works perfectly for me.该代码非常适合我。 Have you tried to uninstall the package and install it again?您是否尝试过卸载 package 并重新安装? You may be working with an old version.您可能正在使用旧版本。 Try this:尝试这个:

remove.packages("AER")
install.packages("AER")

Then, run again your code.然后,再次运行您的代码。 If the problem persists, try to update R.如果问题仍然存在,请尝试更新 R。 You can use the following code:您可以使用以下代码:

install.packages("installr")
library(installr)
updateR()

Cheers!干杯!

Pablo巴勃罗

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM