pmodel.response has several methods to conveniently extract the response of several objects.
pmodel.response(object, ...)
# S3 method for class 'plm'
pmodel.response(object, ...)
# S3 method for class 'data.frame'
pmodel.response(object, ...)
# S3 method for class 'formula'
pmodel.response(object, data, ...)A pseries except if model responses' of a "between"
or "fd" model as these models "compress" the data (the number
of observations used in estimation is smaller than the original
data due to the specific transformation). A numeric is returned
for the "between" and "fd" model.
The model response is extracted from a pdata.frame (where the
response must reside in the first column; this is the case for a
model frame), a Formula + data (being a model frame) or a plm
object, and the
transformation specified by effect and model is applied to
it.
Constructing the model frame first ensures proper NA
handling and the response being placed in the first column, see
also Examples for usage.
plm's model.matrix() for (transformed)
model matrix and the corresponding model.frame()
method to construct a model frame.
# First, make a pdata.frame
data("Grunfeld", package = "plm")
pGrunfeld <- pdata.frame(Grunfeld)
# then make a model frame from a Formula and a pdata.frame
form <- inv ~ value + capital
mf <- model.frame(pGrunfeld, form)
# retrieve (transformed) response directly from model frame
resp_mf <- pmodel.response(mf, model = "within", effect = "individual")
# retrieve (transformed) response from a plm object, i.e., an estimated model
fe_model <- plm(form, data = pGrunfeld, model = "within")
pmodel.response(fe_model)
#> 1-1935 1-1936 1-1937 1-1938 1-1939 1-1940 1-1941 1-1942
#> -290.4200 -216.2200 -197.4200 -350.3200 -277.2200 -146.8200 -96.0200 -160.0200
#> 1-1943 1-1944 1-1945 1-1946 1-1947 1-1948 1-1949 1-1950
#> -108.4200 -60.5200 -46.8200 80.0800 -39.1200 -78.8200 -52.9200 34.8800
#> 1-1951 1-1952 1-1953 1-1954 2-1935 2-1936 2-1937 2-1938
#> 147.8800 283.1800 696.3800 878.6800 -200.5750 -55.1750 59.4250 -148.1750
#> 2-1939 2-1940 2-1941 2-1942 2-1943 2-1944 2-1945 2-1946
#> -180.0750 -48.8750 62.3250 35.1250 -48.8750 -122.2750 -151.7750 9.8250
#> 2-1947 2-1948 2-1949 2-1950 2-1951 2-1952 2-1953 2-1954
#> 10.0250 84.0250 -5.3750 8.3250 177.7250 235.0250 230.5250 48.8250
#> 3-1935 3-1936 3-1937 3-1938 3-1939 3-1940 3-1941 3-1942
#> -69.1900 -57.2900 -25.0900 -57.6900 -54.1900 -27.8900 10.7100 -10.3900
#> 3-1943 3-1944 3-1945 3-1946 3-1947 3-1948 3-1949 3-1950
#> -40.9900 -45.4900 -8.6900 57.6100 44.9100 44.0100 -3.9900 -8.7900
#> 3-1951 3-1952 3-1953 3-1954 4-1935 4-1936 4-1937 4-1938
#> 32.9100 55.0100 77.2100 87.3100 -45.8335 -13.3635 -19.8635 -34.5235
#> 4-1939 4-1940 4-1941 4-1942 4-1943 4-1944 4-1945 4-1946
#> -33.7135 -16.7135 -17.7735 -39.3235 -38.7235 -26.5535 2.6565 -12.0035
#> 4-1947 4-1948 4-1949 4-1950 4-1951 4-1952 4-1953 4-1954
#> -23.4435 3.2365 -7.1435 14.5365 74.4965 58.8765 88.8065 86.3665
#> 5-1935 5-1936 5-1937 5-1938 5-1939 5-1940 5-1941 5-1942
#> -22.1225 -11.0725 12.4375 -8.2925 -19.1525 -15.3225 -0.4025 -22.1325
#> 5-1943 5-1944 5-1945 5-1946 5-1947 5-1948 5-1949 5-1950
#> 0.4375 -9.4825 1.4075 -2.4325 -3.7825 8.5375 5.6175 -6.0625
#> 5-1951 5-1952 5-1953 5-1954 6-1935 6-1936 6-1937 6-1938
#> 18.4975 23.5975 30.0975 19.6275 -35.0510 -29.4310 -29.4710 -27.8810
#> 6-1939 6-1940 6-1941 6-1942 6-1943 6-1944 6-1945 6-1946
#> -30.8110 -26.8710 -12.0010 -12.6010 -27.5710 -22.8110 -16.3810 -5.2410
#> 6-1947 6-1948 6-1949 6-1950 6-1951 6-1952 6-1953 6-1954
#> -3.5610 8.6190 12.7490 21.9290 39.8890 44.0790 72.1090 80.3090
#> 7-1935 7-1936 7-1937 7-1938 7-1939 7-1940 7-1941 7-1942
#> -23.1655 -24.3855 -14.8155 -15.0555 -20.9455 -13.8855 -4.0955 -13.1355
#> 7-1943 7-1944 7-1945 7-1946 7-1947 7-1948 7-1949 7-1950
#> -3.3155 23.2045 -3.4755 1.3845 0.9145 2.4045 2.9945 -5.0655
#> 7-1951 7-1952 7-1953 7-1954 8-1935 8-1936 8-1937 8-1938
#> 17.1745 25.0845 26.2645 41.9145 -29.9615 -16.9915 -7.8415 -20.0015
#> 8-1939 8-1940 8-1941 8-1942 8-1943 8-1944 8-1945 8-1946
#> -24.0515 -14.3215 5.6185 0.4485 -5.8715 -5.0815 -3.6215 10.5685
#> 8-1947 8-1948 8-1949 8-1950 8-1951 8-1952 8-1953 8-1954
#> 12.6685 6.6685 -10.8515 -10.6515 11.4885 28.8885 47.1885 25.7085
#> 9-1935 9-1936 9-1937 9-1938 9-1939 9-1940 9-1941 9-1942
#> -15.2590 -18.4990 -11.2390 -20.9990 -13.1090 -14.9590 -9.8090 -9.6790
#> 9-1943 9-1944 9-1945 9-1946 9-1947 9-1948 9-1949 9-1950
#> -6.1990 20.5810 10.4310 15.0610 12.4310 -1.3590 -9.3490 1.5910
#> 9-1951 9-1952 9-1953 9-1954 10-1935 10-1936 10-1937 10-1938
#> 14.6010 24.0910 24.2210 7.4510 -0.5445 -1.0845 -0.8945 -1.0945
#> 10-1939 10-1940 10-1941 10-1942 10-1943 10-1944 10-1945 10-1946
#> -1.0545 -1.2745 -0.9445 -1.2245 -2.1545 -1.9045 -1.7245 -0.8445
#> 10-1947 10-1948 10-1949 10-1950 10-1951 10-1952 10-1953 10-1954
#> 0.7255 2.5755 1.1255 0.3355 1.5855 2.9155 3.4455 2.0355
# same as constructed before
all.equal(resp_mf, pmodel.response(fe_model), check.attributes = FALSE) # TRUE
#> [1] TRUE