Preheat oven to 350 degrees F. Adjust the position of the rack to the center of the oven. Grease and flour 2 (9-inch) pans or 3 (8-inch) pans. Set aside.

In a large bowl, stir together the flour, baking soda, baking powder, salt, cinnamon, nutmeg, and granulated sugar. Set aside. In the bowl of a mixer, cream margarine and brown sugar on low speed, and then increase speed to medium and beat until well-combined. Gradually add the dry ingredients and beat on low speed until just incorporated. Add eggs, 1 at a time, beating well after each egg and scraping down the sides of the bowl after the addition of each egg. Add vanilla, sweet potatoes, pineapple, raisins, and walnuts and blend on low speed until thoroughly mixed.

Pour batter into pans and smooth the surface with a metal spatula. Bake for 1 hour to 1 hour and 10 minutes, or until a toothpick inserted in center comes out clean; when you touch the center of the cake, it should spring back. Allow to cool in pans for 10 minutes, and then invert onto a rack and cool completely.

For icing: In the bowl of an electric mixer, beat cream cheese and butter on medium speed until smooth. Add vanilla and beat until incorporated. Gradually add sugar and beat on low speed until smooth.

Icing the cake: Place 1 cake layer, top-side down, on a cake platter. Using a metal spatula, spread a layer of cream cheese frosting evenly over the top of the cake. Take the next layer and place it on top, rounded-side up. Frost the top and sides of the cake with the remaining frosting. The cake should be refrigerated for about 1 hour to make sure the layers are set. Sprinkle chopped walnuts on top of cake, if desired.