I am trying to make a variable selection using AIC & Cp Mallows methods.
require(leaps) b <- regsubsets(time~radius_mean+texture_mean+perimeter_mean+area_mean+smoothness_mean+compactness_mean+concavity_mean+concave_points_mean+symmetry_mean+fractal_dimension_mean+radius_se+texture_se+perimeter_se+area_se+smoothness_se+compactness_se+concavity_se+concave_points_se+symmetry_se+fractal_dimension_se+radius_worst+texture_worst+perimeter_worst+area_worst+smoothness_worst+smoothness_worst+compactness_worst+concavity_worst+concave_points_worst+symmetry_worst+fractal_dimension_worst+tumor_size+lymph_node, datasetX) rs<-summary(b) rs$which n<-nrow(datasetX[,3:35]) p<-ncol(datasetX[,3:35]) (AIC<-n*log(rs$rss/n)+(2:p)) plot(AIC~I(1:(p-1)),ylab="AIC",xlab="Number of Predictors")
The plot I get is:
The plot says that the minimum AIC is for 8 predictors that, looking at the which table, are perimeter_mean, area_mean, smoothness_mean, concave_points_mean, perimeter_se, area_se, smoothness_se and concave_points_worst.
Everything seems ok. But when I try to do the same for Cp Mallows criteria, I get:
plot(1:(p-1),rs$cp,xlab="Number of predictors",ylab="Cp Mallows") Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ
That's true. The model has 32 variables and rs$cp is just 8. But I cannot understand why. Could you help me? Maybe am I doing something wrong?
Thank you in advance. Regards!