Lineárna regresia a diagnostika modelu

V práci analyzujem databázu AI Layoffs Register, ktorá obsahuje údaje o prepúšťaní zamestnancov v súvislosti s využívaním umelej inteligencie. Cieľom je zostaviť lineárny regresný model, vyhodnotiť jeho kvalitu a otestovať základné predpoklady regresnej analýzy.

udaje <- read.csv("ai-layoffs-register.csv")
head(udaje)
##           Company       Date                             Sector
## 1 Bank of America 2026-10-14                            Banking
## 2             KLM 2026-10-12                            Airline
## 3          Kroger 2026-10-12                     Grocery retail
## 4        One Zero 2026-10-11                    Digital banking
## 5       HoneyBook 2026-10-08 Small-business management software
## 6            HSBC 2026-10-07        Banking (wealth management)
##                                    Country
## 1                            United States
## 2                              Netherlands
## 3                            United States
## 4                                   Israel
## 5 Israel (company headquartered in the US)
## 6                           United Kingdom
##                                                                                                                                                                                                                                                                                   Functions
## 1                                                                                                                                                                                           Managers (down about 5% year over year, per CEO Brian Moynihan, while client-facing staff rose)
## 2                                                                                                                                                                                     Written customer service (handling Dutch-language questions and complaints), per ANP and De Telegraaf
## 3                                                                                                                                                                                                                       Corporate roles across many functions (the memo does not name them)
## 4                                                                                                                                                                                                                                                                             Not specified
## 5                                                                                                                                                                                                                                                                             Not specified
## 6 Financial advisers in HSBC UK's wealth business, a reduction of close to 70% (per the Financial Times, as relayed by AFP, PA and Sharecast); Management and specialist roles in the UK wealth business, about half of them (per the Financial Times, as relayed by AFP, PA and Sharecast)
##   Roles.counted Roles.reported..not.counted.
## 1            NA                           NA
## 2            NA                          126
## 3            NA                         3000
## 4            NA                           25
## 5            NA                           30
## 6            NA                           NA
##                                                                                                                                                                                                                                             Why.not.counted
## 1                                                                                                                                                                                                                                                          
## 2 The company has not named AI as the cause; the number was reported by the press, not stated publicly by the company; the reduction comes through attrition, not layoffs; the number includes roles moved to other teams or locations, not only roles cut.
## 3                                                                                                                                                                                                                The company has not named AI as the cause.
## 4                                                                                                                                                                                 The number was reported by the press, not stated publicly by the company.
## 5                                                                                                                                                                                 The number was reported by the press, not stated publicly by the company.
## 6                                                                                                                                                                                                                                                          
##                                                                                                                                                                                                                            X..of.workforce
## 1                                                                                                                                                                     about 1.5% of headcount year over year (CEO Brian Moynihan's figure)
## 2                                                                                                                                                                                                                                         
## 3                                                                                                                                                                      about 37% of roughly 8,200 corporate employees (Reuters, Bloomberg)
## 4                                                                                                                                                                                          about 7% (about 25 of about 350, per Calcalist)
## 5                                                                                                                                                                                                        about 14% (of 255, per Calcalist)
## 6 No absolute figure and no base on record: about half of management and specialist roles and close to 70% of financial advisers in the UK wealth business, per the FT's anonymous sources; HSBC does not disclose its UK wealth headcount
##   Evidence.tier Attribution Execution Counts.in.US.index
## 1        Tier 1       mixed  executed                 no
## 2        Tier 2      blamed announced                 no
## 3        Tier 2      blamed announced                 no
## 4        Tier 2       mixed announced                 no
## 5        Tier 2       mixed announced                 no
## 6        Tier 2      blamed announced                 no
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               Claim
## 1                                                                                                                                                                                                               CFO Alastair Borthwick, prepared remarks, Q3 2026 earnings call (October 14, 2026): "We also invested in technology modernization, AI, client acquisition, marketing, and franchise growth. At the same time, productivity continues to improve, as evidenced by our headcount. Even as we add headcount in our sales forces, our headcount was down nearly 3,500 from a year ago as we automate processes and simplify work across the company. This means we don't need to hire quite as many people to refill roles." CEO Brian Moynihan, same call, answering a question on AI deployment: "If you look year-over-year, the total expense base was up $1.2 billion and the headcount was down 3,000 round numbers." "How do we maintain that kind of 1%-2% expense growth with all the investments we are making. We are open five branches in Milwaukee this month and things like that, more headcount front client facing. That is by engineering both through engineering process, through AI application, et cetera. You see it already in the numbers, and we expect to continue going forward" "AI has helped us." "We are going to continue to invest in driving the growth in the franchise, and AI is a major part of that. Say, $300 million going to $700 million, headcount down by 3,000, 1.5% year-over-year. Managers down by about 5% in that, and production teammates that are doing the client-facing work are actually up year-over-year."
## 2 De Telegraaf (October 12, 2026, summary of its subscriber article): "De schriftelijke klantenservice van KLM wordt volledig verplaatst naar de Filipijnse hoofdstad Manilla. Uit interne documenten die De Telegraaf heeft ingezien, blijkt dat hierdoor zo’n 150 medewerkers hun huidige baan verliezen. Hun werk wordt overgenomen door Filipijnse medewerkers die Nederlandse klantvragen met behulp van een AI-vertaaltool gaan afhandelen." (Translation: KLM's written customer service is being moved entirely to the Philippine capital Manila. Internal documents seen by De Telegraaf show that about 150 employees will lose their current job as a result. Their work will be taken over by Philippine staff who will handle Dutch customer queries with the help of an AI translation tool.) A KLM spokeswoman, confirming the move (ANP, October 13, 2026): "Dit klantcontactcenter handelt al vele jaren vragen en klachten af voor KLM-klanten over de hele wereld. De kwaliteit van de afhandeling van vragen en klachten staat voor KLM voorop en zal voor Nederlandstalige klanten in het Nederlands blijven verlopen." (Translation: This customer contact centre has handled questions and complaints for KLM customers around the world for many years. For KLM the quality of handling questions and complaints comes first, and for Dutch-speaking customers it will continue to be in Dutch.) ANP adds: "Het verplaatsen gaat zoveel mogelijk via natuurlijk verloop. Het gaat om de werkzaamheden van 126 voltijdsbanen." (Translation: The move will happen as far as possible through natural attrition. It concerns the work of 126 full-time jobs.)
## 3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Reuters (2026-10-12): "Kroger plans to cut roughly 3,000 corporate roles over the next three years, CEO Greg Foran told staff in a memo, seen by Reuters on Monday, as the grocer integrates AI into its workflow." Foran's memo (full text published by Business Insider, which says Kroger shared it) gives as reasons: "Our company has more layers, more handoffs and more overhead than we need, so we are addressing this issue." and "Technology is reshaping what's possible. The way work gets done is changing across every industry; we must adapt and take advantage of technology. We need to adopt capabilities, reduce duplicative work and look closely at where work is best fit to be done." The memo does not mention AI.
## 4                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            One Zero CEO Eyal Gafni, letter to staff as quoted by Globes (2026-10-11): "ההתפתחות המהירה של GenAI (בינה מלאכותית יוצרת, א' ג') משנה כבר היום את הדרך שבה ארגונים עובדים, מפתחים מוצרים ומשרתים לקוחות" (Translation: "The rapid development of GenAI is already changing the way organizations work, develop products and serve customers."). The bank, quoted by CTech by Calcalist (2026-10-11), said adjustments were being made "wherever technology helps us accelerate processes," and Gafni wrote that the bank must remain "a fast, agile, and efficient organization at all times, enabling us to continue growing without expanding our workforce or cost base." CTech reports the bank's position: "The bank has not said that the employees being laid off are being directly replaced by AI. Rather, it says that the expanded use of automation and generative AI tools allows it to operate with a leaner organizational structure."
## 5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       HoneyBook, in a statement quoted by Calcalist (CTech, 2026-10-08): "HoneyBook is undergoing a reorganization process aimed at aligning our structure and workflows with the AI era, while integrating AI into our product and value proposition for customers. This move is driven by financial strength and strategic focus, with the goal of becoming a faster, more agile organization."
## 6                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            AFP (7 October 2026): "HSBC said Wednesday consultations were underway, after the Financial Times reported that hundreds of jobs were at risk from the bank's adoption of artificial intelligence." The FT reported, as quoted by AFP, that HSBC "is planning sweeping job cuts in its UK wealth management business ... as part of a push to use AI to help serve wealthy clients". HSBC's own statement names no AI: it is "continuing to evolve to deliver more digitally-enabled products and journeys, to support our best-in-class wealth service and meet the changing needs of our customers".
##                                                                                               Source
## 1                            The Motley Fool: Bank of America (BAC) Q3 2026 Earnings Call Transcript
## 2         ANP via Transport Online: KLM verplaatst deel schriftelijke klantenservice naar Filipijnen
## 3 Reuters via AOL: Kroger plans to eliminate 3,000 corporate roles, memo shows, as it expands AI use
## 4             CTech by Calcalist: One Zero lays off 25 employees in latest AI-driven efficiency push
## 5                 CTech by Calcalist: HoneyBook lays off 14% of workforce in AI-driven restructuring
## 6                                        AFP: HSBC 'consults' over UK unit job cuts amid AI adoption
##                                                                                                 Source.URL
## 1     https://www.fool.com/earnings/call-transcripts/2026/10/14/bofa-bac-q3-2026-earnings-call-transcript/
## 2 https://www.transport-online.nl/141605/klm-verplaatst-deel-schriftelijke-klantenservice-naar-filipijnen/
## 3                             https://www.aol.com/articles/kroger-plans-cut-third-corporate-204543000.html
## 4                                                 https://www.calcalistech.com/ctechnews/article/0ggruyjlr
## 5                                                https://www.calcalistech.com/ctechnews/article/syg9pbhizx
## 6                              https://www.afp.com/en/hsbc-consults-over-uk-unit-job-cuts-amid-ai-adoption
##                  Event.ID                Kind
## 1 bank-of-america-2026-10 workforce statement
## 2             klm-2026-10                 cut
## 3          kroger-2026-10                 cut
## 4        one-zero-2026-10                 cut
## 5       honeybook-2026-10                 cut
## 6            hsbc-2026-10                 cut
##                           What.the.employer.said
## 1 Spoke about AI and headcount; no cut announced
## 2     Named no AI reason; others linked it to AI
## 3     Named no AI reason; others linked it to AI
## 4                   Cited AI among other reasons
## 5                   Cited AI among other reasons
## 6     Named no AI reason; others linked it to AI
##                                              Job.families
## 1                                       Management layers
## 2                            Customer service and support
## 3                                     Corporate functions
## 4                                           Not specified
## 5                                           Not specified
## 6 Consulting and professional services; Management layers
str(udaje)
## 'data.frame':    300 obs. of  20 variables:
##  $ Company                     : chr  "Bank of America" "KLM" "Kroger" "One Zero" ...
##  $ Date                        : chr  "2026-10-14" "2026-10-12" "2026-10-12" "2026-10-11" ...
##  $ Sector                      : chr  "Banking" "Airline" "Grocery retail" "Digital banking" ...
##  $ Country                     : chr  "United States" "Netherlands" "United States" "Israel" ...
##  $ Functions                   : chr  "Managers (down about 5% year over year, per CEO Brian Moynihan, while client-facing staff rose)" "Written customer service (handling Dutch-language questions and complaints), per ANP and De Telegraaf" "Corporate roles across many functions (the memo does not name them)" "Not specified" ...
##  $ Roles.counted               : int  NA NA NA NA NA NA 400 581 660 NA ...
##  $ Roles.reported..not.counted.: int  NA 126 3000 25 30 NA NA NA NA 190 ...
##  $ Why.not.counted             : chr  "" "The company has not named AI as the cause; the number was reported by the press, not stated publicly by the com"| __truncated__ "The company has not named AI as the cause." "The number was reported by the press, not stated publicly by the company." ...
##  $ X..of.workforce             : chr  "about 1.5% of headcount year over year (CEO Brian Moynihan's figure)" "" "about 37% of roughly 8,200 corporate employees (Reuters, Bloomberg)" "about 7% (about 25 of about 350, per Calcalist)" ...
##  $ Evidence.tier               : chr  "Tier 1" "Tier 2" "Tier 2" "Tier 2" ...
##  $ Attribution                 : chr  "mixed" "blamed" "blamed" "mixed" ...
##  $ Execution                   : chr  "executed" "announced" "announced" "announced" ...
##  $ Counts.in.US.index          : chr  "no" "no" "no" "no" ...
##  $ Claim                       : chr  "CFO Alastair Borthwick, prepared remarks, Q3 2026 earnings call (October 14, 2026): \"We also invested in techn"| __truncated__ "De Telegraaf (October 12, 2026, summary of its subscriber article): \"De schriftelijke klantenservice van KLM w"| __truncated__ "Reuters (2026-10-12): \"Kroger plans to cut roughly 3,000 corporate roles over the next three years, CEO Greg F"| __truncated__ "One Zero CEO Eyal Gafni, letter to staff as quoted by Globes (2026-10-11): \"ההתפתחות המהירה של GenAI (בינה מלא"| __truncated__ ...
##  $ Source                      : chr  "The Motley Fool: Bank of America (BAC) Q3 2026 Earnings Call Transcript" "ANP via Transport Online: KLM verplaatst deel schriftelijke klantenservice naar Filipijnen" "Reuters via AOL: Kroger plans to eliminate 3,000 corporate roles, memo shows, as it expands AI use" "CTech by Calcalist: One Zero lays off 25 employees in latest AI-driven efficiency push" ...
##  $ Source.URL                  : chr  "https://www.fool.com/earnings/call-transcripts/2026/10/14/bofa-bac-q3-2026-earnings-call-transcript/" "https://www.transport-online.nl/141605/klm-verplaatst-deel-schriftelijke-klantenservice-naar-filipijnen/" "https://www.aol.com/articles/kroger-plans-cut-third-corporate-204543000.html" "https://www.calcalistech.com/ctechnews/article/0ggruyjlr" ...
##  $ Event.ID                    : chr  "bank-of-america-2026-10" "klm-2026-10" "kroger-2026-10" "one-zero-2026-10" ...
##  $ Kind                        : chr  "workforce statement" "cut" "cut" "cut" ...
##  $ What.the.employer.said      : chr  "Spoke about AI and headcount; no cut announced" "Named no AI reason; others linked it to AI" "Named no AI reason; others linked it to AI" "Cited AI among other reasons" ...
##  $ Job.families                : chr  "Management layers" "Customer service and support" "Corporate functions" "Not specified" ...
summary(udaje)
##       Company           Date           Sector         Country   
##  Length   :300   Length   :300   Length   :300   Length   :300  
##  N.unique :249   N.unique :225   N.unique :223   N.unique : 48  
##  N.blank  :  0   N.blank  :  0   N.blank  :  0   N.blank  :  0  
##  Min.nchar:  3   Min.nchar: 10   Min.nchar:  5   Min.nchar:  5  
##  Max.nchar: 39   Max.nchar: 10   Max.nchar: 68   Max.nchar: 87  
##                                                                 
##                                                                 
##      Functions   Roles.counted  Roles.reported..not.counted.  Why.not.counted
##  Length   :300   Min.   :   3   Min.   :    4.00             Length   :300   
##  N.unique :255   1st Qu.: 150   1st Qu.:   89.75             N.unique : 32   
##  N.blank  :  0   Median : 307   Median :  250.00             N.blank  :144   
##  Min.nchar: 10   Mean   : 857   Mean   : 1721.86             Min.nchar:  0   
##  Max.nchar:524   3rd Qu.: 800   3rd Qu.: 1102.50             Max.nchar:259   
##                  Max.   :8000   Max.   :21000.00                             
##                  NAs    :208    NAs    :144                                  
##   X..of.workforce   Evidence.tier    Attribution      Execution  
##  Length   :300    Length   :300   Length   :300   Length   :300  
##  N.unique :198    N.unique :  3   N.unique :  3   N.unique :  5  
##  N.blank  : 92    N.blank  :  0   N.blank  :  0   N.blank  :  0  
##  Min.nchar:  0    Min.nchar:  6   Min.nchar:  5   Min.nchar:  7  
##  Max.nchar:281    Max.nchar:  6   Max.nchar:  8   Max.nchar:  9  
##                                                                  
##                                                                  
##  Counts.in.US.index       Claim            Source        Source.URL 
##  Length   :300      Length   : 300   Length   :300   Length   :300  
##  N.unique :  2      N.unique : 300   N.unique :291   N.unique :299  
##  N.blank  :  0      N.blank  :   0   N.blank  :  0   N.blank  :  0  
##  Min.nchar:  2      Min.nchar: 168   Min.nchar:  4   Min.nchar: 35  
##  Max.nchar:  3      Max.nchar:1617   Max.nchar:210   Max.nchar:235  
##                                                                     
##                                                                     
##       Event.ID          Kind     What.the.employer.said    Job.families
##  Length   :300   Length   :300   Length   :300          Length   :300  
##  N.unique :300   N.unique :  2   N.unique :  7          N.unique : 68  
##  N.blank  :  0   N.blank  :  0   N.blank  :  0          N.blank  :  0  
##  Min.nchar: 10   Min.nchar:  3   Min.nchar: 27          Min.nchar: 13  
##  Max.nchar: 37   Max.nchar: 19   Max.nchar: 51          Max.nchar:127  
##                                                                        
## 
regdata <- udaje[!is.na(udaje$Roles.counted), ]
model <- lm(
  Roles.counted ~ Evidence.tier + Attribution + Execution,
  data = regdata
)
summary(model)
## 
## Call:
## lm(formula = Roles.counted ~ Evidence.tier + Attribution + Execution, 
##     data = regdata)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1759.7  -604.9  -343.4    29.8  6176.3 
## 
## Coefficients:
##                     Estimate Std. Error t value Pr(>|t|)  
## (Intercept)           346.87     504.78   0.687   0.4938  
## Evidence.tierTier 2   -46.16     328.20  -0.141   0.8885  
## Attributionmixed      303.48     446.45   0.680   0.4985  
## Executionexecuted      74.05     354.03   0.209   0.8348  
## Executionpartial     1173.35     446.15   2.630   0.0101 *
## Executionreversed    -301.87    1497.57  -0.202   0.8407  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1410 on 86 degrees of freedom
## Multiple R-squared:  0.1136, Adjusted R-squared:  0.06205 
## F-statistic: 2.204 on 5 and 86 DF,  p-value: 0.06113

