Here you will find daily news and tutorials about R, contributed by over 750 bloggers.
There are many ways to follow us - By e-mail:On Facebook: If you are an R blogger yourself you are invited to add your own R content feed to this site (Non-English R bloggers should add themselves- here)

A common experience for those in the social sciences migrating to R from SPSS or STATA is that some procedures that happened at the click of a button will now require more work or are too obscured by the unfamiliar language to see how to accomplish. One such procedure that I’ve experienced is when calculating the marginal effects of a generalized linear model. In this exercise set, we will explore calculating marginal effects for linear, logistic, and probit regression models in R.

Exercises in this section will be solved using the Margins and mfx packages. It is recommended to take a look at the concise and excellent documentation for these packages before continuing.

Exercise 1
Load the mtcars dataset. Build a linear regression of mpg on wt, qsec, am, and hp.

Exercise 2
Print the coefficients from the linear model in the previous exercise.

Exercise 3
Using Margins package find marginal effects.

Exercise 4
Verify that you receive the same results from Exercises 2 and 3. Why do these marginal effects match the coefficients found when printing the linear model object?

Exercise 5
Using the mtcars dataset, built a linear regression similar to Exercise 1 except include an interaction term with am and hp. Find the marginal effects for this regression.

Exercise 6
Using your favorite dataset (mine is field.goals from the nutshell package), construct a logistic regression.

Exercise 7
Explain why marginal effects for a logit model more complex than for a linear model?

Exercise 8
For the next two exercises, you may use either package. Calculate the marginal effects with respect to the mean.

Exercise 9
Calculate the average marginal effects.

Exercise 10
If these marginal effects are different, explain why they are different.