Home > other >  Labels for Categories of Two Categorical Variables in Interaction - Multiple Linear Regression
Labels for Categories of Two Categorical Variables in Interaction - Multiple Linear Regression

Time:01-04

I am working with a data set that looks like below where the year spans from 2000-2021 and the different types of energy a specific country produced (in terrawatt hours) is listed in the columns starting at "Bioenergy" going right.

# A tibble: 4,707 × 13
   Country             Region  Conti…¹ Year  Bioen…²   Coal   Gas Hydro Nuclear Other…³ Other…⁴ Solar  Wind
   <fct>               <fct>   <chr>   <fct>   <dbl>  <dbl> <dbl> <dbl>   <dbl>   <dbl>   <dbl> <dbl> <dbl>
 1 Afghanistan         Southe… Asia    2000     0      0     0     0.31       0    0.16       0     0     0
 2 Albania             Southe… Europe  2000     0      0     0     0.5        0    0.09       0     0     0
 3 Algeria             Northe… Africa  2000     0      0    22.9   0.56       
# … with 4,697 more rows, and abbreviated variable names ¹​Continent, ²​Bioenergy, ³​`Other Fossil`,
#   ⁴​`Other Renewables`

I ran a linear regression using the following code:

model1 <-lm(Bioenergy ~ Year*Region, data= data)
summary(model1)

and the output looks like this:

Call:
lm(formula = Bioenergy ~ Year * Region, data = data)

Residuals:
    Min      1Q  Median      3Q     Max 
-27.992  -0.988  -0.096  -0.002 141.938 

Coefficients:
                 Estimate Std. Error t value Pr(>|t|)    
(Intercept)      2.055035   0.123232  16.676  < 2e-16 ***
Year1:Region1    1.572657   2.967886   0.530 0.596215    
Year2:Region1   -0.407378   2.967886  -0.137 0.890830    
Year3:Region1    0.366339   2.967886   0.123 0.901769    
Year4:Region1    0.110653   2.967746   0.037 0.970259    
Year5:Region1    0.117725   2.967746   0.040 0.968359    
Year6:Region1    0.060654   2.967661   0.020 0.983695    
Year7:Region1    0.047301   2.967661   0.016 0.987284    
Year8:Region1    0.024555   2.967661   0.008 0.993399    
Year9:Region1   -0.291229   2.967661  -0.098 0.921830    
Year10:Region1  -0.321546   2.967661  -0.108 0.913723    
Year11:Region1  -0.019364   2.967661  -0.007 0.994794    
Year12:Region1  -0.031005   2.967661  -0.010 0.991665    
Year13:Region1   0.145939   2.967384   0.049 0.960777    

How do I get the actual value that I see in the data for "Year" and "Region" to show up in the Coefficients block such that:

"Year4:Region1" becomes

