Skip to contents

This function is primarily used as an internal function in jab_lmJaB.

Usage

get_infl(mod, func.name, package.name = NULL, args = NULL)

Arguments

mod

An lm object. Output from lmstats.

func.name

A character string of the function name used to calculate the desired centrality statistic.

package.name

A character string of the name of the package that func.name function is in. If left as NULL if the function will be called as loaded in the users environment.

args

A named list of additional arguments the func.name function may need beyond the mod object.

Value

A numeric vector of the influence/outlier statistic as calculated by func.name.

See also

Examples

library(stats)
data("LifeCycleSavings")

mod <- lm(sr ~ ., data = LifeCycleSavings)

# defined functions in stats
get_infl(mod, "dffits")
#>      Australia        Austria        Belgium        Bolivia         Brazil 
#>     0.06271756     0.06324405     0.18780542    -0.05967770     0.26464755 
#>         Canada          Chile          China       Colombia     Costa Rica 
#>    -0.03897262    -0.45535788     0.20077524    -0.09602160     0.40493458 
#>        Denmark        Ecuador        Finland         France        Germany 
#>     0.38451126    -0.16946909    -0.14641688     0.27653834    -0.01521770 
#>         Greece      Guatamala       Honduras        Iceland          India 
#>    -0.28114772    -0.23053977     0.04816829    -0.47676403     0.03808618 
#>        Ireland          Italy          Japan          Korea     Luxembourg 
#>     0.52157524     0.13884474     0.85965081    -0.43025048    -0.14006342 
#>          Malta         Norway    Netherlands    New Zealand      Nicaragua 
#>     0.23855360    -0.05216187     0.03663477     0.14694487     0.03972980 
#>         Panama       Paraguay           Peru    Philippines       Portugal 
#>    -0.17751461    -0.46547654     0.48109398     0.48840149    -0.06901872 
#>   South Africa South Rhodesia          Spain         Sweden    Switzerland 
#>     0.03429664     0.16071740    -0.05261883    -0.45256252     0.19034296 
#>         Turkey        Tunisia United Kingdom  United States      Venezuela 
#>    -0.14453378    -0.21765669    -0.27221843    -0.25095085     0.30708996 
#>         Zambia        Jamaica        Uruguay          Libya       Malaysia 
#>     0.74823509    -0.34555773    -0.20513659    -1.16013341    -0.21262745 
get_infl(mod, "rstudent")
#>      Australia        Austria        Belgium        Bolivia         Brazil 
#>     0.23271611     0.17095506     0.60655220    -0.19037831     0.96790816 
#>         Canada          Chile          China       Colombia     Costa Rica 
#>    -0.08983197    -2.31342946     0.69048169    -0.38946778     1.41731062 
#>        Denmark        Ecuador        Finland         France        Germany 
#>     1.48644473    -0.64957871    -0.45986445     0.69640933    -0.04918692 
#>         Greece      Guatamala       Honduras        Iceland          India 
#>    -0.85967533    -0.90854545     0.19051919    -1.73119989     0.13729730 
#>        Ireland          Italy          Japan          Korea     Luxembourg 
#>     1.00485886     0.52015744     1.60321582    -1.69103214    -0.45560591 
#>          Malta         Norway    Netherlands    New Zealand      Nicaragua 
#>     0.81227407    -0.23247367     0.11605663     0.61373189     0.17254242 
#>         Panama       Paraguay           Peru    Philippines       Portugal 
#>    -0.88147653    -1.70488128     1.82391409     1.86382587    -0.21040432 
#>   South Africa South Rhodesia          Spain         Sweden    Switzerland 
#>     0.12996586     0.36714512    -0.18175853    -1.20293404     0.67532922 
#>         Turkey        Tunisia United Kingdom  United States      Venezuela 
#>    -0.71138840    -0.76677907    -0.74959873    -0.35461507     0.99932569 
#>         Zambia        Jamaica        Uruguay          Libya       Malaysia 
#>     2.85355834    -0.85376418    -0.62253411    -1.08930326    -0.80489153 


# define the likelihood distance as influence statistic (Cook, 1986)
infl_like <- function(mod){

  n <- length(mod$fitted.values)
  p <- length(mod$coefficients)

  ti <- rstudent(mod)
  h <- hatvalues(mod)

  p1 <- log( (n/(n-1)) * ((n-p-1) / (ti^2 +n-p-1)) )
  p2 <- ti^2 * (n-1) / (1-h) / (n-p-1)

  return(n*p1 + p2 - 1)
}

