Issues with GLMM error codes with a fixed effect and a random effect

I am getting error messages when trying to run GLMM models with a Fixed effect|random effect combination, for example..
Model1<-lmer(Stock.Head ~ GDP +(GDP|Area), data=stock

this is the error message..
Error in vcov.merMod(object, use.hessian = use.hessian) :

trying to get slot "factors" from an object of a basic class ("matrix") with no slots

In addition: Warning message:

In vcov.merMod(object, use.hessian = use.hessian) :

Computed variance-covariance matrix problem: not a positive definite matrix;

returning NA matrix

can anyone help with this error code?

Thanks for providing code. Could you kindly take further steps to make it easier for other forum users to help you? Share some representative data that will enable your code to run and show the problematic behaviour.

How do I share data for a reprex?

You might use tools such as the library datapasta, or the base function dput() to share a portion of data in code form, i.e. that can be copied from forum and pasted to R session.

Reprex Guide

1 Like

Sure - here is some data..
data.frame(
Year = c(2010L, 2010L, 2010L, 2010L, 2010L, 2010L),
Stock.Head = c(5673000, 493000, 1747700, 4487838, 5000, 48949744),
GDP = c(14698890000,11926950000,1.61207e+11,
83799480000,1148700000,4.26487e+11),
Area = as.factor(c("Afghanistan",
"Albania","Algeria","Angola","Antigua and Barbuda",
"Argentina"))
)
These are the GLMM models I'm trying to run..
Models - Example :-

Model 1 - Stock ~ GDP

Model 2 - Stock ~ GDP + (GDP|Area)

Model 3 - Stock ~ GDP + (GDP|Area) + (Year|Area)

Model 4 - Stock ~ GDP + (Year|Area)

Model 5 - (GDP|Area) + (Year|Area)

Model 6 - Stock ~1 + (GDP|Area) + (Year|Area)

Model 7 - Stock~1 + (Year|Area)

Model 1 - I'm using lm command and it's fine...
Model 2-7 using lmer command...
it's only Model 1, 4 and 7 that work

example this works..
Q1glmm4<-lmer(Stock.Head ~ GDP + (Year|Area), data=STOCK.VS.GDP.GLMM)
this doesn't work..
Q1glmm2<-lmer(Stock.Head ~ GDP +(GDP|Area), data=STOCK.VS.GDP.GLMM)
it's the random effect (GDP|Area) that doesn't run..
this is the error message
Error in vcov.merMod(object, use.hessian = use.hessian) :
trying to get slot "factors" from an object of a basic class ("matrix") with no slots
In addition: Warning message:
In vcov.merMod(object, use.hessian = use.hessian) :
Computed variance-covariance matrix problem: not a positive definite matrix;
returning NA matrix

sorry I can't help as your example doesn't have enough data to reproduce your example of a correctly running lmer; and the one you say doesn't work gives the same error

Error: number of levels of each grouping factor must be < number of observations (problems: Area)

perhaps you could provide enough data so that

Q1glmm4<-lmer(Stock.Head ~ GDP + (Year|Area), data=STOCK.VS.GDP.GLMM)

would run

should I attach the whole dataset? It's approx 2000 lines of data in an Excel csv file

would it not work to pick only a few years of interest and a few Areas ?

structure(list(Area = structure(3:22, levels = c("C\xf4te d'Ivoire",
"T\xfcrkiye", "Afghanistan", "Albania", "Algeria", "Angola",
"Antigua and Barbuda", "Argentina", "Armenia", "Australia", "Austria",
"Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados",
"Belarus", "Belgium", "Belize", "Benin", "Bhutan", "Bolivia (Plurinational State of)",
"Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei Darussalam",
"Bulgaria", "Burkina Faso", "Burundi", "Cabo Verde", "Cambodia",
"Cameroon", "Canada", "Central African Republic", "Chad", "Chile",
"China", "China, Hong Kong SAR", "China, mainland", "Colombia",
"Comoros", "Congo", "Cook Islands", "Costa Rica", "Croatia",
"Cuba", "Cyprus", "Czechia", "Democratic People's Republic of Korea",
"Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica",
"Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea",
"Eritrea", "Estonia", "Eswatini", "Ethiopia", "Fiji", "Finland",
"France", "French Polynesia", "Gabon", "Gambia", "Georgia", "Germany",
"Ghana", "Greece", "Grenada", "Guatemala", "Guinea", "Guinea-Bissau",
"Guyana", "Haiti", "Honduras", "Hungary", "Iceland", "India",
"Indonesia", "Iran (Islamic Republic of)", "Iraq", "Ireland",
"Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan",
"Kenya", "Kuwait", "Kyrgyzstan", "Lao People's Democratic Republic",
"Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Lithuania",
"Luxembourg", "Madagascar", "Malawi", "Malaysia", "Mali", "Malta",
"Mauritania", "Mauritius", "Mexico", "Micronesia (Federated States of)",
"Mongolia", "Montenegro", "Morocco", "Mozambique", "Myanmar",
"Namibia", "Nepal", "Netherlands", "New Caledonia", "New Zealand",
"Nicaragua", "Niger", "Nigeria", "North Macedonia", "Norway",
"Oman", "Pakistan", "Palestine", "Panama", "Papua New Guinea",
"Paraguay", "Peru", "Philippines", "Poland", "Portugal", "Puerto Rico",
"Qatar", "Republic of Korea", "Republic of Moldova", "Romania",
"Russian Federation", "Rwanda", "Saint Kitts and Nevis", "Saint Lucia",
"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 Sudan", "Spain", "Sri Lanka", "Sudan",
"Sudan (former)", "Suriname", "Sweden", "Switzerland", "Syrian Arab Republic",
"Tajikistan", "Thailand", "Timor-Leste", "Togo", "Tonga", "Trinidad and Tobago",
"Tunisia", "Turkmenistan", "Uganda", "Ukraine", "United Arab Emirates",
"United Kingdom of Great Britain and Northern Ireland", "United Republic of Tanzania",
"United States of America", "Uruguay", "Uzbekistan", "Vanuatu",
"Venezuela (Bolivarian Republic of)", "Viet Nam", "Yemen", "Zambia",
"Zimbabwe"), class = "factor"), Year = c(2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L), Stock.Head = c(5673000,
493000, 1747700, 4487838, 5000, 48949744, 570633, 26733000, 2026260,
2299700, 750, 10000, 23051000, 11000, 4151000, 2593000, 92670,
2005000, 352841, 8189786), GDP = c(14698890000, 11926950000,
1.61207e+11, 83799480000, 1148700000, 4.26487e+11, 9875380000,
1.29946e+12, 3.91893e+11, 5.2906e+10, 10095800000, 25713270000,
1.14508e+11, 4529930000, 57231910000, 4.80952e+11, 1387930000,
6970250000, 1547980000, 19649790000), X = structure(c(1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L), levels = c("", "checked"), class = "factor")), row.names = c(NA,
20L), class = "data.frame")

is this OK? its the first 20 lines using dput to extract it

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.