0

I have estimated nested logit in R using the mlogit package. However, I encountered some problems when trying to estimate the marginal effect. Below is the code I implemented.

library(mlogit)

# data
data2 = read.csv(file = "neat_num_energy.csv")
new_ener2 <- mlogit.data(
  data2,
  choice="alter4", shape="long", 
  alt.var="energy_altern",chid.var="id")

# estimate model
nest2 <- mlogit(
  alter4 ~ expendmaint + expendnegy | 
    educ + sex + ppa_power_sp + hu_price_powersupply + 
    hu_2price +hu_3price + hu_9price + hu_10price +
    hu_11price + hu_12price, 
  data = data2, 
  nests = list(
    Trad = c('Biomas_Trad', 'Solar_Trad'), 
    modern = c('Biomas_Modern', 'Solar_Modern')
  ), unscaled=FALSE)


# create Z variable 
z3 <- with(data2, data.frame(
    expendnegy = tapply(expendnegy, idx(nest2,2), mean),
    expendmaint= tapply(expendmaint, idx(nest2,2), mean), 
    educ= mean(educ), 
    sex = mean(sex), 
    hu_price_powersupply = mean(hu_price_powersupply), 
    ppa_power_sp = mean(ppa_power_sp), 
    hu_2price = mean(hu_2price), 
    hu_3price = mean(hu_3price), 
    hu_9price = mean(hu_9price), 
    hu_10price = mean(hu_10price), 
    hu_11price = mean(hu_11price), 
    ppa_power_sp = mean(ppa_power_sp), 
    hu_12price = mean(hu_12price)
))



effects(nest2, covariate = "sex", data = z3, type = "ar")
#> ** Error in Solve.default (H, g[!fixed]): Lapack routine dgesv: #> system is exactly singular:U[6,6] =0.**

My data is in long format with expendmaint and expendnegy being the only alternative specific while every other variable is case specific.

altern4 is a nominal variable representing each alternative

gregmacfarlane
  • 2,121
  • 3
  • 24
  • 53
Hamid
  • 1
  • 1
  • Hi Hamid; it would be helpful to present a minimum working example that illustrates your problem; because we don't have the data, it's impossible to know what exactly you have. That said, system-singular errors are usually created when you have collinearity in your data somewhere. – gregmacfarlane Jan 10 '22 at 14:12
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jan 15 '22 at 14:48

0 Answers0