infl_like(mod)
#>      Australia        Austria        Belgium        Bolivia         Brazil 
#>     0.01332285     0.01393650     0.04279099     0.01329473     0.07801597 
#>         Canada          Chile          China       Colombia     Costa Rica 
#>     0.01164427     0.46179324     0.04710546     0.01725230     0.19766003 
#>        Denmark        Ecuador        Finland         France        Germany 
#>     0.18557686     0.03481345     0.02977880     0.08729178     0.01033835 
#>         Greece      Guatamala       Honduras        Iceland          India 
#>     0.08834026     0.05925346     0.01191127     0.30613332     0.01132692 
#>        Ireland          Italy          Japan          Korea     Luxembourg 
#>     0.30310916     0.02639617     0.85682344     0.25252760     0.02781943 
#>          Malta         Norway    Netherlands    New Zealand      Nicaragua 
#>     0.06408061     0.01197483     0.01132621     0.02744299     0.01122802 
#>         Panama       Paraguay           Peru    Philippines       Portugal 
#>     0.03527406     0.28988377     0.32837082     0.34491328     0.01445942 
#>   South Africa South Rhodesia          Spain         Sweden    Switzerland 
#>     0.01106509     0.03607130     0.01248200     0.23179598     0.04278521 
#>         Turkey        Tunisia United Kingdom  United States      Venezuela 
#>     0.02517964     0.05395529     0.08393131     0.07761392     0.10514619 
#>         Zambia        Jamaica        Uruguay          Libya       Malaysia 
#>     1.21190479     0.13333477     0.05011857     1.49988249     0.05112667 
get_infl(mod, "infl_like")
#> Error in infl_like(structure(list(coefficients = c(`(Intercept)` = 28.5660865407468, pop15 = -0.461193147122768, pop75 = -1.69149767674954, dpi = -0.000336901869141349, ddpi = 0.409694927870671), residuals = c(Australia = 0.863579763089957, Austria = 0.616385987736311, Belgium = 2.218957928338, Bolivia = -0.698319121223192, Brazil = 3.55280944158801, Canada = -0.316892362577826, Chile = -8.2422306716793, China = 2.53603608513497, Colombia = -1.45170709733013, `Costa Rica` = 5.1250781784526, Denmark = 5.40023884278033, Ecuador = -2.40563130331345, Finland = -1.68108565185996, France = 2.47547182883964, Germany = -0.180699295374666, Greece = -3.11616846782401, Guatamala = -3.35528378971092, Honduras = 0.710024484173062, Iceland = -6.21058197743013, India = 0.508673999894876, Ireland = 3.39113064057356, Italy = 1.92675489523614, Japan = 5.28148554984659, Korea = -6.10698144474573, Luxembourg = -1.67080656669553, Malta = 2.97490978233697, Norway = -0.871785361021597, Netherlands = 0.425545510217781, `New Zealand` = 2.28555481755543, Nicaragua = 0.646396607890594, Panama = -3.29416560287372, Paraguay = -6.1257588810932, Peru = 6.53944101694304, Philippines = 6.67500844049873, Portugal = -0.768444679621794, `South Africa` = 0.483165565323186, `South Rhodesia` = 1.2914342214096, Spain = -0.671156455550308, Sweden = -4.26028339866931, Switzerland = 2.48682585582808, Turkey = -2.6656824059543, Tunisia = -2.81792000502934, `United Kingdom` = -2.69241276642556, `United States` = -1.11159014595127, Venezuela = 3.63251769439362, Zambia = 9.75091377184124, Jamaica = -3.01853140824666, Uruguay = -2.26382733704987, Libya = -2.82952566381197, Malaysia = -2.97086904885857), effects = c(`(Intercept)` = -68.384296808551, pop15 = -14.2869718756147, pop75 = 7.30360935931436, dpi = -3.52149771993956, ddpi = -7.94065681116866, -0.655206619955559, -7.98426769818929, 2.11835129324918, -1.5354578825814, 4.94070903923897, 4.9811476263448, -2.36103969775486, -1.5661521693604, 1.68196909708745, -0.182551082570306, -3.28374023011935, -3.03783031104655, 0.762019243487725, -6.28806559687962, 1.15942218549724, 2.92804205826621, 2.04415604780183, 5.04587845254195, -6.2647879270342, -1.38102756737135, 2.31670197356863, -1.15880106817969, -0.209548919949984, 2.26101525601646, 0.709220205102216, -3.39023406360215, -5.44378328667935, 6.93989846010402, 6.81988853627435, -1.20929423152311, 0.996491767935397, 2.24569677287488, -0.520632156857349, -4.74503902147376, 2.40967313840561, -2.54148496023116, -2.56770845836587, -2.71221486177228, -1.81298485410907, 3.95072523713182, 9.62759991285484, -4.29977588639926, -1.63553230064561, -5.52474122081385, -3.28514163602414), rank = 5L,     fitted.values = c(Australia = 10.56642023691, Austria = 11.4536140122637,     Belgium = 10.951042071662, Bolivia = 6.44831912122319, Brazil = 9.32719055841199,     Canada = 9.10689236257783, Chile = 8.8422306716793, China = 9.36396391486503,     Colombia = 6.43170709733013, `Costa Rica` = 5.6549218215474,     Denmark = 11.4497611572197, Ecuador = 5.99563130331345, Finland = 12.92108565186,     France = 10.1645281711604, Germany = 12.7306992953747, Greece = 13.786168467824,     Guatamala = 6.36528378971092, Honduras = 6.98997551582694,     Iceland = 7.48058197743013, India = 8.49132600010512, Ireland = 7.94886935942644,     Italy = 12.3532451047639, Japan = 15.8185144501534, Korea = 10.0869814447457,     Luxembourg = 12.0208065666955, Malta = 12.505090217663, Norway = 11.1217853610216,     Netherlands = 14.2244544897822, `New Zealand` = 8.38444518244457,     Nicaragua = 6.65360339210941, Panama = 7.73416560287372,     Paraguay = 8.1457588810932, Peru = 6.16055898305696, Philippines = 6.10499155950126,     Portugal = 13.2584446796218, `South Africa` = 10.6568344346768,     `South Rhodesia` = 12.0085657785904, Spain = 12.4411564555503,     Sweden = 11.1202833986693, Switzerland = 11.6431741441719,     Turkey = 7.7956824059543, Tunisia = 5.62792000502934, `United Kingdom` = 10.5024127664256,     `United States` = 8.67159014595127, Venezuela = 5.58748230560638,     Zambia = 8.80908622815876, Jamaica = 10.7385314082467, Uruguay = 11.5038273370499,     Libya = 11.719525663812, Malaysia = 7.68086904885857), assign = 0:4,     qr = structure(list(qr = structure(c(-7.07106781186548, 0.14142135623731,     0.14142135623731, 0.14142135623731, 0.14142135623731, 0.14142135623731,     0.14142135623731, 0.14142135623731, 0.14142135623731, 0.14142135623731,     0.14142135623731, 0.14142135623731, 0.14142135623731, 0.14142135623731,     0.14142135623731, 0.14142135623731, 0.14142135623731, 0.14142135623731,     0.14142135623731, 0.14142135623731, 0.14142135623731, 0.14142135623731,     0.14142135623731, 0.14142135623731, 0.14142135623731, 0.14142135623731,     0.14142135623731, 0.14142135623731, 0.14142135623731, 0.14142135623731,     0.14142135623731, 0.14142135623731, 0.14142135623731, 0.14142135623731,     0.14142135623731, 0.14142135623731, 0.14142135623731, 0.14142135623731,     0.14142135623731, 0.14142135623731, 0.14142135623731, 0.14142135623731,     0.14142135623731, 0.14142135623731, 0.14142135623731, 0.14142135623731,     0.14142135623731, 0.14142135623731, 0.14142135623731, 0.14142135623731,     -248.120941091235, 64.0620901313718, 0.165128351395561, -0.117253943076925,     -0.121936899867514, 0.041498292124025, -0.0836927527443743,     -0.161898131147202, -0.19140075892791, -0.207010614896538,     0.155450240695012, -0.186249506458262, 0.102064533282303,     0.14545993287509, 0.172777180820189, 0.136718413532658, -0.182190943906419,     -0.202015460986577, 0.00543952483649349, -0.108200226615121,     0.0502398114664568, 0.153889255098149, 0.115020713736264,     -0.114912464681631, 0.196348063332818, 0.0286982102297497,     0.13156716106301, 0.15092338246411, 0.0276055203119457, -0.166424989378104,     -0.143322402544535, -0.106170945339199, -0.15315661180477,     -0.185469013659831, 0.0845814945974391, 0.0380641238109267,     0.0383763209302993, 0.103625518879166, 0.201967611481524,     0.169967406745836, -0.141137022708927, -0.183283633824223,     0.173401575058934, 0.0713131170241051, -0.187654393495439,     -0.169703059131516, -0.105234353981081, 0.0975376750514007,     -0.145351683820456, -0.200142278270342, -16.2139584926075,     -8.208468361267, -3.77617493796019, 0.0876115456504285, -0.123991445176047,     0.0324742628761381, -0.0774961757403155, -0.0738240761695448,     0.0977743197948592, 0.155107547475184, 0.0545992517279037,     0.120271927354821, -0.234891833982489, 0.281643868164441,     -0.139119350354824, -0.121822565049815, 0.0261316708293862,     -0.00475795269661488, 0.176883803253687, -0.121375110291947,     0.367087953759436, -0.0609541793024463, -0.386710872116642,     -0.119072481822996, -0.093071549693098, -0.0385154980516702,     0.041052595204344, -0.114994298426074, 0.149387613557561,     0.0796606261525182, 0.0235137463728522, -0.10224067862105,     0.067472299707597, 0.0999272621483305, -0.0672935781881911,     -0.110519624702159, -0.312504442270379, -0.106097490965416,     0.108418027831249, -0.0319818209254472, -0.0133251299855025,     0.118700216134212, 0.153382985010363, 0.117026604084129,     0.046727936996969, -0.084880198289551, 0.0756668582882882,     -0.131722597209973, 0.258604824847036, 0.0120897742619538,     -7825.96369775173, -5244.98283997536, -1659.93396642261,     4224.21718621954, -0.0536035761934073, -0.35077055562151,     0.0207623401341921, 0.0236879366399189, 0.0545745559651996,     0.0114296081119295, -0.101423500131805, 0.0655969136116444,     -0.0698187942331708, 0.0345569662376129, -0.141247492691575,     0.200376455993068, 0.0364124765390022, 0.0170765160579042,     -0.0834728759435578, 0.113953733698577, 0.213306965476638,     0.118008933971425, -0.00866553196137767, 0.0792113815433863,     -0.0970181619831277, 0.173825665030011, -0.0698459049119983,     0.0126239481371422, 0.0290805918657238, 0.0643125258094002,     0.0125921826736313, 0.0917999190055434, 0.0570877549090301,     0.0914204492762292, 0.230757469991387, 0.146950137427881,     0.170732567828158, 0.193378225888342, -0.220912223157481,     -0.147702799390841, 0.0443649595718382, 0.077304219055593,     0.114947741036207, -0.529085028782653, -0.0863493470870069,     0.0469190526616599, 0.11777662604228, 0.178113267059554,     0.198657880592627, 0.0226743924701606, -26.5702444098657,     -0.960774896257385, 0.871339488314517, -5.12174037679466,     -19.3818772725331, -0.0342852848366908, -0.050612321042065,     0.151684286261799, -0.0196288590772824, -0.0273668123524811,     0.0198202468033202, -0.0658872227213478, 0.0258944985383431,     0.0450479043578137, -0.0136507065100683, 0.106740475035809,     -0.103928040664259, -0.0141841059200206, -0.116828148616797,     -0.117123520487969, -0.0404334605775779, -0.0262720701160171,     0.214858348707238, 0.106568493847888, -0.113364845360484,     0.213045488244538, -0.00114815133568938, 0.193245329389977,     -0.0955666175455098, -0.0534734806249023, 0.00574774495172758,     -0.140940531212752, -0.147448750016385, -0.0786961245719627,     0.171057803856445, -0.0939467507263722, -0.11359148283, 0.010171477682808,     -0.0211367673646394, -0.0469846629052428, -0.0320113781263437,     -0.121786835708436, -0.0977217117448339, -0.016588388025142,     -0.141504675692516, 0.0790414331106965, 0.338378959036943,     -0.116640440486279, 0.675176165764421, 0.0834079960915886    ), dim = c(50L, 5L), dimnames = list(c("Australia", "Austria",     "Belgium", "Bolivia", "Brazil", "Canada", "Chile", "China",     "Colombia", "Costa Rica", "Denmark", "Ecuador", "Finland",     "France", "Germany", "Greece", "Guatamala", "Honduras", "Iceland",     "India", "Ireland", "Italy", "Japan", "Korea", "Luxembourg",     "Malta", "Norway", "Netherlands", "New Zealand", "Nicaragua",     "Panama", "Paraguay", "Peru", "Philippines", "Portugal",     "South Africa", "South Rhodesia", "Spain", "Sweden", "Switzerland",     "Turkey", "Tunisia", "United Kingdom", "United States", "Venezuela",     "Zambia", "Jamaica", "Uruguay", "Libya", "Malaysia"), c("(Intercept)",     "pop15", "pop75", "dpi", "ddpi")), assign = 0:4), qraux = c(1.14142135623731,     1.1726210822605, 1.16459675512416, 1.15395548271583, 1.0534577838838    ), pivot = 1:5, tol = 1e-07, rank = 5L), class = "qr"), df.residual = 45L,     xlevels = structure(list(), names = character(0)), call = lm(formula = sr ~         ., data = LifeCycleSavings), terms = sr ~ pop15 + pop75 +         dpi + ddpi, model = structure(list(sr = c(11.43, 12.07,     13.17, 5.75, 12.88, 8.79, 0.6, 11.9, 4.98, 10.78, 16.85,     3.59, 11.24, 12.64, 12.55, 10.67, 3.01, 7.7, 1.27, 9, 11.34,     14.28, 21.1, 3.98, 10.35, 15.48, 10.25, 14.65, 10.67, 7.3,     4.44, 2.02, 12.7, 12.78, 12.49, 11.14, 13.3, 11.77, 6.86,     14.13, 5.13, 2.81, 7.81, 7.56, 9.22, 18.56, 7.72, 9.24, 8.89,     4.71), pop15 = c(29.35, 23.32, 23.8, 41.89, 42.19, 31.72,     39.74, 44.75, 46.64, 47.64, 24.42, 46.31, 27.84, 25.06, 23.31,     25.62, 46.05, 47.32, 34.03, 41.31, 31.16, 24.52, 27.01, 41.74,     21.8, 32.54, 25.95, 24.71, 32.61, 45.04, 43.56, 41.18, 44.19,     46.26, 28.96, 31.94, 31.92, 27.74, 21.44, 23.49, 43.42, 46.12,     23.27, 29.81, 46.4, 45.25, 41.12, 28.13, 43.69, 47.2), pop75 = c(2.87,     4.41, 4.43, 1.67, 0.83, 2.85, 1.34, 0.67, 1.06, 1.14, 3.93,     1.19, 2.37, 4.7, 3.35, 3.1, 0.87, 0.58, 3.08, 0.96, 4.19,     3.48, 1.91, 0.91, 3.73, 2.47, 3.67, 3.25, 3.17, 1.21, 1.2,     1.05, 1.28, 1.12, 2.85, 2.28, 1.52, 2.87, 4.54, 3.73, 1.08,     1.21, 4.46, 3.43, 0.9, 0.56, 1.73, 2.72, 2.07, 0.66), dpi = c(2329.68,     1507.99, 2108.47, 189.13, 728.47, 2982.88, 662.86, 289.52,     276.65, 471.24, 2496.53, 287.77, 1681.25, 2213.82, 2457.12,     870.85, 289.71, 232.44, 1900.1, 88.94, 1139.95, 1390, 1257.28,     207.68, 2449.39, 601.05, 2231.03, 1740.7, 1487.52, 325.54,     568.56, 220.56, 400.06, 152.01, 579.51, 651.11, 250.96, 768.79,     3299.49, 2630.96, 389.66, 249.87, 1813.93, 4001.89, 813.39,     138.33, 380.47, 766.54, 123.58, 242.69), ddpi = c(2.87, 3.93,     3.82, 0.22, 4.56, 2.43, 2.67, 6.51, 3.08, 2.8, 3.99, 2.19,     4.32, 4.52, 3.44, 6.28, 1.48, 3.19, 1.12, 1.54, 2.99, 3.54,     8.21, 5.81, 1.57, 8.12, 3.62, 7.66, 1.76, 2.48, 3.61, 1.03,     0.67, 2, 7.48, 2.19, 2, 4.35, 3.01, 2.7, 2.96, 1.13, 2.01,     2.45, 0.53, 5.14, 10.23, 1.88, 16.71, 5.08)), terms = sr ~         pop15 + pop75 + dpi + ddpi, row.names = c("Australia",     "Austria", "Belgium", "Bolivia", "Brazil", "Canada", "Chile",     "China", "Colombia", "Costa Rica", "Denmark", "Ecuador",     "Finland", "France", "Germany", "Greece", "Guatamala", "Honduras",     "Iceland", "India", "Ireland", "Italy", "Japan", "Korea",     "Luxembourg", "Malta", "Norway", "Netherlands", "New Zealand",     "Nicaragua", "Panama", "Paraguay", "Peru", "Philippines",     "Portugal", "South Africa", "South Rhodesia", "Spain", "Sweden",     "Switzerland", "Turkey", "Tunisia", "United Kingdom", "United States",     "Venezuela", "Zambia", "Jamaica", "Uruguay", "Libya", "Malaysia"    ), class = "data.frame")), class = "lm")): could not find function "infl_like"