Reputation: 197
> set.seed(12)
> x=matrix(rnorm(100*10),ncol=10)
> x=scale(x,TRUE,TRUE)
> y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100)
> newx=matrix(rnorm(100*10),ncol=10)
> fit=hierNet(x,y,lam=50)
GG converged in 31 iterations.
> yhat=predict(fit,newx)
>
> fit=hierNet.path(x,y)
i,lam= 1 129.72
GG converged in 1 iterations.
i,lam= 2 101.8
GG converged in 20 iterations.
i,lam= 3 79.89
GG converged in 26 iterations.
i,lam= 4 62.69
GG converged in 26 iterations.
i,lam= 5 49.2
GG converged in 26 iterations.
i,lam= 6 38.61
GG converged in 48 iterations.
i,lam= 7 30.3
GG converged in 57 iterations.
i,lam= 8 23.78
GG converged in 62 iterations.
i,lam= 9 18.66
GG converged in 55 iterations.
i,lam= 10 14.64
GG converged in 63 iterations.
i,lam= 11 11.49
GG converged in 60 iterations.
i,lam= 12 9.02
GG converged in 119 iterations.
i,lam= 13 7.08
GG converged in 122 iterations.
i,lam= 14 5.55
GG converged in 139 iterations.
i,lam= 15 4.36
GG converged in 147 iterations.
i,lam= 16 3.42
GG converged in 200 iterations.
i,lam= 17 2.68
GG converged in 374 iterations.
i,lam= 18 2.11
GG converged in 291 iterations.
i,lam= 19 1.65
GG converged in 602 iterations.
i,lam= 20 1.3
GG converged in 657 iterations.
> yhat=predict(fit,newx)
> hierNet.varimp(fit,x,y)
1Error in fit$th[-j, -j] : incorrect number of dimensions
Using sample code from hierNet::hierNet.varimp, I'm not able to get a measure of variable importance. Is there something wrong with my syntax or is there another solution that's viable to obtain variable importance metrics or plots for the hierNet model? Is there a better package that generates a hierarchical model that can be as easily used in an igraph interface as hierNet? If so, I'm open to suggestions.
Upvotes: 0
Views: 193
Reputation: 152
You have to pass a valid hierNet fit (not a path) to the function as shown below
fit=hierNet(x,y,lam=50)
imp = hierNet.varimp(fit, x, y)
You can also plot it
ggplot2::ggplot(as.data.frame(imp), aes(x=Predictor, y=Importance)) +
scale_x_continuous(limits = c(1, 10), breaks = seq(0, 10, by = 1)) +
geom_point( color="red", size=4, alpha=0.6)+
xlab('Variable')+
ylab(' Importance')+
theme_light() +
coord_flip()
Upvotes: 1