Cannot plot plot a tobit model--getting error message(what do I do)?

Hi, I'm doing a project for school. I'm trying to plot my tobit model. We didn't learn tobit in class but my professor said to write a strong report we'd have to use the tobit model. I've tried plotting it like I plotted my past glm and lm models but I receive an error message.

Any help would be great!

Thanks ~ EX_Tenn

This is what I see:

plot(fitted(tobit_1), resid(tobit_1))
abline(h = 0, col = "red", lwd = 1)

Error: $ operator not defined for this S4 class

Hi @EX_Tenn,

Ideally you'd give us a reproducible example (reprex) of your issue as a starting point. A reprex makes it much easier for others to understand your issue and figure out how to help. A lack of a reprex just makes it much less likely others will reply.

If I had to take a guess, there may not be a method implemented for fitted and/or resid for the type of model you are using, but without a reprex it is hard to know for sure!

I don’t know what package and function you are using to fit your tobit model (this is why a reproducible example would really help!), but since different packages are written by different authors, the structure of the model object is not always the same. So the model object might return something differently structured than you expect when you call fitted() and resid() (assuming, as @tbradley points out, that it has been designed to respond to those functions at all! Sometimes package authors go their own way...)

To dig into this yourself, you might try running:


(At least one of these lines may return an error)

However, if you’re not used to looking at the structure of R objects, you might not find the results very illuminating.

On the “common things are common” principle, are you using VGAM::vgam() to fit your tobit? If so, this worked example (including plotting) might be helpful:

You’ll notice that when they plot the fitteds vs residuals, they do have to use slightly different selectors to access the values from the structures returned by fitted() and resid().

1 Like

Hi ~ Sorry I didn’t get back to you. I’ve been busy writing my final report for this project. I meant to delete this but couldn’t figure out how. Sorry if I caused you some trouble.

I spoke to my professor earlier and she said that plotting residuals wasn’t really a thing with probabolyyy models like they were with linear regression models. I know about Reprex and ha w read up in it but still don’t understand how to upload my data and code.

But I appreciate the help.


I Hi~ I am using VGAM. I’m sorry I didn’t post a Reprex but I don’t know how to do it exactly. I’ve read up on it though. It’s still a bit fuzzy on how it works for me. I also meant to delete this because I spoke to my professor. I just couldn’t figure out how to delete my post.

I appreciate the help for the future though.


To delete a post, try the little grey ... button at the bottom of your original post. After enough time has gone by, though, the forum software may restrict you from deleting (or if you don’t have enough privileges yet due to being a newly joined member). If you get stuck like that again, please feel free to send me a direct message and I can help you delete your post.

If you can’t wrap your head around the fully fledged reprex process, a best effort approximation is much better than nothing, Here’s what I see as the fallbacks:

If you can’t figure out how to use the reprex package, at least post...

  • Self-contained sample data and code that anybody else can copy-paste and run (formatted as code :sparkles:)

if you can’t figure out how to post self-contained sample data and code, at least post...

  • All the code involved in your problem, with extraneous stuff removed (formatted as code :sparkles:)

if you can’t figure out how to post all the code involved in your problem and no more than that, at least post...

  • All the code in the script you were running when you had the problem (formatted as code :sparkles:)

Notice I’m assuming you’ll always format your code as code :grin: — you don’t even have to remember how to do that part! Just use the button in the posting box (it looks like this: </>)

1 Like