I am using Aparch/Garch model (library: "fGarch") and want to read (& use later) the objects like AIC, t-values of the coefficients in the summary of the model fit. How can I do this?
m3<-(garchFit(~arma(1,0)+aparch(1,1), cond.dist= "sged" ,data=t2, trace=FALSE))
summary(m3)
Title:
GARCH Modelling
Call:
garchFit(formula = ~arma(1, 0) + aparch(1, 1), data = t2, cond.dist = "sged",
trace = FALSE)
Mean and Variance Equation:
data ~ arma(1, 0) + aparch(1, 1)
[data = t2]
Conditional Distribution:
sged
Coefficient(s):
mu ar1 omega alpha1 gamma1 beta1 delta skew shape
0.00063936 0.07745422 0.00116542 0.24170185 0.19179650 0.74430731 1.11902269 1.06401615 1.23013925
Std. Errors:
based on Hessian
Error Analysis:
Estimate Std. Error t value Pr(>|t|)
mu 0.0006394 0.0004789 1.335 0.181828
ar1 0.0774542 0.0256070 3.025 0.002489 **
omega 0.0011654 0.0003097 3.763 0.000168 ***
alpha1 0.2417019 0.0368264 6.563 5.26e-11 ***
gamma1 0.1917965 0.0699436 2.742 0.006104 **
beta1 0.7443073 0.0383066 19.430 < 2e-16 ***
delta 1.1190227 0.2569665 4.355 1.33e-05 ***
skew 1.0640162 0.0295095 36.057 < 2e-16 ***
shape 1.2301392 0.0592616 20.758 < 2e-16 ***
Information Criterion Statistics:
AIC BIC SIC HQIC
-4.835325 -4.803583 -4.835395 -4.823503
I think you'll have to extract those from the output of garchFit, not its summary. Start by looking at:
> attributes(m3)
Then you can access something like $fit$tval by doing
> m3#fit$tval
Related
I estimate a heckit-model using the heckit-model from sampleSelection.
The model looks as follows:
library(sampleSelection) Heckman = heckit(AgencyTRACE ~ SizeCat + log(Amt_Issued) + log(daysfromissuance) + log(daystomaturity) + EoW + dMon + EoM + VIX_95_Dummy + quarter, Avg_Spread_Choi ~ SizeCat + log(Amt_Issued) + log(daysfromissuance) + log(daystomaturity) + VIX_95_Dummy + TresholdHYIG_II, data=heckmandata, method = "2step")
The summary generates a probit selection equation and an outcome equation - see below:
Tobit 2 model (sample selection model)
2-step Heckman / heckit estimation
2019085 observations (1915401 censored and 103684 observed)
26 free parameters (df = 2019060)
Probit selection equation:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.038164 0.043275 0.882 0.378
SizeCat2 0.201571 0.003378 59.672 < 2e-16 ***
SizeCat3 0.318331 0.008436 37.733 < 2e-16 ***
log(Amt_Issued) -0.099472 0.001825 -54.496 < 2e-16 ***
log(daysfromissuance) 0.079691 0.001606 49.613 < 2e-16 ***
log(daystomaturity) -0.036434 0.001514 -24.066 < 2e-16 ***
EoW 0.021169 0.003945 5.366 8.04e-08 ***
dMon -0.003409 0.003852 -0.885 0.376
EoM 0.008937 0.007000 1.277 0.202
VIX_95_Dummy1 0.088558 0.006521 13.580 < 2e-16 ***
quarter2019.2 -0.092681 0.005202 -17.817 < 2e-16 ***
quarter2019.3 -0.117021 0.005182 -22.581 < 2e-16 ***
quarter2019.4 -0.059833 0.005253 -11.389 < 2e-16 ***
quarter2020.1 -0.005230 0.004943 -1.058 0.290
quarter2020.2 0.073175 0.005080 14.406 < 2e-16 ***
Outcome equation:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 46.29436 6.26019 7.395 1.41e-13 ***
SizeCat2 -25.63433 0.79836 -32.109 < 2e-16 ***
SizeCat3 -34.25275 1.48030 -23.139 < 2e-16 ***
log(Amt_Issued) -0.38051 0.39506 -0.963 0.33547
log(daysfromissuance) 0.02452 0.34197 0.072 0.94283
log(daystomaturity) 7.92338 0.24498 32.343 < 2e-16 ***
VIX_95_Dummy1 -2.34875 0.89133 -2.635 0.00841 **
TresholdHYIG_II1 10.36993 1.07267 9.667 < 2e-16 ***
Multiple R-Squared:0.0406, Adjusted R-Squared:0.0405
Error terms:
Estimate Std. Error t value Pr(>|t|)
invMillsRatio -23.8204 3.6910 -6.454 1.09e-10 ***
sigma 68.5011 NA NA NA
rho -0.3477 NA NA NA
Now I'd like to estimate a value using the outcome equation. I'd like to predict Spread_Choi_All using the following data:
newdata = data.frame(SizeCat=as.factor(1),
Amt_Issued=50*1000000,
daysfromissuance=5*365,
daystomaturity=5*365,
VIX_95_Dummy=as.factor(0),
TresholdHYIG_II=as.factor(0)
SizeCat is a categorical/factor variable with the value 1, 2 or 3.
I have tried varies ways, i.e.
predict(Heckman, part ="outcome", newdata = newdata)
I aim to predict a value (with the data from newdata) using the outcome equation (incl. the invMillsRatio). Is there a way how to predict a value from the outcome equation?
I have a question about Poisson GLM and formula representation:
Considering a data set:
p <- read.csv("https://raw.githubusercontent.com/Leprechault/PEN-533/master/bradysia-greenhouse.csv")
Without considering the interaction:
m1 <- glm(bradysia ~ area + mes, family="quasipoisson", data=p)
summary(m1)
#(Intercept) 4.36395 0.12925 33.765 < 2e-16 ***
#areaCV -0.19696 0.12425 -1.585 0.113
#areaMJC -0.71543 0.08553 -8.364 3.11e-16 ***
#mes -0.08872 0.01970 -4.503 7.82e-06 ***
The final formula is: bradysia = exp(4.36395*CS-0.19696*CV-0.71543-0.08872*mes)
Considering the interaction:
m2 <- glm(bradysia ~ area*mes, family="quasipoisson", data=p)
summary(m2)
#(Intercept) 4.05682 0.15468 26.227 < 2e-16 ***
#areaCV 0.15671 0.35219 0.445 0.6565
#areaMJC 0.54132 0.31215 1.734 0.0833 .
#mes -0.03943 0.02346 -1.680 0.0933 .
#areaCV:mes -0.05724 0.05579 -1.026 0.3052
#areaMJC:mes -0.22609 0.05576 -4.055 5.57e-05 **
The final formula is: bradysia = exp(?????) and any help, please?
When I run logistic regression and use predict() function and when I manually calculate with formula p=1/(1+e^-(b0+b1*x1...)) I cannot get the same answer. What could be the reason?
>test[1,]
loan_status loan_Amount interest_rate period sector sex age grade
10000 0 608 41.72451 12 Online Shop Female 44 D3
sector and period was insignificant so I removed it from the regression.
glm gives:
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -1.1542256 0.7610472 -1.517 0.12936
interest_rate -0.0479765 0.0043415 -11.051 < 2e-16 ***
sexMale -0.8814945 0.0656296 -13.431 < 2e-16 ***
age -0.0139100 0.0035193 -3.953 7.73e-05 ***
gradeB 0.3209587 0.8238955 0.390 0.69686
gradeC1 -0.7113279 0.8728260 -0.815 0.41509
gradeC2 -0.4730014 0.8427544 -0.561 0.57462
gradeC3 0.0007541 0.7887911 0.001 0.99924
gradeD1 0.5637668 0.7597531 0.742 0.45806
gradeD2 1.3207785 0.7355950 1.796 0.07257 .
gradeD3 0.9201400 0.7303779 1.260 0.20774
gradeE1 1.7245351 0.7208260 2.392 0.01674 *
gradeE2 2.1547773 0.7242669 2.975 0.00293 **
gradeE3 3.1163245 0.7142881 4.363 1.28e-05 ***
>predictions_1st <- predict(Final_Model, newdata = test[1,], type = "response")
>predictions_1st
answer: **0.05478904**
But when I calculate like this:
>prob_1 <- 1/(1+e^-((-0.0479764603)*41.72451)-0.0139099563*44)
>prob_1
answer: 0.09081154
I calculated also with insignificant coefficients but answer still is not the same. What could be the reason?
You have also an (Intercept) -1.1542256 and a gradeD3 0.9201400
1/(1+exp(-1*(-1.1542256 -0.0479764603*41.72451 -0.0139099563*44 + 0.9201400)))
#[1] 0.05478904
I have a list named "mylist" that contains gam outputs. Summary of the first list is the following:
> summary(mylist[[1]][[1]])
Family: quasipoisson
Link function: log
Formula:
cardva ~ s(trend, k = 11 * 6, fx = T, bs = "cr") + s(temp_01, k = 6, fx = F, bs = "cr") + rh_01 + as.factor(dow) + s(fluepi, k = 4, fx = F, bs = "cr") + as.factor(holiday) + Lag(pm1010, 0)
Parametric coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.1584139 0.0331388 95.309 < 2e-16 ***
rh_01 0.0005441 0.0004024 1.352 0.17639
as.factor(dow)2 0.0356757 0.0127979 2.788 0.00533 **
as.factor(dow)3 0.0388823 0.0128057 3.036 0.00241 **
as.factor(dow)4 0.0107302 0.0129014 0.832 0.40561
as.factor(dow)5 0.0243382 0.0128705 1.891 0.05867 .
as.factor(dow)6 0.0277954 0.0128360 2.165 0.03040 *
as.factor(dow)7 0.0275593 0.0127373 2.164 0.03053 *
as.factor(holiday)1 0.0444349 0.0147219 3.018 0.00255 **
Lag(pm1010, 0) -0.0010816 0.0042891 -0.252 0.80091
After unlisting the list I have extracted the coefficients of the linear terms for the first list:
> head(plist)
[[1]]
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.1584139271 0.0331388386 95.3085280 0.000000000
rh_01 0.0005441175 0.0004024202 1.3521128 0.176392590
as.factor(dow)2 0.0356757100 0.0127979429 2.7876128 0.005327293
as.factor(dow)3 0.0388823055 0.0128056733 3.0363343 0.002405504
as.factor(dow)4 0.0107302325 0.0129013816 0.8317119 0.405606249
as.factor(dow)5 0.0243382447 0.0128704711 1.8910143 0.058672841
as.factor(dow)6 0.0277953708 0.0128359850 2.1654256 0.030396240
as.factor(dow)7 0.0275592574 0.0127372874 2.1636677 0.030531063
as.factor(holiday)1 0.0444348611 0.0147218816 3.0182868 0.002553265
Lag(pm1010, 0) -0.0010816252 0.0042890866 -0.2521808 0.800910389
My question is: it possible to include the names of the dependent variable (in this example cardiac) as part of the plist?
What I want to achieve is (output deliberately reduced)
cardva Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.1584139271 0.0331388386 95.3085280 0.000000000
rh_01 0.0005441175 0.0004024202 1.3521128 0.176392590
as.factor(dow)2 0.0356757100 0.0127979429 2.7876128 0.005327293
or
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.1584139271 0.0331388386 95.3085280 0.000000000
rh_01 0.0005441175 0.0004024202 1.3521128 0.176392590
as.factor(dow)7 0.0275592574 0.0127372874 2.1636677 0.030531063
as.factor(holiday)1 0.0444348611 0.0147218816 3.0182868 0.002553265
cardva_Lag(pm1010, 0) -0.0010816252 0.0042890866 -0.2521808 0.800910389
Two options: Name the nodes of the list so they would then be printed as:
names(plist)[1] <- 'cardva'
plist[1]
$cardva
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.1584139271 0.0331388386 95.3085280 0.000000000
rh_01 0.0005441175 0.0004024202 1.3521128 0.176392590
as.factor(dow)2 0.0356757100 0.0127979429 2.7876128 0.005327293
as.factor(dow)3 0.0388823055 0.0128056733 3.0363343 0.002405504
as.factor(dow)4 0.0107302325 0.0129013816 0.8317119 0.405606249
as.factor(dow)5 0.0243382447 0.0128704711 1.8910143 0.058672841
as.factor(dow)6 0.0277953708 0.0128359850 2.1654256 0.030396240
as.factor(dow)7 0.0275592574 0.0127372874 2.1636677 0.030531063
as.factor(holiday)1 0.0444348611 0.0147218816 3.0182868 0.002553265
Lag(pm1010, 0) -0.0010816252 0.0042890866 -0.2521808 0.800910389
Or:
temp <- plist[[1]]
rownames(temp)[nrow(temp)] <- paste0( "cardva_", rownames(temp)[nrow(temp)] )
I'm trying to fit inflated beta regression model to proportional data. I'm using the package gamlss and specifing the family BEINF. I'm wondering how I can extract the p-values of the $mu.coefficients. When I typed the command fit.3$mu.coefficients (as shown at the bottom of the my r code), it gave me only the estimates of Mu coefficients. The following is an example of my data.
mydata = data.frame(y = c(0.014931087, 0.003880983, 0.006048048, 0.014931087,
+ 0.016469269, 0.013111447, 0.012715517, 0.007981377), index = c(1,1,2,2,3,3,4,4))
mydata
y index
1 0.004517611 1
2 0.004351405 1
3 0.007952064 2
4 0.004517611 2
5 0.003434018 3
6 0.003602046 4
7 0.002370690 4
8 0.002993016 4
> library(gamlss)
> fit.3 = gamlss(y ~ factor(index), family = BEINF, data = mydata)
> summary(fit.3)
*******************************************************************
Family: c("BEINF", "Beta Inflated")
Call:
gamlss(formula = y ~ factor(index), family = BEINF, data = mydata)
Fitting method: RS()
-------------------------------------------------------------------
Mu link function: logit
Mu Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -5.3994 0.1204 -44.858 1.477e-06
factor(index)2 0.2995 0.1591 1.883 1.329e-01
factor(index)3 -0.2288 0.1805 -1.267 2.739e-01
factor(index)4 -0.5017 0.1952 -2.570 6.197e-02
-------------------------------------------------------------------
Sigma link function: logit
Sigma Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -4.456 0.2514 -17.72 4.492e-07
-------------------------------------------------------------------
Nu link function: log
Nu Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -21.54 10194 -0.002113 0.9984
-------------------------------------------------------------------
Tau link function: log
Tau Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -21.63 10666 -0.002028 0.9984
-------------------------------------------------------------------
No. of observations in the fit: 8
Degrees of Freedom for the fit: 7
Residual Deg. of Freedom: 1
at cycle: 12
Global Deviance: -93.08548
AIC: -79.08548
SBC: -78.52938
*******************************************************************
fit.3$mu.coefficients
(Intercept) factor(index)2 factor(index)3 factor(index)4
-5.3994238 0.2994738 -0.2287571 -0.5016511
I really appreciate all your help.
Use the save option in summary.gamlss, like this for your model above
fit.3 = gamlss(y ~ factor(index), family = BEINF, data = mydata)
sfit.3<-summary(fit.3, save=TRUE)
sfit.3$mu.coef.table
sfit.3$sigma.coef.table
#to get a list of all the slots in the object
str(sfit.3)
fit.3 = gamlss(y ~ factor(index), family = BEINF, data = mydata.ex)
sfit.3<-summary(fit.3, save=TRUE)
fit.3$mu.coefficients
sfit.3$coef.table # Here use Brackets []
estimate.pval<-data.frame(Intercept=sfit.3$coef.table[1,1],pvalue=sfit.3$coef.table[1,4],
"factor(index)^2"=sfit.3$coef.table[2,1] ,pvalue=sfit.3$coef.table[2,4],
"factor(index)^3"=sfit.3$coef.table[3,1] ,pvalue=sfit.3$coef.table[3,4],
"factor(index)^4"=sfit.3$coef.table[4,1] ,pvalue=sfit.3$coef.table[4,4])