Combination patterns - how to calculate? I have a bag of 9 different colored balls, and I want to calculate the probabilities of all the patterns there can be. If I picked 4 balls (with replacement), I could get the following patterns:


*

*all 4 are the same color (eg RRRR) 

*3 are the same color, and 1 is different (RRRY) 

*2 are the same color, and the other two are the same color (RRYY) 

*2 are the same color, and the other two are different
(RRYB) 

*all 4 are different colors (RYBG)


I've actually produced and sorted all the possible combinations, so I know what my end numbers should be. I did that so I could try to understand how to get to the correct number, but I'
m not having much luck, and that won't work once I start getting to larger groups (pulling 5, ,6, 7, 8, or 9).
Calculating cat 1 is easy - it's always 9. There are 9 options for the first ball, and then 1 option (the matching color) for all of the rest.
Calculating the last category is also easy: 9*8*7*6*....
Its the intermediates that are causing me issues. I'm not understanding how to get there. For example, my count showed 216 possibilities where 3 balls were the same color and the other was a different color. To me, this seems like it would be 9*1*1*8, but that's definitely NOT 216. 
How do I calculate these? Especially for larger groups, it will be vital that I understand this - I can't generate all 0.53/5/43/387 billion possible combinations.

In the event that order matters:


*

*All balls same color: $9$

*Three balls same color, one ball different: $\binom{4}{3}\cdot 9\cdot \binom{1}{1}\cdot 8 = 4\cdot 9\cdot 8 = 288$

*Two balls same color, remaining two balls same color: $\binom{9}{2}\binom{4}{2}= 216$

*Two balls same color, remaining two balls different colors: $\binom{4}{2}\cdot 9\cdot 8\cdot 7 = 3024$

*All balls different colors: $9\cdot 8\cdot 7\cdot 6 = 3024$
Adding these together gives: $9+288+216+3024+3024 = 6561$ which happens to equal $9^4$, the total number of arrangements of four balls where order matters, just as we should have expected.

More details for the third case for instance where two balls are of the same color and remaining two balls are of a same different color.
We first pick which two colors appear simultaneously.  This can be done in $\binom{9}{2}$ ways.  Now that we see what colors were selected, there is an unambiguous color whose name comes first alphabetically.  We pick which two spaces are occupied by that color ball.  This can be done in $\binom{4}{2}$ ways.  The remaining spaces are then occupied by balls of the other selected color.  We get then a count of $\binom{9}{2}\binom{4}{2}=216$ ways.
Alternatively, we could pick the color of the first ball.  We then pick which position among the remaining three matches in color.  We then pick the remaining color for the remaining positions.  This can be done in $9\cdot \binom{3}{2}\cdot 8=216$ ways which we see is equal to what we got before.

In response to comment.
9 colors 5 at a time:


*

*All balls same color: $9$

*Four balls same color, one ball different: $\binom{5}{4}\cdot 9\cdot 8 = 360$

*Three balls same color, remaining two balls same: $\binom{5}{3}\cdot 9\cdot 8 =  720$

*Three balls same color, remaining two balls different: $\binom{5}{3}\cdot 9\cdot 8\cdot 7 = 5040$

*Two balls same, Two other balls same, one ball different: $\binom{9}{2}\binom{5}{2}\binom{3}{2}\cdot 7 = 7560$

*Two balls same, remaining all different: $9\cdot \binom{5}{2}\cdot 8\cdot 7\cdot 6 = 30240$

*All balls different: $9\cdot 8\cdot 7\cdot 6\cdot 5 = 15120$
Checking, we get $9+360+720+5040+7560+30240+15120=59049=9^5$, just as we expected.
Your errors were doing something totally out of left field for the 3/2 case that I can't explain your thought process... adding? $\binom{3}{2}$?  Where did those come from?
The other mistake was much more common.  In the 2/2/1 case, you did "Pick two spaces for the first color" then "pick what the first color actually is" followed by "pick two spaces for the second color" followed by "pick what the second color actually is" finally followed by "pick the color for the last space."
This is incorrect and overcounts because you can use different sequences of answers to get the same result.  We can't tell which was the "first" color and which was the "second" color after they have already been distributed and your counting makes the difference between "first" and "second" color somehow significant when it shouldn't have been.
For example:
"First two spaces": $\underline{\star}~\underline{\star}~\underline{~}~\underline{~}~\underline{~} \rightarrow$ "Red": $\underline{R}~\underline{R}~\underline{~}~\underline{~}~\underline{~}\rightarrow$ "Third and fourth spaces": $\underline{R}~\underline{R}~\underline{\star}~\underline{\star}~\underline{~}\rightarrow$ "Yellow": $\underline{R}~\underline{R}~\underline{Y}~\underline{Y}~\underline{~}\rightarrow$ "Blue": $\underline{R}~\underline{R}~\underline{Y}~\underline{Y}~\underline{B}$
gave the same result as:
"Third and fourth spaces": $\underline{~}~\underline{~}~\underline{\star}~\underline{\star}~\underline{~} \rightarrow$ "Yellow": $\underline{~}~\underline{~}~\underline{Y}~\underline{Y}~\underline{~}\rightarrow$ "First two spaces": $\underline{\star}~\underline{\star}~\underline{Y}~\underline{Y}~\underline{~}\rightarrow$ "Red": $\underline{R}~\underline{R}~\underline{Y}~\underline{Y}~\underline{~}\rightarrow$ "Blue": $\underline{R}~\underline{R}~\underline{Y}~\underline{Y}~\underline{B}$
Instead, select both colors used for two balls simultaneously, then for the earlier appearing alphabetically pick which spaces it uses.
$\binom{9}{2}$ to choose the colors, $\binom{5}{2}$ to pick the spaces for the alphabetically first selected color, then $\binom{3}{2}$ to pick the spaces for the remaining selected color, finally $7$ choices for the final color, giving $\binom{9}{2}\binom{5}{2}\binom{3}{2}\cdot 7 = 7560$ arrangements.
Alternatively, pick the location of the singleton color and what color it is.  Then in the furthest left remaining available position pick a color for it.  Pick one of the remaining positions to match the color.  Finally pick a color for the remaining positions, giving a total of $5\cdot 9\cdot 8\cdot 3\cdot 7=7560$, same as before.
In both of these correct ways of counting, we make sure that there is an unambiguous single way of arriving at each outcome where we can't rearrange our answers in a way to give the same result like we could for yours.  We accomplished that by noting that there is an unambiguous "first" color when ordering them alphabetically in the first method.  We accomplished that by noting there is an unambiguous "furthest left" remaining available space in the second method.
