Plot function of svm in R - 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)

Related

Is there an R function for creating an interaction plot of a panelAR model?

In order to strengthen the interpretation of an interaction term I would like to create an interaction plot.
Starting Point: I am analyzing a panel data frame with which I fitted a feasible generalized least squares model by using the panelAR function. It includes an interaction term of two continuous variables.
What I want to do: To create an interaction plot, e.g. following the style of “plot_model” from the package sjPlot (see Three-Way-Interactions: link).
Problem: I could neither find any package which supports the type of my model nor a different way to get a plot.
Question: Is there any workaround which can be used for obtaining an interaction plot or even a package which supports a panelAR model?
Since I am quite new to R I would appreciate every kind of help. Thank you very much

ggadjustedcurves, fun="cumhaz" does not work

In the 'survminer' package I have been able to construct adjusted curves using cox model but this only shows me the surival function. When I try to input "events" or "cumhaz" into fun= option this only gives me the same survival function. I found this link
https://github.com/kassambara/survminer/issues/287
Wondering if anyone have any suggestions?
I took the advice of Chung30916 in the comment chain and used the following code
plotdata2<-plotdata%>%
mutate(cumhaz=1-surv)
to make a cumulative incidence curve but, forgive me for my inexperience, how do I proceed? Just plot the graph in ggplot2 using the strata (2 groups in my case) and the x will be the time whereas y will be the cumhaz?
Thanks

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)

SVM plot R library(e1071)

I'm working with a data set that has more than 500 variables, all of them numeric.
I've run the svm() function of the e1071 library and the results are great.
Now I'm struggling with the way to plot my results.
I had reviewed some the plot.svm function, and I can make it work with 4 variables.
But I'm wondering if there is a better way for plotting my results, something that summarizes the model I have created with svm.
Any suggestions?

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