Further Exercises for MW24.1 - 02
-
Question
Install R and a frontend for R, e.g. R-Studio.
Save the file DYQ.csv in your working directory. (Don’t take the detour of opening the file in your spreadsheet program (e.g. Microsoft Excel) and save it from that program. Spreadsheet programs often do considerable damage to your data. By taking the detour through your spreadsheet program you will often change numbers to what the spreadsheet program thinks is a date. If you find it difficult to save a link from your browser, try clicking with the right mouse button on the link. In many browsers this right-click opens a menu where you can choose “Save link as…” or something similar.)
If you are not sure which directory R currently uses as a working directory, you can use the command
getwd()
In RStudio you can also use the menu Session / Set Working Directory / Choose Directory to choose your working directory.
Read the file
DYQ.csv
with the commandDYQ <- read.csv("DYQ.csv")
Now the variable
DYQ
contains your data. In this exercise we have a brief look at your data:
-
Use the command
nrow(DYQ)
to determine the number of rows in your data. How many rows do you have? -
Use the command
names(DYQ)
to determine the names of the variables in your data. How many variables do you have? -
Use the command
mean(DYQ$X3)
to determine the mean of the variableX3
in your data. -
Use the command
median(DYQ$X3)
to determine the median of the variableX3
in your data. -
Use the command
sd(DYQ$X3)
to determine the standard deviation of the variableX3
in your data. (If Moodle complains about an “incomplete answer”, please check whether the format of your answer is in line with Moodle’s expectations. Make sure that Moodle and you interpret decimal separators in the same way. Depending on the settings of your computer it is possible that Moodle expects decimal numbers like3.14
and not like3,14
).
-
Use the command
-
Question
Your sample of the random variable contains independent and normally distributed observations: . You are looking for an estimator for . Which of the following statements are correct:
The estimator is an unbiased estimator for .
Yes / No
The estimator is an unbiased estimator for .
Yes / No
The estimator is an unbiased estimator for .
Yes / No
The estimator is an unbiased estimator for .
Yes / No
The estimator dominates .
Yes / No
The estimator dominates .
Yes / No
-
Question
You use a level of significance of 0.1.
- You assume that your test statistic follows a standard normal distribution. How large (in absolute terms) can your test statistic (for a two-sided test) be, so that you still don’t reject your Null-hypothesis? (You can calcualate this value with R.)
- You assume that the random variable follows a normal distribution with unknown mean and standard deviation 3. Your sample contains 27 observations. The sample mean is -10. Your Null-hypothesis is that has a mean of 0.3. How large is the absolute value of your test statistic?
- You still assume that the random variable follows a normal distribution with unknown mean and standard deviation 3. Now you consider a sample with 27 observations and sample mean -10. Your Null-hypothesis is still that has a mean of 0.3. How large is the -value (for a two-sided test, rounded to 4 decimal places)?
-
Question
Your data in the file DFG.csv contains two variables:
Z
andr
. The variabler
tells you which group (D or H) the observationZ
belongs to.Compare the mean of
Z
for two groups D and H with the help of a (two-sided) -test.- Your Null-hypothesis is that the mean of the normally distributed Z is the same in both groups. How large is the -value for this -test?
- You use a level of significance of 10%. Do you reject your Null-hypothesis? Yes / No
-
Question
The random variable follows a normal distribution with unknown variance . You draw a sample with 15 observations. You find a sample mean of 4 and a sample standard deviation of 3.
- Determine a 95%-confindence interval for your estimation of the expected value of : .
- What is the lower boundary of the interval?
- What is the upper boundary of the interval?
-
Question
A random variable is distributed as follows:
We have .
In your sample you have the following observations:
.
What is the maximum-likelihood estimator for ?
-
Question
The file DEJ.csv contains two variables:
X
andY
.To explain
Y
as a linear function ofX
, you estimate the model.
- Which value do you estimate for ?
- Your (two sided) Null-hypothesis is . Determine the -value for this test (report at least 4 decimal places).
- You use a level of significance of 5%. Can you reject your Null-hypothesis? Yes / No
- What is the lower boundary of the 95% confidence interval for ?
- What is the upper boundary of the 95% confidence interval for ?
-
Question
Use data from the file D03b.csv.
You want to measure the effect X1 has on Y1, the effect X2 has on Y2, the effect X3 has on Y3, and the effect X4 has on Y4. For each case below, select the most suitable specification and provide the point estimate of the effect.
-
By how many percentage points does
Y1
change approximately whenX1
changes by one unit? -
What is the elasticity of
Y2
with respect toX2
? -
What is the marginal effect of
X3
onY3
? -
By which amount does
Y4
change whenX4
changes by 1 percentage point?
-
By how many percentage points does
-
Question
Use the data from the file DUX.csv. Based on this data you estimate the following relationship:
.
- Which value do you estimate for ?
- Your (two sided) Null-hypothesis is . Determine the -value for this test (report at least 4 decimal places).
- You use a level of significance of 5%. Can you reject your Null-hypothesis? Yes / No
- What is the lower boundary of the 95%-confidence-interval for ?
- What is the upper boundary of the 95%-confidence-interval for ?
-
Question
Consider the following model:
The variable indicates whether you are in situation DKZ or GJS: In the case of DKZ you have . In the case of GJS you have .
The variable indicates whether you are in situation HQF or YNA: In the case of HQF you have . In the case of YNA you have .
The mean values of for the four different combinations of DKZ and GJS and HQF and YNA are shown in the following table:
- What is ?
- What is ?
- What is ?
- What is ?
-
Question
Save the file DLE.csv in your working directory. You want to estimate the mean of the absolute value of
X2
.
-
What is the plug-in estimate of the mean of the absolute value of
X2
? - Use a bootstrap (with 10000 replications) to determine the standard deviation of this estimate
-
You assume this estimate follows a normal distribution. Use a parametric bootstrap to determine the lower boundary of a 90%-confidence interval for the mean of the absolute value of
X2
?
-
What is the plug-in estimate of the mean of the absolute value of
-
Question
The random variable follows a normal distribution with unknown mean and known standard deviation .
According to your prior the following holds:
- with probability 1/6,
- with probability 5/6.
The probability for all other values of is zero.
You have one observation, .
In the following you can use
dnorm
to calculate the density function of the normal distribution.E.g.
dnorm(4,8,2)
yields the density of the normal distribution for when and .
- What is the posterior probability ?
- What is the posterior probability ?
- Now you have two observations: . What is the posterior probability ?
-
Question
The file DMM.csv contains a variable
X
. ThisX
is a sample of the random variable . Here we write the normal distribution as where is the mean and is the precision. You assume that follows a normal distribution: where is the variance of . You have the following priors: , ( denotes the Gamma distribution).To obtain the necessary precision, please use
run.jags
defaults. Please don’t change options or modules.
- What is the lower boundary of the 95%-credible-interval for ?
- What is the upper boundary of the 95%-credible-interval for ?
- What is the lower boundary of the 95%-credible-interval for ?
- What is the upper boundary of the 95%-credible-interval for ?
- What is the posterior probability (a number between 0 and 1) of ?
- What is the posterior probability (a number between 0 and 1) of ?
-
Question
The file DLX.csv contains an independent variable
L
and a dependent binary variableR
.You estimate the following model:
where is the logistic distribution.
- What is your estimate for ?
- What is the marginal effect of for the average value of in your data?
- What is the average marginal effect of ?
- What is the marginal effect of if ?
- What are the odds for if ?
-
Question
The file DVU.csv contains two independent variables
X1
, andX2
, and a dependent count variableY
. (Hint: In the following you may find the libraryMASS
useful.)
-
Use a Poisson model where you explain
Y
as a function ofX1
andX2
. What is the coefficient ofX2
? -
Now you use a negative binomial model to explain
Y
as a function ofX1
andX2
. What is now the coefficient ofX2
? - In the negative binomial model, what is your estimate for the parameter ?
- Your Null-hypothesis is that , i.e. that the negative binomial model does not significantly improve the goodness of fit of the Poisson model. Use a Likelihood-Ratio test to test this hypothesis. Which -value do you get (rounded to 4 decimal places)?
-
Use a Poisson model where you explain
-
Question
The file DBJ.csv contains three variables, b, H and R. The variable
b
denotes to which group observations belong.R
is our dependent variable.We write the normal distribution as where is the mean and is the precision. denotes the Gamma distribution. You use JAGS to estimate the following model with random effects:
where the group specific random effect and the residual . Here and are the precision of and , respectively.
Your priors are: , , .
To obtain the necessary precision, please use
run.jags
defaults. Please don’t change the options or modules.
- What is the 50%-quantile of your posterior for ?
- What is the 50%-quantile of your posterior for ?
- What is the posterior probability (a number between 0 and 1) of ?
-
Question
The file DBN.csv contains the variables
X
,Y
andZ
. You estimate the model .
- Use a standard OLS model to estimate the model. What is the coefficient of ?
- Provide a -value for the test of the Null-hypothesis that the coefficient of is zero (round to 4 decimal places)?
-
Now use the variable as an instrument for . Use the command
ivreg
from the AER library to estimate the coefficient of for this model. - For the instrumental variables model provide a -value for the test of the Null-hypothesis that the coefficient of is zero (round to 4 decimal places)?
-
Question
The file DNW.csv contains eight independent variables,
X1, X2, X3, X4, X5, X6, X7, X8
, and a dependent variableY
. You estimate the following (full) model:
-
What is the coefficient of
X7
in the full model? -
You simplify the model and include only terms which are significant on a 5% level in the above estimation. You drop insignificant terms only once. If you find insignificant terms in your simplified model, you keep them. You also keep
X7
. What is now the coefficient ofX7
? -
Use the function
extractAIC
to obtain the AIC of this (simplified) model. (Note: the functionextractAIC
returns two numbers. Only one of them is the AIC). -
Now you use the
step
function to simplify the (full) model based on the AIC. If thestep
function has removedX7
from the model, addX7
back to your model. What is the coefficient ofX7
in this model? -
Use the function
extractAIC
to obtain the AIC of this model.
-
What is the coefficient of
-
Question
The file DRL.csv contains an independent variable
H
and a dependent binary variableM
.You estimate the following model:
where is the standard normal distribution.
- What is your estimate for ?
- What is the marginal effect of for the average value of in your data?
- What is the average marginal effect of ?
- What is the marginal effect of if ?
-
Question
A random variable follows a distribution with density function if and otherwise.
Your sample contains the observations .
What is the Maximum-Likelihood estimator for ?
-
Question
The data in the file DGX.csv contains 8 variables,
Yjd, Ykm, Yps, Yuf, Xjd, Xkm, Xps, Xuf
. You investigate the effectXjd
has onYjd
, the effectXkm
has onYkm
, the effectXps
has onYps
, the effectXuf
has onYuf
. For each case below, select the most suitable specification and provide the point estimate of the effect.- Use a specification where
Yuf
changes by a fixed amount whenXuf
changes by a given percentage. By which amount doesYuf
change whenXuf
changes by 1 percentage point? - Use a specification where
Yjd
changes by a fixed number of percentage points whenXjd
changes by one unit. By how many percentage points doesYjd
change approximately whenXjd
changes by one unit? - Use a specification where the elasticity of
Ykm
with respect toXkm
is constant. What is the elasticity ofYkm
with respect toXkm
? - Use a specification where the marginal effect of
Xps
onYps
is constant. What is the marginal effect ofXps
onYps
?
- Use a specification where
-
Question
The file DTK.csv contains a variable
D
. ThisD
is a sample of the random variable . You assume that follows a normal distribution: where is the variance of . Your priors are , . We write the normal distribution as where is the mean and is the precision. denotes the Gamma distribution.To obtain the necessary precision, please use
run.jags
defaults. Please don’t change options or modules.The last two questions belong to chapter 12 of the lecture! Remember that if is the probability of an event, then the odds are .
- What is the lower boundary of the 95%-credible-interval for ?
- What is the upper boundary of the 95%-credible-interval for ?
- What is the lower boundary of the 95%-credible-interval for ?
- What is the upper boundary of the 95%-credible-interval for ?
- What are the posterior odds of ?
- What are the posterior odds of ?
-
Question
Use the data from the file DSQ.csv. You are interested in the interquartile range of the variable
X2
. The interquartile range is the distance between the 25% and 75% quantiles. In R you can use the functionIQR(x)
to determine the interquartile range ofx
.
-
What is the plug-in estimate of the interquartile range of
X2
? - Use a bootstrap (with 10000 replications) to determine the standard deviation of this estimate.
-
What is the plug-in estimate of the interquartile range of
-
Question
The file DYM.csv contains four variables, B, D, J and p.
The variable
p
denotes the group to which an observation belongs.You compare the following two models: A standard OLS model and a model with a random effect.
- Here is the OLS model:
- Now you extend this model with a random effect :
You use
lmer
from thelme4
library to estimate the model with random effects.
- What is your estimate for in the OLS model?
- What is your estimate for in the OLS model?
- What is your estimate for in the model with a random effect?
- What is your estimate for in the model with a random effect?
- What is your estimate for the standard deviation of the random effect ?