# R: Automatically group the insignificant dummy levels and re-fit the model

I am running a reg model with Weekdays as my dummy variables so I can find the weekday effects to the output metric. The picture below shows the results from this regression, and only Sunday is significant. In this case, I usually like to group the Mon, Sat, Thur, Tue & Wed into one group along with the baseline "Friday" as they are all insignificantly different to the base-line Friday (named as "Rest"), and re-run the model with two dummies "Sun" and "Rest". (one of the two will be automatically chosen as the base line by R). I wonder is there some package or method R can do this auto-regrouping and re-run the model by itself till all grouped dummy groups are significant.

thank you.

• This sounds like an R question--it clearly is asking for R code--so it's sure to get close votes. But there's an important statistical question beneath it related to the inadvisability of abusing p-values in this way. It seems likely this procedure is going to be used inappropriately to determine some "optimal" way to group the days. Consider addressing that issue before you use this procedure.
– whuber
Aug 22, 2017 at 17:14

1. The $p$-values of the new model will be inaccurate because they won't account for how you selected the model based on previous $p$-values.
2. What's more, $p$-values of coefficients are a bad way to select models because they don't directly quantify any useful measures of model quality.
3. Finally, while obtaining $p < α$ tells you that a null hypothesis is infeasible, obtaining $p > α$ doesn't much support its feasibility, so when a test fails to reject the null hypothesis, it doesn't tell you anything.