r - Why won't lda() accept a string as it's 'formula' argument? -
i'm doing regression analysis , i've come across strange behavior lda
function in mass
library. specifically, seems unable accept string it's formula
argument. doesn't appear problem base glm
functions. i've constructed small example using iris
illustrate point.
library(mass) myform<-"species~petal.length" # disregard warnings line, they're artifact of example. works. lgriris<-glm(formula=myform, data=iris, family="binomial") # breaks. ldairis<-lda(formula=myform, data=iris)
the final line above throws:
error in lda.default(formula = myform, data = iris) : argument "x" missing, no default
which, judging documentation, seems indicate lda
doesn't think it's been provided formula
argument. know why happening, or how fix it?
you can turn "myform" formula using as.formula()
:
myform <- "species~petal.length" class(myform) # [1] "character" myform <- as.formula(myform) class(myform) # [1] "formula" myform # species ~ petal.length lda(formula=myform, data=iris) # call: # lda(myform, data = iris) # prior probabilities of groups: # setosa versicolor virginica # 0.3333333 0.3333333 0.3333333 # group means: # petal.length # setosa 1.462 # versicolor 4.260 # virginica 5.552 # coefficients of linear discriminants: # ld1 # petal.length 2.323774
Comments
Post a Comment