"2004:Afghanistan" (for example - I don't know if that is what it would actually be)

Thank you all!! Mark

Here is a sample of the data that can be loaded into R:

structure(list(Country = structure(c(177L, 143L, 191L, 8L, 130L, 
5L, 138L, 20L, 108L, 99L, 40L, 146L, 182L, 82L, 131L, 190L, 162L, 
184L, 52L, 137L, 26L, 156L, 80L, 148L, 63L, 41L, 12L, 146L, 203L, 
78L, 49L, 65L, 165L, 40L, 20L, 191L, 163L, 210L, 49L, 156L, 121L, 
59L, 149L, 170L, 141L, 163L, 202L, 150L, 49L, 182L, 4L, 38L, 
184L, 192L, 109L, 37L, 13L, 212L, 194L, 123L, 77L, 118L, 59L, 
113L, 34L, 158L, 37L, 215L, 17L, 87L, 60L, 133L, 195L, 15L, 147L, 
127L, 45L, 43L, 205L, 3L, 93L, 114L, 106L, 175L, 127L, 100L, 
119L, 105L, 211L, 202L, 39L, 203L, 110L, 190L, 58L, 21L, 207L, 
4L, 13L, 154L, 44L, 88L, 198L, 62L, 129L, 171L, 67L, 179L, 20L, 
159L, 212L, 154L, 80L, 148L, 212L, 107L, 5L, 53L, 9L, 159L, 76L, 
209L, 116L, 182L, 183L, 56L, 108L, 79L, 173L, 215L, 139L, 117L, 
88L, 138L, 67L, 29L, 189L, 80L, 188L, 156L, 167L, 29L, 123L, 
98L, 95L, 63L, 111L, 155L, 36L, 55L, 4L, 193L, 215L, 158L, 60L, 
113L, 202L, 85L, 22L, 46L, 50L, 17L, 145L, 152L, 5L, 119L, 169L, 
172L, 156L, 131L, 36L, 162L, 151L, 125L, 6L, 34L, 196L, 154L, 
42L, 137L, 126L, 166L, 107L, 131L, 29L, 145L, 129L, 76L, 20L, 
35L, 53L, 197L, 129L, 197L, 145L, 123L, 141L, 211L, 191L, 112L, 
123L, 201L, 214L, 103L, 118L, 42L, 182L, 40L, 196L, 174L, 85L, 
22L, 77L, 2L, 200L, 140L, 81L, 152L, 173L, 22L, 125L, 143L, 175L, 
125L, 212L, 95L, 115L, 107L, 66L, 64L, 128L, 194L, 193L, 85L, 
103L, 15L, 124L, 98L, 156L, 144L, 41L, 98L, 123L, 214L, 127L, 
111L, 51L, 25L, 105L, 108L), levels = c("Afghanistan", "Albania", 
"Algeria", "American Samoa", "Angola", "Antigua and Barbuda", 
"Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", 
"Bahamas (the)", "Bahrain", "Bangladesh", "Barbados", "Belarus", 
"Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", 
"Bosnia Herzegovina", "Botswana", "Brazil", "Brunei Darussalam", 
"Bulgaria", "Burkina Faso", "Burundi", "Cabo Verde", "Cambodia", 
"Cameroon", "Canada", "Cayman Islands (the)", "Central African Republic (the)", 
"Chad", "Chile", "China", "Colombia", "Comoros (the)", "Congo (the Democratic Republic of the)", 
"Congo (the)", "Cook Islands (the)", "Costa Rica", "Cote d'Ivoire", 
"Croatia", "Cuba", "Cyprus", "Czechia", "Denmark", "Djibouti", 
"Dominica", "Dominican Republic (the)", "Ecuador", "Egypt", "El Salvador", 
"Equatorial Guinea", "Eritrea", "Estonia", "Eswatini", "Ethiopia", 
"Falkland Islands (the) [Malvinas]", "Faroe Islands (the)", "Fiji", 
"Finland", "France", "French Guiana", "French Polynesia", "Gabon", 
"Gambia (the)", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", 
"Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", 
"Guinea-Bissau", "Guyana", "Haiti", "Honduras", "Hong Kong", 
"Hungary", "Iceland", "India", "Indonesia", "Iran (Islamic Republic of)", 
"Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", 
"Kazakhstan", "Kenya", "Kiribati", "Korea (the Democratic People's Republic of)", 
"Kosovo", "Kuwait", "Kyrgyzstan", "Lao People's Democratic Republic (the)", 
"Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Lithuania", 
"Luxembourg", "Macao", "Madagascar", "Malawi", "Malaysia", "Maldives", 
"Mali", "Malta", "Martinique", "Mauritania", "Mauritius", "Mexico", 
"Moldova", "Mongolia", "Montenegro", "Montserrat", "Morocco", 
"Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", 
"New Caledonia", "New Zealand", "Nicaragua", "Niger (the)", "Nigeria", 
"Niue", "North Macedonia", "Norway", "Oman", "Pakistan", "Palestine, State of", 
"Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines (the)", 
"Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", 
"Russian Federation (the)", "Rwanda", "Saint Helena, Ascension and Tristan da Cunha", 
"Saint Kitts and Nevis", "Saint Lucia", "Saint Pierre and Miquelon", 
"Saint Vincent and the Grenadines", "Samoa", "Sao Tome and Principe", 
"Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", 
"Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", 
"South Africa", "South Korea", "South Sudan", "Spain", "Sri Lanka", 
"Sudan (the)", "Suriname", "Sweden", "Switzerland", "Syrian Arab Republic (the)", 
"Taiwan", "Tajikistan", "Tanzania, the United Republic of", "Thailand", 
"Timor-Leste", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", 
"Turkey", "Turkmenistan", "Turks and Caicos Islands (the)", "Uganda", 
"Ukraine", "United Arab Emirates", "United Kingdom", "United States of America", 
"Uruguay", "Uzbekistan", "Vanuatu", "Venezuela (Bolivarian Republic of)", 
"Viet Nam", "Virgin Islands (British)", "Virgin Islands (U.S.)", 
"Western Sahara", "Yemen", "Zambia", "Zimbabwe"), class = "factor"), 
    Region = structure(c(5L, 19L, 16L, 21L, 11L, 10L, 2L, 20L, 
    12L, 21L, 14L, 15L, 15L, 20L, 5L, 5L, 3L, 14L, 5L, 8L, 14L, 
    21L, 9L, 4L, 14L, 5L, 21L, 15L, 12L, 3L, 21L, 8L, 3L, 14L, 
    20L, 16L, 3L, 3L, 21L, 21L, 19L, 5L, 8L, 19L, 20L, 3L, 21L, 
    14L, 21L, 15L, 13L, 14L, 14L, 16L, 21L, 10L, 3L, 11L, 13L, 
    20L, 1L, 16L, 5L, 12L, 1L, 7L, 10L, 5L, 7L, 6L, 12L, 17L, 
    3L, 18L, 21L, 6L, 4L, 10L, 14L, 11L, 21L, 22L, 15L, 19L, 
    6L, 15L, 15L, 21L, 3L, 21L, 6L, 12L, 17L, 5L, 10L, 1L, 8L, 
    13L, 3L, 19L, 13L, 7L, 15L, 5L, 3L, 5L, 22L, 6L, 20L, 7L, 
    11L, 19L, 9L, 4L, 11L, 16L, 10L, 3L, 3L, 7L, 19L, 16L, 5L, 
    15L, 11L, 11L, 12L, 3L, 16L, 5L, 4L, 5L, 7L, 2L, 22L, 20L, 
    15L, 9L, 6L, 21L, 10L, 20L, 20L, 6L, 21L, 14L, 20L, 3L, 10L, 
    14L, 13L, 20L, 5L, 7L, 12L, 12L, 21L, 3L, 18L, 20L, 7L, 7L, 
    21L, 16L, 10L, 15L, 20L, 20L, 21L, 5L, 10L, 3L, 14L, 4L, 
    3L, 1L, 11L, 19L, 10L, 8L, 7L, 13L, 16L, 5L, 20L, 21L, 3L, 
    19L, 20L, 3L, 3L, 21L, 3L, 21L, 21L, 20L, 20L, 3L, 16L, 11L, 
    20L, 7L, 5L, 6L, 16L, 10L, 15L, 14L, 11L, 7L, 3L, 18L, 1L, 
    19L, 5L, 20L, 4L, 16L, 16L, 18L, 4L, 19L, 19L, 4L, 11L, 21L, 
    6L, 16L, 12L, 12L, 19L, 13L, 20L, 3L, 6L, 18L, 5L, 6L, 21L, 
    12L, 5L, 6L, 20L, 5L, 6L, 20L, 12L, 17L, 21L, 12L), levels = c("Northern America", 
    "Austrailia & New Zealand", "Carribbean", "Central America", 
    "Eastern Africa", "Eastern Asia", "Eastern Europe", "Melanesia", 
    "Micronesia", "Middle Africa", "Northern Africa", "Northern Europe", 
    "Polynesia", "South America", "South Central Asia", "Southeastern Asia", 
    "Southern Africa", "Southern Asia", "Southern Europe", "Western Africa", 
    "Western Asia", "Western Europe"), class = "factor"), Continent = c("Africa", 
    "Europe", "Asia", "Asia", "Africa", "Africa", "Oceania", 
    "Africa", "Europe", "Asia", "South America", "Asia", "Asia", 
    "Africa", "Africa", "Africa", "North America", "South America", 
    "Africa", "Oceania", "South America", "Asia", "Oceania", 
    "North America", "South America", "Africa", "Asia", "Asia", 
    "Europe", "North America", "Europe", "Oceania", "North America", 
    "South America", "Africa", "Asia", "North America", "North America", 
    "Europe", "Asia", "Europe", "Africa", "Oceania", "Europe", 
    "Africa", "North America", "Asia", "South America", "Europe", 
    "Asia", "Oceania", "South America", "South America", "Asia", 
    "Asia", "Africa", "North America", "Africa", "Oceania", "Africa", 
    "North America", "Asia", "Africa", "Europe", "North America", 
    "Europe", "Africa", "Africa", "Europe", "Asia", "Europe", 
    "Africa", "North America", "Asia", "Asia", "Asia", "North America", 
    "Africa", "South America", "Africa", "Asia", "Europe", "Asia", 
    "Europe", "Asia", "Asia", "Asia", "Asia", "North America", 
    "Asia", "Asia", "Europe", "Africa", "Africa", "Africa", "North America", 
    "Oceania", "Oceania", "North America", "Europe", "Oceania", 
    "Europe", "Asia", "Africa", "North America", "Africa", "Europe", 
    "Asia", "Africa", "Europe", "Africa", "Europe", "Oceania", 
    "North America", "Africa", "Asia", "Africa", "North America", 
    "South America", "Europe", "Europe", "Asia", "Africa", "Asia", 
    "Africa", "Africa", "Europe", "North America", "Asia", "Africa", 
    "North America", "Africa", "Europe", "Oceania", "Europe", 
    "Africa", "Asia", "Oceania", "Asia", "Asia", "Africa", "Africa", 
    "Africa", "Asia", "Asia", "South America", "Africa", "North America", 
    "Africa", "South America", "Oceania", "Africa", "Africa", 
    "Europe", "Europe", "Europe", "Asia", "North America", "Asia", 
    "Africa", "Europe", "Europe", "Asia", "Asia", "Africa", "Asia", 
    "Africa", "Africa", "Asia", "Africa", "Africa", "North America", 
    "South America", "North America", "North America", "North America", 
    "Africa", "Europe", "Africa", "Oceania", "Europe", "Oceania", 
    "Asia", "Africa", "Africa", "Asia", "North America", "Europe", 
    "Africa", "North America", "North America", "Asia", "North America", 
    "Asia", "Asia", "Africa", "Africa", "North America", "Asia", 
    "Africa", "Africa", "Europe", "Africa", "Asia", "Asia", "Africa", 
    "Asia", "South America", "Africa", "Europe", "North America", 
    "Asia", "North America", "Europe", "Africa", "Africa", "North America", 
    "Asia", "Asia", "Asia", "North America", "Europe", "Europe", 
    "North America", "Africa", "Asia", "Asia", "Asia", "Europe", 
    "Europe", "Europe", "Oceania", "Africa", "North America", 
    "Asia", "Asia", "Africa", "Asia", "Asia", "Europe", "Africa", 
    "Asia", "Africa", "Africa", "Asia", "Africa", "Europe", "Africa", 
    "Asia", "Europe"), Year = structure(c(17L, 10L, 20L, 8L, 
    6L, 6L, 8L, 12L, 7L, 8L, 22L, 1L, 8L, 5L, 19L, 15L, 1L, 16L, 
    11L, 4L, 19L, 18L, 9L, 5L, 1L, 5L, 18L, 3L, 14L, 10L, 21L, 
    9L, 9L, 7L, 8L, 18L, 18L, 6L, 3L, 8L, 20L, 7L, 7L, 2L, 9L, 
    15L, 6L, 19L, 22L, 11L, 12L, 13L, 7L, 17L, 12L, 12L, 6L, 
    10L, 12L, 1L, 11L, 9L, 3L, 5L, 13L, 3L, 1L, 13L, 5L, 20L, 
    4L, 4L, 10L, 11L, 9L, 6L, 19L, 4L, 17L, 12L, 15L, 4L, 14L, 
    19L, 4L, 19L, 10L, 21L, 6L, 5L, 16L, 16L, 10L, 19L, 14L, 
    12L, 2L, 1L, 2L, 11L, 5L, 20L, 15L, 2L, 12L, 13L, 1L, 8L, 
    7L, 13L, 3L, 17L, 13L, 14L, 7L, 9L, 1L, 17L, 7L, 19L, 22L, 
    11L, 13L, 4L, 19L, 4L, 6L, 2L, 2L, 16L, 6L, 4L, 13L, 3L, 
    20L, 12L, 22L, 22L, 19L, 21L, 2L, 11L, 5L, 5L, 20L, 17L, 
    19L, 11L, 18L, 20L, 21L, 12L, 2L, 11L, 11L, 13L, 19L, 13L, 
    21L, 8L, 10L, 8L, 12L, 7L, 10L, 4L, 5L, 13L, 15L, 14L, 14L, 
    17L, 9L, 16L, 22L, 17L, 21L, 6L, 13L, 6L, 2L, 6L, 18L, 9L, 
    3L, 14L, 20L, 15L, 9L, 22L, 13L, 4L, 15L, 14L, 8L, 12L, 13L, 
    12L, 7L, 16L, 4L, 11L, 20L, 3L, 7L, 9L, 9L, 4L, 22L, 22L, 
    2L, 14L, 17L, 7L, 10L, 15L, 16L, 6L, 8L, 22L, 5L, 3L, 11L, 
    18L, 19L, 5L, 19L, 15L, 8L, 8L, 19L, 10L, 2L, 8L, 4L, 17L, 
    20L, 12L, 7L, 11L, 19L, 15L, 16L, 5L, 18L, 20L, 4L, 1L, 12L, 
    12L), levels = c("2000", "2001", "2002", "2003", "2004", 
    "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", 
    "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020", 
    "2021"), class = "factor"), Bioenergy = c(0, 0, 12.19, 0, 
    0, 0, 0.7, 0, 0.04, 0.02, 1.24, 0.77, 0.01, 0, 0.11, 0.57, 
    0, 0.01, 0, 0, 51.76, 0.03, 0, 0.03, 0, 0, 0, 0.82, 18.1, 
    0, 0.06, 0.1, 0, 0.2, 0, 9.05, 0, 0, 0, 0, 0.01, 0, 0.1, 
    0, 0.01, 0, 0, 0, 0.06, 0.04, 0, 0, 0, 0, 0, 0.01, 0, 0, 
    0, 0, 0, 0.8, 0, 0.01, 10.02, 0, 0.01, 0.34, 0, 0, 0.03, 
    0, 0, 0.01, 0, 0, 0.04, 0.02, 1.51, 0, 0, 0.03, 0, 0.26, 
    0, 0, 0, 0, 0, 0, 54.07, 28.47, 0, 0.56, 0, 0, 0, 0, 0, 2.61, 
    0, 2.23, 0, 0.01, 0, 0, 2.48, 0.36, 0, 0.47, 0, 3.07, 0, 
    0.1, 0, 0, 0, 0, 0, 0.48, 0.45, 0.06, 0, 0, 0.91, 0, 0.04, 
    0.39, 0, 0.42, 0.49, 0.07, 1.65, 0.55, 8.64, 0, 0, 0, 1.98, 
    0.03, 0, 0, 0, 15.75, 0.1, 0, 0, 0, 0, 1.6, 0, 0, 0.28, 0.11, 
    0.74, 0.22, 0.01, 0, 0, 0, 1.85, 0.03, 0, 0.03, 0, 0, 0.06, 
    0, 0.03, 0.17, 0, 0, 0.11, 7.12, 0, 10.63, 0, 1.68, 0, 0, 
    0, 0.01, 0.21, 0.03, 0, 0, 0, 0.22, 0, 0, 0, 0.08, 0, 0.88, 
    0, 0, 0.02, 0, 1.87, 0, 0, 0.19, 0.17, 0, 0.62, 0, 0.06, 
    0.16, 0, 1.66, 0, 0, 0, 0, 0.09, 0, 2.44, 0.03, 0, 0, 6.63, 
    0, 0.22, 7.51, 0, 0, 0, 0.01, 9.95, 0, 0, 0, 0, 0, 0, 0.03, 
    0.36, 20.06, 0, 0.35, 0, 22.86, 0, 0.01, 0, 0, 2.49, 0, 0, 
    0.12), Coal = c(0, 5.3, 34.7, 0, 11.12, 0, 5.85, 0, 0, 0, 
    6.21, 0.53, 0, 0, 0, 0, 0, 0, 0, 0, 22.52, 0, 0, 0, 0, 0, 
    0, 0.55, 130.26, 0, 0, 0, 0, 2.23, 0, 34.81, 0, 0, 0, 0, 
    0, 0, 0, 21.86, 0.66, 0, 0, 0, 0, 0, 0, 26.34, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 31.03, 0, 0, 61.98, 20.31, 0, 3.22, 0, 22.55, 
    0, 0.01, 0, 1.75, 0, 3.3, 0, 0, 0, 0, 0, 0, 0.81, 4.62, 3.02, 
    74.83, 0, 0, 0, 0, 4046.17, 75.88, 0, 0, 0, 0, 0, 0, 0, 7.1, 
    0, 4.03, 0, 0, 0, 0, 27, 160.9, 0, 159.39, 0, 12.63, 0, 0.4, 
    0, 0, 0, 0, 0, 167.77, 6.2, 15.91, 0.23, 0, 0, 0, 0, 0.82, 
    0, 3.98, 0, 0, 6.34, 5.9, 3.64, 0, 0.55, 0, 132.26, 0, 0, 
    0, 0, 254, 19.14, 0, 0, 0, 0, 0, 0, 0, 4.33, 20.68, 0, 0, 
    0, 0, 0, 0, 45.94, 0, 0, 14.07, 0, 0, 0, 0, 0, 0, 0, 0, 0.38, 
    31.48, 0, 58.29, 0, 15.23, 0, 0, 3.07, 0, 10.08, 0, 0, 0, 
    0, 25.75, 0, 0, 0, 31.42, 0, 61.92, 0, 0, 0.77, 0, 23.04, 
    0, 0, 67.3, 1.3, 8.61, 26.63, 0, 0, 2.09, 0, 2.11, 0, 0, 
    0, 0, 0, 0, 1.81, 14.26, 0, 0, 21.74, 5.12, 5.29, 28.54, 
    0, 25.9, 0, 0, 13.89, 0, 1.55, 0, 0, 0, 8.72, 1.66, 0.78, 
    267.62, 0, 0.04, 0, 341.57, 0, 0, 5.27, 0, 25.31, 0.89, 0, 
    0), Gas = c(0, 0, 118.02, 1.4, 2.44, 0, 8.19, 0, 2.1, 9.73, 
    14.37, 29.66, 0, 0, 1.95, 0, 0, 0, 0, 0, 51.99, 42.79, 0, 
    0, 0, 0, 13.49, 31.58, 95.84, 0, 0, 0, 0, 7.41, 0, 117.91, 
    0, 0, 0, 18.29, 1.83, 0, 0, 0.5, 13.81, 0, 57.05, 0, 0, 0, 
    0, 12.48, 0, 0, 6.58, 0, 0, 0, 0, 0, 0, 71.48, 0, 2.69, 56.52, 
    8.97, 0, 0, 29.31, 12.16, 0.5, 0, 6.96, 21.34, 0.2, 0, 0, 
    0, 1.06, 46.44, 45.09, 2.62, 0, 0.48, 0, 21.47, 0, 66.89, 
    0, 49.27, 166.91, 99.88, 0, 1.92, 0, 0, 0, 0, 0, 14.9, 0, 
    8.7, 12.42, 0, 0, 0, 11.51, 79.62, 0, 495.72, 0, 12.58, 0, 
    0, 0, 0, 0, 0, 0, 497.51, 22.3, 44.77, 0, 0, 1.71, 62.61, 
    1.49, 0, 17.72, 0, 0, 0, 9.4, 5.59, 39.31, 0, 0.27, 0, 93.11, 
    44.48, 0, 0, 0, 221.73, 45.43, 0, 0, 0, 0, 1.38, 0, 0, 0, 
    7.26, 0.3, 2.88, 126.61, 0, 0, 3.5, 0.98, 29.81, 20.56, 9.57, 
    0, 0, 0, 0, 36.34, 0, 0, 0, 7.72, 173.69, 0, 59.59, 18.73, 
    13.61, 0, 0, 2.21, 0, 0, 0, 0, 24.67, 0, 6.79, 0, 0, 0, 63.54, 
    0, 105.12, 13.32, 0, 20.89, 0, 88.93, 34.03, 0, 15.7, 0, 
    0, 67.39, 0, 0, 6.95, 19.08, 4.19, 0, 0, 0, 0, 0, 0, 0, 10.39, 
    26.65, 0, 84.38, 0, 0.55, 178.21, 0, 18.5, 0.66, 0, 10.56, 
    0, 0, 0, 0, 0, 0, 44.93, 0, 356.58, 16.06, 4.8, 0, 433.09, 
    0, 0, 0, 0, 9.76, 0, 54.04, 3.01), Hydro = c(0, 0.68, 0, 
    0.13, 7.34, 0, 0, 1.99, 0, 19.64, 58.94, 32.51, 5.44, 0.33, 
    6.34, 0, 1.83, 0.16, 8.17, 0.08, 0, 0, 0.59, 1.5, 0.15, 0, 
    0.01, 381.73, 0.09, 18.63, 0, 2.91, 0.13, 0.01, 0.17, 3.46, 
    0, 0.43, 6.97, 0, 0, 0.23, 0.49, 0.39, 0, 135.47, 0.05, 8.34, 
    82.83, 12.66, 19.2, 0, 57.6, 0.03, 0, 0.62, 0, 0.18, 0.68, 
    0, 3.39, 0, 8.95, 0, 0, 0, 4.72, 0, 45.94, 1.7, 1.83, 0, 
    0.06, 83.16, 0.25, 7, 1.19, 0, 0.06, 19.33, 6.31, 0, 3.29, 
    0.99, 0, 26.41, 2.9, 10.14, 0.58, 0.05, 7.18, 0, 5.94, 66.43, 
    0.84, 1.86, 0.08, 0.63, 37.1, 0, 0, 2.56, 30.55, 0, 0.52, 
    27.38, 0, 4, 0, 0.12, 0.13, 0, 0, 0, 0, 0, 0.56, 174.07, 
    0, 0.74, 65.07, 8.36, 0, 22.5, 60.12, 0.03, 1.6, 0, 0.31, 
    0, 10.93, 0, 0, 424.05, 16.83, 0.33, 12.37, 51.98, 65.85, 
    5.89, 0.32, 0.05, 6.42, 0, 2.35, 173.51, 30.51, 0, 0, 16.17, 
    0.05, 0.7, 0, 0, 9.27, 0, 38.29, 0, 57.86, 0.89, 131.7, 0.22, 
    0.12, 0.5, 0.23, 0, 7.04, 30.09, 133.66, 1.39, 0, 0, 0.15, 
    8.58, 6.59, 15.97, 8.58, 12.8, 0, 11.02, 0, 12.77, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 21.81, 0.76, 0.1, 0, 0.42, 0.2, 1.34, 
    63.77, 6.96, 0, 3.21, 0.05, 6.72, 0.09, 0, 2.32, 0, 3.79, 
    8.02, 0, 2.75, 0.04, 0, 0.16, 1.58, 55.19, 12.52, 6.35, 0, 
    6.53, 375.97, 0, 0.02, 29.91, 1.07, 2.67, 0, 0, 0, 5.91, 
    0.11, 0.18, 8.19, 387.87, 0.54, 0, 0, 10.78, 0.1, 0.94, 5.66, 
    9.92, 0, 0.02, 3.71, 0.04, 3.51, 0, 0), Nuclear = c(0, 0, 
    0, 0, 0, 0, 0, 0, 0, 163.05, 0, 5.73, 0, 0, 0, 0, 2.35, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 15.16, 4.08, 0, 0, 0, 0, 0, 0, 
    5.88, 0, 0, 0, 0, 0, 0, 0, 48.23, 0, 0, 0, 0, 0, 0, 0, 0, 
    439.73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 12.75, 0, 0, 0, 0, 0, 0, 0, 0, 52.76, 0, 
    92.54, 0, 0, 0, 0, 0, 60.47, 0, 0, 0, 0, 0, 0, 0, 0, 2.41, 
    0, 0, 10.32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 137.47, 0, 
    0, 0, 0, 0, 0, 77.49, 0, 0, 0, 47.94, 0, 0, 0, 0, 14.8, 0, 
    0, 0, 0, 52.17, 63.75, 47.31, 0, 0, 0, 0, 169.07, 58.3, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 25.47, 0, 0, 0, 32.22, 0, 0, 0, 15.43, 
    0, 0, 10.4, 0, 0, 0, 0, 0, 0, 0, 7.71, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4.25, 0, 9.83, 0, 0, 436.48, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 14.97, 0, 0, 25.56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97.58, 
    0, 0, 0, 22.3, 0, 14.28, 0, 0, 0, 0, 0, 0, 0, 0, 0), `Other Fossil` = c(0.05, 
    2.68, 0.44, 0.39, 3.98, 4.75, 0, 0, 0.01, 24.45, 0, 19.49, 
    4.77, 0.06, 4.39, 0, 0, 20.76, 7.15, 0.02, 0.31, 2.06, 0.4, 
    0, 1.33, 0.04, 0.02, 9.39, 5.79, 18.85, 6.68, 3.61, 0.81, 
    10.32, 0.38, 0.05, 1.58, 0.98, 0, 0, 0, 0.04, 0.4, 3.71, 
    1, 0.74, 0.46, 2.62, 0, 0.12, 0, 0.15, 11.74, 0.11, 1.22, 
    6.78, 4.63, 2.9, 0.5, 0.31, 2.07, 0.08, 0, 0.03, 0.1, 0.37, 
    0, 0, 0.52, 3.44, 0.26, 0.67, 4.83, 117.52, 0.26, 3.74, 0.13, 
    0.38, 0.05, 0, 0, 0.45, 0.24, 0.89, 0.62, 21.03, 15.85, 2.62, 
    0.96, 14.61, 2.45, 0, 13.47, 3.48, 3.76, 0, 0.35, 0.31, 3.41, 
    0, 0.05, 2.87, 18.18, 1.89, 0.23, 67.68, 0.16, 5.86, 0.41, 
    1.62, 1.49, 0.38, 2.05, 0.03, 0, 0.03, 0.33, 22.53, 0.28, 
    0.69, 1.75, 0, 0, 0.98, 4.23, 0.82, 5.48, 0.04, 3.35, 0, 
    7.06, 0.39, 2.11, 13.6, 0.09, 5.07, 0.66, 1.24, 2.55, 5.81, 
    4.92, 2.43, 0.07, 0.02, 2.34, 10.1, 12.38, 0, 74.67, 0.1, 
    0, 0.62, 0.14, 0, 1.24, 0, 2.72, 2.3, 3.34, 1.26, 9.35, 0.42, 
    0.04, 0.36, 0.83, 0.55, 1.85, 48.8, 0.2, 0.03, 0.02, 0.05, 
    0.3, 17.56, 1.14, 1.3, 0.92, 14.87, 0.26, 5.46, 1.01, 20.85, 
    0.26, 0.61, 0, 0.03, 0, 0.5, 0, 0.05, 0.61, 3.07, 0.21, 5.33, 
    0, 0.42, 1.36, 0.16, 11.26, 8.88, 0.59, 0.34, 0, 0.11, 0.16, 
    1.76, 4.29, 0.34, 0, 0.08, 0.03, 0, 0.12, 0.24, 5.31, 0.11, 
    0, 10.25, 5.48, 0.04, 0.53, 13.94, 0, 0.06, 3.34, 0.28, 4.12, 
    0, 0.29, 0.26, 3.62, 4.75, 0.04, 0, 5.95, 1.9, 0, 1.26, 8.26, 
    0.02, 0, 0, 16.1, 4.38, 0.04, 0.86, 0.86, 0.23, 0.96, 1.23
    ), `Other Renewables` = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13.06, 
    0, 0.28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0.47, 0, 0, 0, 0, 0, 0, 0, 1.45, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 2.34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 7.3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.4, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 1.21, 0, 0, 0.46, 0.03, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0.9, 0, 0, 0, 0, 0, 0, 0, 0, 6.68, 0, 0, 0, 0, 0, 
    11.04, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.1, 0, 
    0, 0.06, 0, 0, 0, 0, 0, 0, 0.56, 10.24, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.22, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.01, 0, 0, 0, 0, 0, 0, 0, 
    9.6, 0, 0, 0, 0, 0, 0, 0), Solar = c(0, 0.01, 0, 0, 0, 0.01, 
    0, 0, 0, 1.28, 0, 0.01, 4.88, 0, 0.12, 0, 0, 0, 0, 0, 0, 
    0.04, 0, 0, 0.68, 0, 0, 6.59, 1.11, 0.03, 0, 0, 0, 0.03, 
    0.03, 0, 0.72, 0, 0, 0, 0, 0, 0.01, 0.01, 0.02, 0, 0, 0.01, 
    0, 0, 0.04, 0, 0.02, 0, 0.01, 0, 0.22, 0.05, 0, 0, 0.02, 
    0, 0, 0, 0, 0, 0, 0, 0.01, 0.01, 0, 0.02, 0, 22.95, 0, 0, 
    0.02, 0.01, 0, 0.04, 0, 0, 0, 0.01, 0, 6.06, 0.06, 0, 0, 
    0.03, 0.16, 0, 0, 0.01, 0, 0, 0, 0, 0.02, 0, 0, 0.01, 0, 
    0, 0.05, 0.01, 0, 4.43, 0.03, 0.03, 0.03, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0.01, 0, 0, 0, 0, 0, 0, 0, 0.56, 0.01, 0, 0, 
    0, 0, 0, 0, 0, 4.9, 0.01, 4.05, 0, 0, 0, 0, 0.09, 0.16, 20.67, 
    0, 0, 0, 0.11, 0, 0, 0, 0.05, 0, 0.01, 0, 0, 0, 0.83, 0.01, 
    0.02, 0.02, 0, 0, 0, 0.01, 0, 0, 0, 0, 0, 0.14, 0, 0, 0, 
    0, 0, 0, 0, 1.52, 0, 0, 0, 0, 0, 0, 0, 0.01, 0, 3.9, 0, 0.04, 
    0, 0, 0.14, 0, 6.39, 0, 0, 0, 0, 0.05, 0, 0, 0.42, 0.01, 
    0, 0, 0, 0, 0, 0, 0, 0.01, 0, 0, 3.65, 0, 0, 0.08, 0.02, 
    0, 0.17, 0, 0.01, 0, 0, 0, 0.02, 0, 0, 0, 1.48, 0.08, 0, 
    0, 0, 0, 0.02, 0.02, 0, 0, 0, 2.38, 0, 0, 0.01, 0.01), Wind = c(0, 
    6.15, 0, 0, 0, 0.11, 0, 0.14, 0.01, 27.77, 0, 1.01, 10.87, 
    0, 0.32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.01, 0, 0, 55.43, 7.55, 
    0, 0, 0, 0, 0.64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.49, 0, 2.22, 
    0, 0, 0, 0, 0, 0, 4.07, 0, 0, 0, 0.24, 0.3, 0, 0, 0.02, 0, 
    0, 0, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 5.22, 0, 0, 0.02, 0.08, 
    0, 0, 0, 0, 0, 0, 0, 38.12, 0, 0.05, 0, 0.02, 0.49, 0, 0, 
    6.11, 0.19, 0.15, 0, 0, 1.33, 0, 0, 0, 0, 0, 0.6, 0.02, 0, 
    7.27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.01, 0, 0, 0.2, 0, 0, 0, 
    0.86, 0, 0, 0, 1.29, 0, 0.06, 0, 0, 2.7, 0, 0, 0, 0.72, 2.49, 
    31.96, 0.14, 0, 0.26, 0, 0, 0, 56.44, 0, 0, 0, 0.47, 0, 0, 
    0, 0.13, 0, 0, 0, 5.86, 0, 23.95, 0, 0.06, 0, 0.33, 0, 0.01, 
    0.06, 0.89, 0, 0, 0, 0, 0.75, 0, 0, 0.07, 0.62, 0, 0, 0, 
    3.02, 0, 0, 0, 0, 0, 0, 0.05, 0, 0, 3.55, 0, 4.58, 0, 0.11, 
    0.12, 0, 17.32, 0, 0, 0, 0.11, 0.26, 0.01, 0, 0.67, 0.08, 
    0, 0, 0, 0, 0, 0, 0.05, 0, 0, 0.52, 4.14, 0, 0.27, 33.24, 
    0.04, 0, 0.07, 0, 0, 0, 0, 0, 0.34, 0, 0, 0, 17.78, 0.02, 
    0, 0, 0.06, 0, 0.01, 0, 0.07, 0, 0, 0.33, 0, 0, 0, 0)), row.names = c(NA, 
-250L), class = c("tbl_df", "tbl", "data.frame"))

CodePudding user response:

model1$xlevels gives the variables and levels for the predictors for model1. names gives the variable names. With the summary as a dataframe, you can replace those variable names within the terms column of the summary.

library(tidyverse)
# Summary ast tibble, with terms as column
broom::tidy(model1) %>% 
  mutate(term = stringr::str_replace_all(term, 
                                         # Get variable names
                                         model1$xlevels %>% names() %>%
                                           # Collapse, separated by "|" to replace any occurrences
                                           str_c(., collapse = "|"), 
                                         "") # Replace with blank
         )
  • Related