I am using stepAIC() function from library (MASS).
And per the documentation it says that I can pass an 'object':
a model of an appropriate class. This is used as the initial model in the stepwise search.
What is an appropriate class?
I created a model using ksvm() but, stepAIC seems not to accept it.
I am using the code:
stepAIC(svmFit, direction="both")
And I get the error
Error: $ operator not defined for this S4 class
The object svmFit I am passing is of class:
[1] "ksvm"
attr(,"package")
[1] "kernlab"
It's not exactly clear to me what models are accepted, but we can take some guesses based on the source.
It needs a model that can be accessed using
$(i.e. typically an S3 class). Your model is an S4 class, and therefore by definition will not work.In addition, there need to be at least a working method for the model class for the the following functions:
formula,terms,update.formula,nobs,extractAIC,deviance,update(judging from a scan of the source). This can be a default method, such asstats:::formula.default, which finds eitherx$formula,$terms,$call$formulaor a formula attribute.If one or more of these methods have not been implemented, then it will also fail.
Basically, it is making a lot of assumptions that work for many of the modelling functions, such as
lmandglm. One can write a new modelling function that will create models that are compatible withstepAIC, and a comprehensive list may be difficult to create!