Error in effect.default....argument "offset" is missing, with no default - r

I'm looking to plot the effects for a TOBIT regression model at -1SD and +1SD using a bar graph. I would normally use a line graph, but my co-authors have asked for a bar graph instead. I have had some help identifying what I should do here, but I am getting an error that no one seems to be able to figure out.
Creating dataframe - this runs fine.
tobitforgraph <- survreg(Surv(S1, S2, type='right') ~ +(Var1centered)*Var2centered*Var3standardized,data=Datafilename, dist='gaussian', robust=TRUE))
Load effects library.
library(effects)
Extract values for plotting (the values coming from here are then supposed to be used to plot as normal in Excel, although there may be a way to do it in R; regardless, this is where I am getting an error).
print((intplot<-as.data.frame(ef< Effect(c("Var1centered","Var3standardized"),mod=tobitforgraph,xlevels=list(Var1centered=c(-.4987531,.5012469),Var3standardized=c(-1.0,1.0), data=subset(Datafilename, Var4==-0.5025))))))
Error that comes from this value extraction:
Error in Effect.default(c("Var1centered", "Var3standardized"), mod = tobitforgraph, :
argument "offset" is missing, with no default

Related

can't fit GLM with family binomial and log link to estimate RR

I am trying to estimate relative risk using log-binomial model using the glm function. Although it works well with univariable analysis, it gives me an error message when I add multiple variables
This is the error message I get
Error: no valid set of coefficients has been found: please supply starting values.
I did some search but couldn't find a way to solve this issue
Thanks
This error can happen for one of two reasons. First, if any of the deviances are infinite, and second, if invalid starting values have been supplied. Assuming that you haven't supplied starting values, then I suggest doing so, by using the start = option in glm.
Having said that, the only times I have seen this problem is when either the dataset is pathological, or the model is wrong (for example using an inappropriate link function). Since you don't supply a reproducible example, there isn't much more we can say.

Plot function of svm in R

I have constructed a model of svm on a dataset of Fraud transactions , but when I am trying to plot the model it is neither showing any error nor showing any plot. My code is -
>library(e1071)
>attach(FraudTransData)
>model2<- svm(FraudTransData$Fraud_Ind~., data= FraudTransData)
>plot(model2, FraudTransData)
I used the same plot function on another dataset cats and it showed a successful plot. I am unable to understand where have I gone wrong.
How many inputs do you have?
The code you wrote does not work if you have more than two. You should add arguments formula and slice in the plot function.
Check the 'iris' example at help(plot.svm)

Trouble with abline

I'm having trouble plotting 2 abline()s on a graph of the log10 Brain mass and log10 body mass. I'm following someone else's script but it just doesn't work for me. This is what I have:
This is the graph produced:
Why are the lines off there like that? Are the values I'm getting for the intercept and slope incorrect, or am I using the wrong ones? I've done other examples of this and its worked OK, but I've always ended up using the first model, never the second one so I'm not sure if I'm using the right values.
If you want to represent a linear regression of the log of the body mass compared to the log of the brain mass, the code is:
model <- lm(log10(brain)~log10(body))
then
abline(model$coefficients[2], model$coefficients[1])
When you don't know which parameter to enter in a function, use the help of that function. For abline(), the first parameter is the slope and the second one is the intercept.
Currently, your model use log10(brain), log10(body) and class.
If you want to assess the quality of your model, look at the residuals.
plot(model)
You can also just use the result of your lm like this:
model <- lm(log10(brain)~log10(body))
plot(log10(brain)~log10(body))
abline(model,col=2)

weighted box plot unknown error

My question is with regards to creating a weighted box plot using ENmisc library. I have a dataframe and I want to plot the boxplot based on two different categories (both type chr).
The error given is ## Error: missing value where TRUE/FALSE needed from the line wtd.boxplot(df2J$mean_P32 ~ df2J$mode_Litho,weights=df2J$length). I've attached a log of the portion of code in question below which shows the values of each data type as well as that there is not any data missing. The last line produces a boxplot similar to the one I would expect from the line above.
Unfortunately I don't know how to recreate this error with a general example so I haven't provided code that can be run.
If anyone could shed some light on this error it would be much appreciated.
Other Info:
The plots work if I use the base package boxplot function.
There are other ways I could create weighted boxplots if needed such as this but I really don't see any reason this shouldn't work.
wtd.boxplot function
ENmisc library
I'm not sure why this doesn't show up in the Knitr ourput but The error that shows up in the R console is Error in if (any(out[nna])) stats[c(1, 5)] <- range(x[!out], na.rm = TRUE) :
missing value where TRUE/FALSE needed
I have the same problem and it happens because (I think) you have only 1 member for one of your groups. Check it.

Errors in stat_smooth line fit for some groups cause no plot to be produced

I'm trying to plot curves for a data set with a large number of different groups. I want to visualize the curves all together on one graph fit to a common model (stat_smooth with a glm with a quasipoisson error), so, I'm using color to group them. However, for some curves, the fitting function borks out and I get
Error: no valid set of coefficients has been found: please supply starting values
And then there is no plot.
Is there a way to have the plot come up without the curves for those "bad" groups? I ask as there are a huge number of groups, and while I could write an error-check script to then kick them out of the data, it would be nicer if everything but those with an error would plot.
I don't think there's a very easy way to do this, but here's what I would try:
Write a loop or an ldply statement to run the model you have in mind, wrapped in try: e.g.
trymodelList <- ldply(mydata,.(grp1,grp2),glm,formula=y~x,family="quasipoisson")
(I think that the current data chunk should get filled in automatically as the data argument).
Figure out which ones were bad: something like alply(trymodelList,inherits,what="try-error")
Use this logical vector to subset out the groups you don't want, then pass the subsetted data to geom_smooth instead of the full data set.
I know there are a few details left out ...
edit: I see that I've essentially written down your "write an error-check script ... then kick them out of the data" strategy. Sorry, I don't think there's an easier way to do this. You might try the ggplot users' list ...

Resources