Regresný model skúma vplyv premenných Evidence.tier, Attribution a Execution na počet dotknutých pracovných miest (Roles.counted).

Koeficient pri premennej Executionpartial je štatisticky významný na 5 % hladine významnosti (p = 0.0101). Ostatné premenné nevykazujú štatisticky významný vplyv na počet dotknutých pracovných miest.

Uloženie pracovného prostredia

Pre potreby ďalších cvičení je možné uložiť pracovné prostredie do súboru .RData a následne ho znovu načítať bez potreby opätovného importu databázy.

save.image("pamat.RData")

Pracovné prostredie je možné v budúcnosti obnoviť pomocou funkcie load().

load("pamat.RData")

Testovanie štatistickej významnosti koeficientov

Pre jednotlivé koeficienty testujeme hypotézy:

\[H_0:\beta_j = 0\] \[H_1:\beta_j \neq 0\]

Ak p-hodnota < 0,05, zamietame nulovú hypotézu a koeficient považujeme za štatisticky významný.

Kvalita modelu

summary(model)$r.squared
## [1] 0.1135894
summary(model)$adj.r.squared
## [1] 0.0620539

Koeficient determinácie R²

Koeficient determinácie dosiahol hodnotu 0,1136. To znamená, že model vysvetľuje približne 11,36 % variability premennej Roles.counted.

