I am trying to find the bandwidth of a semiparametric panel regression of the form:
x1it = a1 + a2 x2it + a3 x3it + a4 x4it + fei + fet + g(x5it) + uit
where fei and fet are the country and time fixed effects. For that I am using the code:
bw <- npplregbw(x1 ~ x2+ x3+ x4+ effect1 + effect2 + effect3 + effect4 + effect5 + effect6 + effect7 + effect8 + effect9 + effect10 + effect11 + effect12 + effect13 + effect14 + effect15 + effect16 + effect17 + effect18 + effect19|x5, data = mydata, na.action = na.omit)
But when I am running that I am getting the following error:
Error in npregbw.rbandwidth(xdat = xdat, ydat = ydat, bws = tbw, bandwidth.compute = bandwidth.compute) :
number of regression data and response data do not match
I cannot understand what is the problem.
Any help would be appreciated.
Thanks a lot
Related
reg laccidentsvso2 weakban strongban lpop lunemp permale2 lrgastax laccidentmv2 st1-st50 t1-t48 time stt1-stt50 [aweight=pop],cluster(state)
There is no direct equivalent of the Stata regress command in R, but the following code should produce the same results:
library(lmtest)
model1 <- lm(laccidentsvso2 ~ weakban + strongban + lpop + lunemp + permale2 + lrgastax + laccidentmv2 + st1-st50 + t1-t48 + time + stt1-stt50, data = rstata, weights = aweight)
model2 <- lm(laccidentsvso2 ~ weakban + strongban + lpop + lunemp + permale2 + lrgastax + laccidentmv2 + st1-st50 + t1-t48 + time + stt1-stt50 + cluster(state), data = rstata, weights = aweight)
coeftest(model1, model2)
I am running the following code:
mydata1 = data.frame(dataset)
mydata1 <- na.omit(mydata1)
bw <- npplregbw(mydata1$X1 ~ mydata1$X2 + mydata1$X3 + mydata1$X4 + mydata1$effect_1993 + mydata1$effect_1994 + mydata1$effect_1995 + mydata1$effect_1996 + mydata1$effect_1997 + mydata1$country_2 + mydata1$country_3 + mydata1$country_4 + mydata1$country_5 + mydata1$country_6 + mydata1$effect_1998 + mydata1$effect_1999 + mydata1$effect_2000 + mydata1$effect_2001 + mydata1$effect_2002 + mydata1$effect_2003 + mydata1$effect_2004 + mydata1$effect_2005 + mydata1$effect_2006 + mydata1$effect_2007 + mydata1$effect_2008 + mydata1$effect_2009 + mydata1$effect_2010 + mydata1$effect_2011 + mydata1$effect_2012 + mydata1$effect_2013 + mydata1$effect_2014 + mydata1$effect_2015 + mydata1$effect_2016 + mydata1$effect_2017 + mydata1$effect_2018 + mydata1$effect_2019 + mydata1$effect_2020 + mydata1$effect_2021|mydata1$X5 + mydata1$X6 + mydata1$X7 + mydata1$X8, data = mydata1, na.action = na.omit)
summary(bw)
reg_np <- npplreg(bw)
The code is running fine except the last command which gives the following error:
Error in chol.default(t(model.matrix(model)) %*% model.matrix(model)) :
the leading minor of order 4 is not positive definite
My data do not have 0 (except the fixed effects data) or NA values.
Is there any way I can proceed with the npplreg regression without getting that error?
Thanks a lot in advance
How can i find out how many observations were used in a regression?
model_simple <- as.formula("completion_yesno ~ ac + ov + UCRate + FirstWeek + LastWeek + DayofWeekSu + DayofWeekMo + DayofWeekTu + DayofWeekWe + DayofWeekTh + DayofWeekFr + MonthofYearJan + MonthofYearFeb + MonthofYearMar + MonthofYearApr +MonthofYearMay+ MonthofYearJun + MonthofYearJul + MonthofYearAug + MonthofYearSep + MonthofYearOct + MonthofYearNov")
clog_simple1 = glm(model_simple,data=cllw,family = binomial(link = cloglog))
summary(clog_simple1)
I have tried the fitted command which did not result in a concrete number of observations N
Use the built in nobs() function
nobs(clog_simple1)
I'm feeding a new set of data to the Random forest prediction model and encounter this error:
Error in checkData(oldData, RET) :
Classes of new data do not match original data
Here's the code:
fit1 <- cforest((b == 'three')~ affect+ certain+ negemo+ future+swear+sad
+negate+ppron+sexual+death + filler+leisure + conj+ funct + i
+future + past + bio + body+cause + cogmech + death +
discrep + future +incl + motion + quant + sad + tentat + excl+insight +percept +posemo
+ppron +quant + relativ + space + article + age + s_all + s_sad + gender
, data = trainset1,
controls=cforest_unbiased(ntree=500, mtry= 1))
testset2$pre_swl<-predict(fit1, newdata=testset2 , type='response')
Both of the training set and the test set are data.frame.
I have this model and I need to calculate "AIC" to make model selection, my problem is that when I run the model "AIC" appears as "NA".
MODEL= svyglm(formula = Asiste ~ afro + sexo + E27 + JovenActivo + hijos +
jefe + LN_YSVL_sin_joven_prom + aniosed + climaeducativo +
Mdeo + icv2 + TV + Computadora + Telefono + Internet + Cable +
Calefon + DVD + Microhondas + Aire + Auto_o_moto + Secadora +
Madre_ausente + Internet + TV + Lavavajillas + Refrigerador +
climaeducativo + Actividad_del_Jefe + Hacinamiento, family = quasibinomial(link =
"logit"),
data = Personas.con.muestra, design = diseƱo_personas_14_17,
subset = (Stratum != 0))
MODEL$aic
[1] NA
Any suggestion?
Thanks!! Natalia
You can try this:
summary(MODEL)$aic