| Title: | Tools for Teaching Econometrics |
|---|---|
| Description: | Functions used in my econometrics courses to generate solutions, print results and generate data. |
| Authors: | Pierre Chausse [aut, cre] |
| Maintainer: | Pierre Chausse <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.2-0 |
| Built: | 2026-10-22 11:20:40 UTC |
| Source: | https://codeberg.org/pchausse/metricsUW |
The function create a distribution table to be printed in Latex format.q
distTable(df=NULL, df2=NULL, digits=4, dist=c("t", "chisq", "f", "normal"), size=0.05, CDF=FALSE, float=TRUE, label=NULL)distTable(df=NULL, df2=NULL, digits=4, dist=c("t", "chisq", "f", "normal"), size=0.05, CDF=FALSE, float=TRUE, label=NULL)
df |
A vector of degrees of freedom. |
df2 |
A second vector of degrees of freedom for the f-distribution. |
digits |
How many digits to print? |
dist |
The distribution table to be printed. |
size |
The size for F-tests. |
CDF |
Should the normal table show CDF values? By default, it shows the probability of being between 0 and z. |
float |
Should the Latex table be a floating table? |
label |
The label of referencing the table in Latex. By default,
it is |
It prints a latex table.
## Not run: distTable()## Not run: distTable()
Functions to simulate data from a supply and demand system with one exogenous variable in each function, plot the system and print the equations.
genDemSup(n, a=c(20, 1, -2), d=c(100,-1,2,0), sige=16, sigeta=16, sigX=c(5,5), sigZ=5) ## S3 method for class 'DemSup' print(x, ...) ## S3 method for class 'DemSup' plot(x, y=NULL, nCurves=NULL, nPoints=NULL, fac=c(0.9,1.1), ...)genDemSup(n, a=c(20, 1, -2), d=c(100,-1,2,0), sige=16, sigeta=16, sigX=c(5,5), sigZ=5) ## S3 method for class 'DemSup' print(x, ...) ## S3 method for class 'DemSup' plot(x, y=NULL, nCurves=NULL, nPoints=NULL, fac=c(0.9,1.1), ...)
x |
An object of class |
n |
The sample size. |
a |
The coefficient of the supply function. The first is the intercept, the second is the slope of the supply and the third is the coefficient of the exogenous variable Z. |
d |
The coefficient of the demand function. The first is the intercept, the second is the slope of the demand and the third is the coefficient of the exogenous variable X. |
sige, sigeta, sigX, sigZ
|
The variance of the error in the supply, the error in the demand, the exogenous variable X and the exogenous variable Z. |
nCurves |
How many supply and demand curves to plot. By default, all curves are plotted. |
nPoints |
How many data points to plot. By default, they are all plotted. |
fac |
It determine the range for each demand and supply
function. The function goes from |
y |
Not used at the moment. |
... |
Arguments to pass to other methods. Currently not used. |
genDemSup returns an object of class DemSup. The object is
a list that contains the following:
dat |
A |
a |
The parameters of the supply. |
d |
The parameters of the demand. |
sig |
The variance of the error terms. |
sigExo |
The variance of the exogenous variables. |
set.seed(112233) sys <- genDemSup(200) print(sys) plot(sys, nCurves=10)set.seed(112233) sys <- genDemSup(200) print(sys) plot(sys, nCurves=10)
The function generate datasets with known properties. Students can try different techniques to identify the processes.
genTS(n=200, frequency=12, start=c(1960,1), seed)genTS(n=200, frequency=12, start=c(1960,1), seed)
n |
The sample size |
frequency, start
|
The frequency and starting data. See |
seed |
An optional seed for the random generators |
It returns an mts object with two time series, X and
Y. One of them is a unit root process and the other is a trend
stationary series. The true processes are saved in the attribute "which".
dat <- genTS()dat <- genTS()
The following are all solution generators for different types of inference questions. They return an object that can be converted into Latex though its print method.
testMean(x, h0, size=.05, alter=c("diff","greater","less"), assume=c("Normal","nonNormal"), digits=4, dround=NULL, xbar=NULL, se=NULL, n=NULL) ciMean(x, size=0.05, assume=c("Normal","nonNormal"), digits=4, dround=NULL, xbar=NULL, se=NULL, n=NULL) testDiffMeans(x1, x2, h0, size=.05, alter=c("diff","greater","less"), assume=c("Normal","nonNormal"), assumev=c("same", "diff"), digits=4, dround=NULL, xbar=NULL, se=NULL, n=NULL) ciDiffMeans(x1, x2, size=.05, assume=c("Normal","nonNormal"), assumev=c("same", "diff"), digits=4, dround=NULL, xbar=NULL, se=NULL, n=NULL) testVar(x, h0, size=.05, alter=c("diff","greater","less"), assume=c("Normal","nonNormal"), digits=4, dround=NULL, se=NULL, n=NULL) ciVar(x, size=0.05, assume=c("Normal","nonNormal"), digits=4, dround=NULL, se=NULL, n=NULL) testDiffVar(x1, x2, size=.05, assume=c("Normal","nonNormal"), digits=4, dround=NULL, se=NULL, n=NULL)testMean(x, h0, size=.05, alter=c("diff","greater","less"), assume=c("Normal","nonNormal"), digits=4, dround=NULL, xbar=NULL, se=NULL, n=NULL) ciMean(x, size=0.05, assume=c("Normal","nonNormal"), digits=4, dround=NULL, xbar=NULL, se=NULL, n=NULL) testDiffMeans(x1, x2, h0, size=.05, alter=c("diff","greater","less"), assume=c("Normal","nonNormal"), assumev=c("same", "diff"), digits=4, dround=NULL, xbar=NULL, se=NULL, n=NULL) ciDiffMeans(x1, x2, size=.05, assume=c("Normal","nonNormal"), assumev=c("same", "diff"), digits=4, dround=NULL, xbar=NULL, se=NULL, n=NULL) testVar(x, h0, size=.05, alter=c("diff","greater","less"), assume=c("Normal","nonNormal"), digits=4, dround=NULL, se=NULL, n=NULL) ciVar(x, size=0.05, assume=c("Normal","nonNormal"), digits=4, dround=NULL, se=NULL, n=NULL) testDiffVar(x1, x2, size=.05, assume=c("Normal","nonNormal"), digits=4, dround=NULL, se=NULL, n=NULL)
x, x1, x2
|
Numeric vectors |
h0 |
The null hypothesis. |
size |
The size of the test or one minus the confidence level when confidence intervals are computed. |
alter |
The alternative hypothesis. |
assume |
What is assumed about the distribution of the data. It affects how the critical values are obtained. The t or F distribution is used under normality, and the asymptotic N(0,1) or chi-square is used otherwise. |
assumev |
Do we assume that the variance of the two samples are different or that they are same? |
digits |
How many digits to print? |
dround |
If we want to round the numbers before doing inference,
|
xbar, se, n
|
Alternatively, the sample mean(s), standard deviation(s) and sample size(s) can be provided, instead of numeric vector(s). |
It returns an object of class metricsSol.
## Test on the mean from the data set.seed(112233) x1 <- rnorm(30) obj <- testMean(x1, 0) ## Test on the mean without data obj <- testMean(h0=0, xbar=0.1, se=0.6, n=35) ## See vignette for more examples## Test on the mean from the data set.seed(112233) x1 <- rnorm(30) obj <- testMean(x1, 0) ## Test on the mean without data obj <- testMean(h0=0, xbar=0.1, se=0.6, n=35) ## See vignette for more examples
The following are all solution generators for different types of inference questions based on linear regression. They return an object that can be converted into Latex though its print method.
testRegCoef(object, h0, which, size=.05, alter=c("diff","greater","less"), digits=4, assume=c("Normal","nonNormal"), beta=NULL, se = NULL, n=NULL, ncoef=NULL, dround=NULL) ciRegCoef(object, size=0.05, which, digits=4, assume=c("Normal", "nonNormal"), beta=NULL, se=NULL, n=NULL, ncoef=NULL, dround=NULL) testLinRegCoefs(object, R, q, size=.05, alter=c("diff","greater","less"), digits=4, assume=c("Normal","nonNormal"), beta=NULL, vcoef=NULL, n=NULL, dround=NULL) testRegF(object, objectr=NULL, size=.05, digits=4, assume = c("Normal", "nonNormal"), dround=NULL, Rsq=NULL, SSRu=NULL, SSRr=NULL, nrest=NULL, n=NULL, ncoef=NULL)testRegCoef(object, h0, which, size=.05, alter=c("diff","greater","less"), digits=4, assume=c("Normal","nonNormal"), beta=NULL, se = NULL, n=NULL, ncoef=NULL, dround=NULL) ciRegCoef(object, size=0.05, which, digits=4, assume=c("Normal", "nonNormal"), beta=NULL, se=NULL, n=NULL, ncoef=NULL, dround=NULL) testLinRegCoefs(object, R, q, size=.05, alter=c("diff","greater","less"), digits=4, assume=c("Normal","nonNormal"), beta=NULL, vcoef=NULL, n=NULL, dround=NULL) testRegF(object, objectr=NULL, size=.05, digits=4, assume = c("Normal", "nonNormal"), dround=NULL, Rsq=NULL, SSRu=NULL, SSRr=NULL, nrest=NULL, n=NULL, ncoef=NULL)
object, objectr
|
Object of class |
h0 |
The null hypothesis. |
which |
An integer specifying which coefficient is being tested. |
size |
The size of the test or one minus the confidence level when confidence intervals are computed. |
alter |
The alternative hypothesis. |
assume |
What is assumed about the distribution of the data. It affects how the critical values are obtained. The t or F distribution is used under normality, and the asymptotic N(0,1) or chi-square is used otherwise. |
digits |
How many digits to print? |
dround |
If we want to round the numbers before doing inference,
|
beta, se, n, ncoef
|
Alternatively, the coefficient estimate(s),
the standard error(s), the sample size(s) and the number of coefficients
in the regression model can be provided, instead of the |
R, q
|
For test of linear combinations of coefficients, |
vcoef |
The alternative estimated covariance matrix. It is needed for robust testings |
Rsq |
The R-squared of the unrestricted model. If provided, an F-test for the significance of all coefficients but the intercept is performed. |
SSRu, SSRr, nrest
|
The unrestricted SSR, the restricted SSR and
the number of restrictions being tested. These values are needed if
not |
It returns an object of class metricsSol.
## Test on one coefficient data(wage1, package="wooldridge") fit <- lm(wage~educ+exper, wage1) testRegCoef(fit, h0=0.5, which=2, size=0.10, alter="greater") ## See vignette for more examples## Test on one coefficient data(wage1, package="wooldridge") fit <- lm(wage~educ+exper, wage1) testRegCoef(fit, h0=0.5, which=2, size=0.10, alter="greater") ## See vignette for more examples
metricsSol
It prints the solution from the object using Latex format. It is mainly used inside markdown documents to generate nicely formatted solution.
## S3 method for class 'metricsSol' print(x, addMess=NULL, ...)## S3 method for class 'metricsSol' print(x, addMess=NULL, ...)
x |
An object of class |
addMess |
Message to print at the end of the solution. I use it to add the mark distribution when I generate solutions for exams. |
... |
Arguments to pass to other methods. Currently not used. |
It print the type of inference and the detailed solution in Latex format.
set.seed(112233) x1 <- rnorm(30) obj <- testMean(x1, 0) print(obj, addMess="Not point if no justification")set.seed(112233) x1 <- rnorm(30) obj <- testMean(x1, 0) print(obj, addMess="Not point if no justification")
The function generates a Latex equation from a model estimated by
lm or glm.
## S3 method for class 'lm' printReg(obj, digits=4, format="f", maxpl=5, adjrsq=FALSE, se=NULL, stars=FALSE, dist=c("t","n"), label=NULL, omit=NULL, ...) ## S3 method for class 'tsls' printReg(obj,digits=4, format='f', maxpl=5, se=NULL, stars=FALSE, label=NULL, omit=NULL, strength=FALSE, Jtest=FALSE, Exo=FALSE, ...) ## S3 method for class 'formula' printReg(obj, maxpl=5, label=NULL, coef="\\beta", error="\\epsilon", ...)## S3 method for class 'lm' printReg(obj, digits=4, format="f", maxpl=5, adjrsq=FALSE, se=NULL, stars=FALSE, dist=c("t","n"), label=NULL, omit=NULL, ...) ## S3 method for class 'tsls' printReg(obj,digits=4, format='f', maxpl=5, se=NULL, stars=FALSE, label=NULL, omit=NULL, strength=FALSE, Jtest=FALSE, Exo=FALSE, ...) ## S3 method for class 'formula' printReg(obj, maxpl=5, label=NULL, coef="\\beta", error="\\epsilon", ...)
obj |
An object used to print the regression equation. |
digits |
The number of digits to be printed (See
|
format |
Printing format for coefficient estimates and their
standard errors.(See |
maxpl |
The maximum number of variables to be printed per line. |
adjrsq |
Should we print the adjusted R-square? |
se |
Alternative vector of standard errors. By default, the one
from |
stars |
Should we add stars next to significant coefficients? |
dist |
Distribution used for p-values. By default, the t-distribution is used. Alternatively, we can replace it by the asymptotic N(0,1). |
label |
Label for latex equations in case a reference is needed. By default, it is null and the equation is not numbered. |
omit |
This argument is to specify variables to omit from the
printed equation. It is a character vector, and the function omits
any variables that contain the characters detected by
|
strength, Jtest, Exo
|
Should the first stage F-test, J-test and the list of exogenous variables be printed? |
coef, error
|
What Greek letters to use for coefficients and error term? Note that two backslashes is needed for Greek letter. It is also possible to use normal letter and omit the backslashes. |
... |
Other argument to pass to |
It returns an equation in Latex format.
## Estimated linear model set.seed(112233) x1 <- rnorm(30) x2 <- rnorm(30) y <- x1+x2+rnorm(30) fit <- lm(y~x1+x2) printReg(fit) ## formula to equation printReg(y~x1*x2+z+I(z^2))## Estimated linear model set.seed(112233) x1 <- rnorm(30) x2 <- rnorm(30) y <- x1+x2+rnorm(30) fit <- lm(y~x1+x2) printReg(fit) ## formula to equation printReg(y~x1*x2+z+I(z^2))
The function generates a Latex equation with the detailed steps to calculate probability of areas using a printed normal table.
probFromTable(a, b=NULL, type=c("less","greater"), digits=3, mu=0, sig2=1, varName="X", approx=FALSE, print=TRUE, CDF=FALSE)probFromTable(a, b=NULL, type=c("less","greater"), digits=3, mu=0, sig2=1, varName="X", approx=FALSE, print=TRUE, CDF=FALSE)
a |
One of the boundary of the interval. See details. |
b |
One of the boundary of the interval. See details |
digits |
The number of digits shown in the normal table |
type |
When |
mu |
The expected value of the normal distribution for the unscaled variable. |
sig2 |
The variance of the normal distribution for the unscaled variable. |
varName |
The name of the variable to be printed in the solution. |
approx |
Is the normal distribution an approximation? |
print |
Should the table be printed? If FALSE, the probabilities are returned. |
CDF |
Is the normal table showing the CDF? The alternative is a table that shows the probability of being between 0 and z. |
When b is NULL, it returns the probability that X is less than
a when type="less" and the probability of being greater
than a when type="greater". When b is not NULL, it
returns the probability of being between a and b.
It returns an equation in Latex format or a numeric probability.
## Not run: probFromTable(-10, 8, mu=6, sig2=25, digits=3)## Not run: probFromTable(-10, 8, mu=6, sig2=25, digits=3)