Hodnota R² je pomerne nízka, čo naznačuje, že premenné Evidence.tier, Attribution a Execution vysvetľujú len malú časť variability počtu dotknutých pracovných miest. Na rozsah prepúšťania pravdepodobne vplývajú aj ďalšie faktory, ktoré nie sú v modeli zahrnuté.

Upravený koeficient determinácie

Hodnota Adjusted R² je 0,0621. Po zohľadnení počtu vysvetľujúcich premenných model vysvetľuje približne 6,21 % variability závislej premennej.

F-test model

Celkovú štatistickú významnosť modelu overujeme pomocou F-testu.

\[H_0:\beta_i = 0 \quad \forall i\] \[H_1:\exists i,\beta_i\neq0\]

summary(model)$fstatistic
##   value   numdf   dendf 
##  2.2041  5.0000 86.0000

Hodnota F-štatistiky je 2,204.

P-hodnota F-testu je 0,06113. Keďže je väčšia ako 0,05, na 5 % hladine významnosti nezamietame nulovú hypotézu. Regresný model ako celok nie je štatisticky významný.

Hoci model zachytáva určité vzťahy medzi premennými, výsledok F-testu nepreukázal jeho celkovú štatistickú významnosť na 5 % hladine významnosti. To naznačuje, že vysvetľovacie premenné nemusia dostatočne opisovať rozdiely v počte dotknutých pracovných miest medzi jednotlivými udalosťami.

