The short answer is that it varied widely by time and place, with some polities taking their militia duties very seriously and others trying to shift the burden onto others. It would not have been uncommon to see a very organized, very professional-looking militia in the northern or north-western states prior to the 1830s, but on the flipside, it would also not have been uncommon to see a very poorly organized militia in those same places around the same time.
The notion of "farmers and shopkeepers" grabbing guns and harassing invaders is not a bad one, necessarily, but it makes a few common errors that a lot of people - including professional historians - tend to make when they discuss the militia: they see it only as s military force, when the militia was as much a cultural and social institution. It was a fire-fighting force, a police force, a means of shifting property-owning men into easily recognizable hierarchies, it was a social club, and a means for men to voice their political opinions outside the voting booth. It connected to notions of citizenship (since, technically, the militia was a force of armed citizens not just men-who-live-here, and the difference is important), masculinity, and bigger ideas of a man's individual and collective relationship to power.
I'll give two examples that more or less show both extremes. One is the Detroit militia in the early 19th century, and the other is Philadelphia in the 1830s, the former is an example of the militia as a meaningful institution and the latter is a view of the militia on the wane.
In 1805, decorated Revolutionary War veteran William Hull was appointed Governor of the Michigan territory. Hull had quite a job in organizing the place, as it was not only a bustling fur trade depot and important location for treaty annuities and council fires for regional Native groups, it was also predominantly francophone, with a large transient population and small permanent one. The people who loved there weren't stereotypical 19th century Americans, is what I'm getting at. That said, Hull set out to professionalize the militia, a duty he took very seriously in part due to his military experience, and because one of his main roles as governor was to defend Detroit against possible attack from the British or Native Americans, or both.
Hull organized the militia along a somewhat complicated two-track scheme: one track was the typical militia, consisting of land-owning men who could afford to arm and equip themselves in a standard militia regiment. Then he had a "Voluntary Legionary Corps" which consisted of men of a little higher income or property, who could be relied upon to serve when called, and to do it on short notice and with the expectation that they would bear a lopsided burden of military duties. The former were required to uniform themselves along pretty familiar lines: blues coats (or a local variation, the capot), white weskit and trousers, and a round leather hat.
The Voluntary Legionary Corps, on the other hand, was expected to wear a much more complicated uniform: buff-faced blue coattees (think George Washington's continental army uniform), white weskit and breeches, a cocked hat with a rose cockade, and long boots with silver spurs.
Hull ended up having to reorganize his militia a few times, but eventually he ended up with a fairly robust militia, and at least 300 of them were organized and fighting at the outbreak of the War of 1812. They were not only organized and uniforms (even though to many observers the francophonic militia of Detroit looked in appearance and order to be no different from their Canadian counterparts, and were described as dressing in "the Indian mode"), but they fought with distinction in the battles of Brownstown and Maguaga, and eventually at the ill-fated battles at the River Raisin. There was at least one company of "freeblack renegadoes" from Kentucky who fought in those battles as well. Even though the 3500 residents of Detroit likely should have been able to muster a larger militia, the men who did show up on the day were organized, well-led, and motivated, and proved it on the battlefield even against Native warriors and British regulars. It was in every sense the militia serving its military purpose.
Contrast that to Philadelphia following the War of 1812. For a variety of reasons, the regulations regarding service in the militia fell unevenly on the wealthy and poor: wage-workers in the still-sorting-out industrial capitalist marketplace found the burdens of service unfair, as they were badly (and sometimes even un-) paid for their required time, which also lost them a day's wage, and having to keep up-to-date military accouterments, including weapons but especially a uniform, were onerous to all but the wealthy elite.
The problem was further compounded by the allowance of "private" companies to form, and they were often exclusive organizations that required a higher cost of membership and invites. Because they were left to organize themselves, the private companies often existed solely on paper and neglected their military or social duties, leaving the poorer men in the public companies again footing the burden.
Militia musters turned into folk protests that were often modelled on burlesque: protesting militia men might take their requirements for a backpack, for instance, to a ludicrous extreme, some men going so far as to strap stoves to their back, and others protested by wearing motley or dressing as other colorful characters. The idea was to mock the requirements and call attention to the lopsided burden, but to stay within the letter of the law.
One of the more interesting ways this manifested was when the Philadelphia men used the militia's democratic nature against itself. Regiments were expected to elect their own officers, and ideally within a well-balanced society, the men of high character who had shown themselves to be interested in the local community and were well-suited to leadership, were given the captaincies and colonelships.
But in 1825, a Philadelphia regiment elected a man named John Pluck, an ostler at a public stable, and by all accounts a "stupid, ignorant fellow." Pluck's election was intended as a thumb in the eye to the establishment, and his election was a horror to the elites watching from outside the regiment. Pluck likely had a developmental disability, and was short, bowlegged, and stoop=shouldered. His job as an ostler was as a stall-sweeper, so he was often visibly filthy, and the lack of a robust family or close friends meant that he could do nothing but appear that way when he had to muster and march with his company.
A quote from a newspaper gives an illuminating account of Pluck:
On Wednesday last was enacted the Grand Military farce, in which the redoubtable John Pluck made his debut in the character of colonel of the Merry 84th. The sport was not so great as was anticipated by the lovers of frolic and fun, and from the complete indifference with which the Colonel went through his part, apparently unconscious of everything around him, staring with stupid indifference and scarce possessing the spirit to answer occasional questions... It is said he once mustered sufficien Pluck to say 'he did not know where they were going to march him but would tell them all about it when he got back, if he could remember the way...' which was much applauded as a brave speech by his friends and clamorously encored by the great crowd which had gathered around his quarters.
Pluck was not really in on the joke (and may not have been capable of understanding it), which made the farce all the more public and ridiculous. The parade itself was a topsy-turvy of a military parade, and gleefully highlighted some of the visibly lopsided expectations of service: men carried broomsticks and cornstalks in place of muskets, something which had been done before when men couldn't afford their required weapons, but under Pluck's command, the joke was taken to extremes.
Whether or not Pluck and his election had a huge effect on the continued existence of the militia is an open question, but it served the singular and extremely effective purpose of popularizing many of the issues faced by lower-income men who were obligated to serve in a system that was not built with their particular situations in mind. Part of this was due to a changing culture and changing ideas regarding military service, and partly this was due to the sweeping economic changes brought upon by the lightning-fast industrialization in the United States. Pluck's election, for many, was a public display of rejecting the notion of the militia as it was organized.
We can't know exactly what these Philadelphians would have done in the unlikely event of a foreign attack, but the institution of the militia had always been about more than "making a military appearance:" it was a reflection of the citizenry, a reflection of the thoughts and feelings and opinions of the propertied men of a region, and whether they organized themselves in strict and controlled companies or rampaged around a city in a mob, it was done in a manner that was deliberately channeled through this public obligation to serve. Sometimes this meant that men proudly wore the uniform and served with distinction when powdersmoke fogged the battlefield, and other times it meant making an expasperated mockery of an unworkable and inflexible system.
Sources below