简体   繁体   中英

How do I create a Tobit model in R?

Fairly new to R, so please bear with me.

I'm hoping to create a model where my outcome variable is only positive - number of conversions from Facebook ads.

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:

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)"

Perhaps I'm not approaching this correctly, or the tobit function isn't the correct method. 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? 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. You can use the following code:

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

Cheers!

Pablo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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