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)] )
Related
I understand from this question here that coefficients are the same whether we use a lm regression with as.factor() and a plm regression with fixed effects.
N <- 10000
df <- data.frame(a = rnorm(N), b = rnorm(N),
region = rep(1:100, each = 100), year = rep(1:100, 100))
df$y <- 2 * df$a - 1.5 * df$b + rnorm(N)
model.a <- lm(y ~ a + b + factor(year) + factor(region), data = df)
summary(model.a)
# (Intercept) -0.0522691 0.1422052 -0.368 0.7132
# a 1.9982165 0.0101501 196.866 <2e-16 ***
# b -1.4787359 0.0101666 -145.450 <2e-16 ***
library(plm)
pdf <- pdata.frame(df, index = c("region", "year"))
model.b <- plm(y ~ a + b, data = pdf, model = "within", effect = "twoways")
summary(model.b)
# Coefficients :
# Estimate Std. Error t-value Pr(>|t|)
# a 1.998217 0.010150 196.87 < 2.2e-16 ***
# b -1.478736 0.010167 -145.45 < 2.2e-16 ***
library(lfe)
model.c <- felm(y ~ a + b | factor(region) + factor(year), data = df)
summary(model.c)
# Coefficients:
# Estimate Std. Error t value Pr(>|t|)
# a 1.99822 0.01015 196.9 <2e-16 ***
# b -1.47874 0.01017 -145.4 <2e-16 ***
However, the R and R-squared differ significantly. Which one is correct and how does the interpretation changes between the two models? In my case, the R-squared is much larger for the plm specification and is even negative for the lm + factor one.
I am desperately trying to plot a Johnson-Neyman Plot for the following interaction:
nxsc_20 <-lm(meandec20 ~ centered_nep*centered_selfcontrol + factor(study), data = allstudies_wide)
I get the following output:
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.28264 0.02260 12.508 < 2e-16 ***
centered_nep 0.08998 0.01192 7.551 7.41e-14 ***
centered_selfcontrol 0.01894 0.01021 1.856 0.06364 .
factor(study)2 0.03462 0.02531 1.368 0.17146
factor(study)3 0.35767 0.02635 13.573 < 2e-16 ***
factor(study)4 0.33224 0.03709 8.956 < 2e-16 ***
centered_nep:centered_selfcontrol 0.03706 0.01300 2.850 0.00443 **
Now I try to make a JN-Plot
johnson_neyman(nxsc_20, meandec20, centered_selfcontrol, alpha = 0.05, plot = TRUE)
and I get the following error:
Fehler in vmat[pred, pred] : Indizierung außerhalb der Grenzen (Error in vmat[pred, pred] : indexing out of range)
Can anybody help me with this?
Thank you so much!
The pred = option is not for the response variable but for the predictor you want to plot on the y-axis. This will work:
library(interactions)
allstudies_wide = data.frame(meandec20=rnorm(500),centered_nep = runif(500),
centered_selfcontrol = runif(500), study = sample(1:4,500,replace=TRUE))
nxsc_20 <-lm(meandec20 ~ centered_nep*centered_selfcontrol + factor(study),
data = allstudies_wide)
johnson_neyman(model = nxsc_20, pred = centered_nep,modx = centered_selfcontrol)
I made this nls model
formula1 <- nls(y ~ a+(x/500)^b, data=my_data, start =list(a=1, b=1))
Then I got the result below,
summary(formula)
Parameters:
Estimate Std. Error t value Pr(>|t|)
a -0.5578576 0.2335056 -2.389 0.0251 *
b 0.9424152 0.0004498 2095.239 <2e-16 ***
But I want to change the "a", "b" to "0.02", "0.9", so I've changed my formula like this and got this error message ;
formula2 <- nls(y ~ 0.02+(x/500)^0.9, data=my_data)
Error in getInitial.default(func, data, mCall = as.list(match.call(func, : # no 'getInitial' method found for "function" objects
And I changed the start value as 'a=0,02, b=0.9', but the 'estimate value' is same as formula1 ;
formula2 <- nls(y ~ a+(x/500)^b, data=my_data, start =list(a=0.02, b=0.9))
summary(formula2)
Parameters:
Estimate Std. Error t value Pr(>|t|)
a -0.5578576 0.2335056 -2.389 0.0251 *
b 0.9424152 0.0004498 2095.239 <2e-16 ***
Please let me know how can I make nls formula with fixed start value. Thanks. :)
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])
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