Test normality rezíduí

Normalitu rezíduí sme overili pomocou Shapiro-Wilkovho testu.

\[H_0: \text{Reziduá majú normálne rozdelenie}\] \[H_1: \text{Reziduá nemajú normálne rozdelenie}\]

shapiro.test(residuals(model))
## 
##  Shapiro-Wilk normality test
## 
## data:  residuals(model)
## W = 0.7178, p-value = 5.26e-12

Shapiro-Wilkov test poskytol hodnotu p-value = 5,26 × 10^-12.

Keďže p-hodnota je menšia ako 0,05, zamietame nulovú hypotézu o normalite rezíduí. Reziduá regresného modelu preto nemajú normálne rozdelenie.

Výsledok Shapiro-Wilkovho testu naznačuje, že reziduá nie sú normálne rozdelené. Tento výsledok môže byť spôsobený vysokou variabilitou počtu prepustených zamestnancov, keďže databáza obsahuje udalosti s veľmi rozdielnym rozsahom od jednotiek až po tisíce pracovných miest.

Diagnostika regresného modelu

par(mfrow = c(2,2))
plot(model)
## Warning: not plotting observations with leverage one:
##   65

Diagnostické grafy slúžia na vizuálne overenie predpokladov regresného modelu. Sledujeme najmä linearitu vzťahov, homogenitu rozptylu rezíduí a prítomnosť odľahlých pozorovaní.

Diagnostické grafy naznačujú určitú heterogenitu rozptylu rezíduí a prítomnosť niekoľkých odľahlých pozorovaní. Tento výsledok je očakávaný vzhľadom na výrazné rozdiely v počte prepustených zamestnancov medzi jednotlivými spoločnosťami.

Q-Q graf zároveň potvrdzuje odchýlky od normálneho rozdelenia rezíduí, čo je v súlade s výsledkom Shapiro-Wilkovho testu.

Záver

V práci bol vytvorený lineárny regresný model pre databázu AI Layoffs Register. Závislou premennou bol počet dotknutých pracovných miest (Roles.counted), pričom medzi vysvetľujúce premenné boli zaradené Evidence.tier, Attribution a Execution.

Výsledky ukázali, že štatisticky významný vplyv mala iba premenná Executionpartial. Koeficient determinácie R² dosiahol hodnotu 0,1136, čo znamená, že model vysvetľuje približne 11,36 % variability závislej premennej.

Shapiro-Wilkov test zároveň preukázal, že reziduá modelu nemajú normálne rozdelenie. Získaný model preto poskytuje iba obmedzenú vysvetľovaciu schopnosť a je vhodný najmä na základnú analýzu vzťahov medzi premennými.