The acronym desk stands for didactic econometrics starter kit. The primary audience of this package are students and teachers, but also casual users. desk …
In the following, we present the most important and easy-to-grasp features. We illustrate these features in the form of functions and mostly through resulting graphical representations.
ols()
As the cornerstone of econometrics, the OLS method is typically the
initial step in computing an estimator. Our version is similar to the
lm function (linear
model, a base function in R), but it yields a more
appealing output and various applications in combination with the base
functions plot()
and print()
. The following
code creates data points and plots them:
A regression line is now estimated and the results are presented both, numerically and as a straight line through the data points:
my.model.est <- ols(y ~ x)
my.model.est
#>
#>
#> coef std.err t.value p.value
#> (Intercept) 1.0000 1.4491 0.6901 0.5615
#> x 0.8000 0.5292 1.5119 0.2697
plot(my.model.est)
Being useful to calculate further figures or reproduce them, details of the estimation can be shown:
print(my.model.est, details = TRUE)
#>
#>
#> coef std.err t.value p.value
#> (Intercept) 1.0000 1.4491 0.6901 0.5615
#> x 0.8000 0.5292 1.5119 0.2697
#>
#>
#> Number of observations: 4
#> Number of coefficients 2
#> Degrees of freedom: 2
#> R-squ.: 0.5333
#> Adj. R-squ.: 0.3
#> Sum of squ. resid.: 2.8
#> Sig.-squ. (est.): 1.4
#> F-Test (F-value): 2.2857
#> F-Test (p-value): 0.2697
In contrast to summary(lm(y ~ x))
, the sum of squares
residual and the sample’s standard error (σ̂2) are included.
However, detailed information about the residuals is hidden, as it is
rarely used.
par.t.test()
To test a single linear combination of parameters, a t-test is typically employed. First, we replicate the standard test for the slope parameter using the OLS results above:
par.t.test(my.model.est, nh = c(0,1))
#>
#> t-test on one linear combination of parameters
#> -----------------------------------------------
#>
#> Hypotheses:
#> H0: H1:
#> 1*x = 0 1*x <> 0
#>
#> Test results:
#> t.value crit.value p.value sig.level H0
#> 1.5119 4.3027 0.2697 0.05 not rejected
Furthermore, we save a similar, one-sided test to visualize the results:
The same principle applies to other functions in our package, allowing for various tests to be visualized.
datasets()
The simple command datasets()
(without arguments,
i.e. with empty brackets) shows available datasets in the package
alongside a short description:
datasets()
#> =====================================
#> Available datasets in package desk.
#> =====================================
#> Name
#> 1 data.anscombe
#> 2 data.auto
#> 3 data.ballb
#> 4 data.burglary
#> 5 data.cars
#> 6 data.cobbdoug
#> 7 data.comp
#> 8 data.eu
#> 9 data.fertilizer
#> 10 data.filter
#> 11 data.govexpend
#> 12 data.icecream
#> 13 data.income
#> 14 data.insurance
#> 15 data.iv
#> 16 data.lifesat
#> 17 data.macro
#> 18 data.milk
#> 19 data.pharma
#> 20 data.printer
#> 21 data.regional
#> 22 data.rent
#> 23 data.savings
#> 24 data.sick
#> 25 data.software
#> 26 data.spurious
#> 27 data.tip
#> 28 data.tip.all
#> 29 data.trade
#> 30 data.unempl
#> 31 data.wage
#> 32 data.windscreen
#> Description
#> 1 Anscombe's Quartet
#> 2 Prices and Qualitative Characteristics of US-Cars
#> 3 Defective Ball Bearings
#> 4 Burglaries and Power Blackouts
#> 5 Speed and Stopping Distances of Cars
#> 6 Cobb-Douglas Production Function
#> 7 Monthly Rentals and Qualitative Characteristics of Computers
#> 8 Expenditures of the EU-25
#> 9 Fertilizer in the Cultivation of Barley
#> 10 Water Filter Sales
#> 11 Government Expenditures of US-States
#> 12 Sales of Ice Cream
#> 13 Income Per Capita
#> 14 Sales of Insurance Contracts
#> 15 Instrumental Variables
#> 16 Life Satisfaction
#> 17 Macroeconomic Data from Germany
#> 18 Milk Production
#> 19 Pharmaceutical Advertisements
#> 20 Prices and Qualitative Characteristics of Laser Printers
#> 21 Regional Cost of Living in Germany
#> 22 Average Basic Rent in City Districts
#> 23 International Life-Cycle Savings and Disposable Income
#> 24 Sick Leave and Unemployment
#> 25 Employment Data of a Software Company
#> 26 Non-Stationary Time Series Data
#> 27 Tip Data in a Restaurant
#> 28 Tip Data in a Restaurant with all 20 observations. Only used in textbook.
#> 29 Gravity Model Applied to Germany
#> 30 German Economic Growth and Unemployment Rates
#> 31 Wage Data in a Company
#> 32 Efficiency of a Car Glass Service Company
Typing in a dataset’s name shows the data in the console:
data.anscombe
#> x1 x2 x3 x4 y1 y2 y3 y4
#> 1 10 10 10 8 8.04 9.14 7.46 6.58
#> 2 8 8 8 8 6.95 8.14 6.77 5.76
#> 3 13 13 13 8 7.58 8.74 12.74 7.71
#> 4 9 9 9 8 8.81 8.77 7.11 8.84
#> 5 11 11 11 8 8.33 9.26 7.81 8.47
#> 6 14 14 14 8 9.96 8.10 8.84 7.04
#> 7 6 6 6 8 7.24 6.13 6.08 5.25
#> 8 4 4 4 19 4.26 3.10 5.39 12.50
#> 9 12 12 12 8 10.84 9.13 8.15 5.56
#> 10 7 7 7 8 4.82 7.26 6.42 7.91
#> 11 5 5 5 8 5.68 4.74 5.73 6.89
It can also be saved into the global environment:
As with functions, a question mark as prefix shows the help-file:
repeat.sample()
A fundamental insight in (applied) econometrics involves the restriction of repeated samples, which can be challenging to grasp. As a didactic aid for educators, random samples can be drawn while maintaining the same population slope and intercept. Here, we generate four samples with a slope of 1 and no intercept over x-values ranging from 1 to 30:
Additional graphical representations help to understand the relationship between the true parameters and the estimated ones. To better visualize the distribution of data points around the regression line and the various estimated regression lines, we limit the x-values to a range of 1 to 10 and generate 100 samples, respectively.
x <- 1:10
hundred.samples <- repeat.sample(x, true.par = c(0, 1), sd = 1, rep = 100)
plot(hundred.samples, plot.what = "scatter")
Alongside the 35 functions relating to econometrics, desk also includes some useful tools to make working with R easier.
The function rm.all()
removes all objects from global
environment, while new.session()
accomplishes the same task
and additionally resets most settings. Moreover, it sets the working
directory to the source file location if the function is used from an R
script. Starting a script with this function can speed up the working
flow. Both functions can be used without input.
Furthermore, the arguments()
function reveals a
function’s possible input in a simple way: