Interpretate garch(1,1)-results - r

How should I read the results I got from my Garch-model?
Does this mean that none of my external regressors had any impact?
Conditional Variance Dynamics
-----------------------------------
GARCH Model : sGARCH(1,1)
Mean Model : ARFIMA(1,0,0)
Distribution : ghyp
Optimal Parameters
------------------------------------
Estimate Std. Error t value Pr(>|t|)
mu 0.007363 0.005930 1.241772 0.214321
ar1 0.088732 0.031644 2.804059 0.005046
omega 0.000002 0.000004 0.534986 0.592660
alpha1 0.049419 0.015292 3.231603 0.001231
beta1 0.863324 0.006810 126.771068 0.000000
vxreg1 0.000000 0.002269 0.000004 0.999996
vxreg2 0.000000 0.000000 1.724852 0.084554
vxreg3 0.000000 0.000000 0.595820 0.551296
vxreg4 0.000000 0.000317 0.000032 0.999975
vxreg5 0.000000 0.000157 0.000064 0.999949
vxreg6 0.000000 0.000000 0.027500 0.978061
vxreg7 0.000000 0.000000 0.000000 1.000000
vxreg8 0.000000 0.000067 0.000149 0.999881
skew 0.206258 0.233379 0.883791 0.376809
shape 1.882771 0.128208 14.685333 0.000000
ghlambda -0.464969 0.508095 -0.915121 0.360128

Related

How to get all dots in boxplot using ggplot?

I would like to display a boxplot with a dot for each of my data.
Here is my a downsampling of my data:
value value1 value2 value3 value4 value5 value6 value7 value8 value9 value10 value11 value12 value13 value14 value15 value16 value17 value18 value19 value20 value21 value22 value23 value24 value25 value26 value27 value28 value29 value30 value31 value32 value33 value34 value35 value36 value37 value38 value39 value40 value41 value42 value43 value44 value45 value46 value47 value48 value49 value50 value51 value52 value53 value54 value55 value56 value57 value58 value59 value60 value61 value62 value63 value64 value65 value66 value67 value68 value69 value70 value71 value72 value73 value74 value75 value76 value77 value78 value79 value80 value81 value82 value83 value84 value85 value86 value87 value88 value89 value90 value91 value92 value93
1 DLBCL 1994.95631 2621.3410 753.2132 0.000000 11197.10111 0.000000 176.337991 2000.983371 862.402989 8491.35251 0.000000 0.000000 0.000000 0.000000 0.000000 1293.604484 431.201495 11022.058175 6899.22391 1557.191604 0.00000 0.0000000 491.33939 0.00000 935.4880 473.089640 117093.3704 267.06673 0.000000 1201.315893 546.473181 817.685797 5550.213652 5864.340327 0.000000 756.0793 1186.963254 0.000000 0.000000 182.35834 0.000000 0.000000 2.221214e+04 546.4731813 0.000000 22467.36115 25197.16560 4527.61569 47851.49797 0.0000000 809.029514 1780.444881 466.4264055 2854.851275 2178.702289 0.000000 1155.2188880 0.000000 0.000000 0.000000 0.0000000 325.947587 0.000000 0.000000 0.00000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.0000000 0.000000 5219.72808 0.000000 1092.946363 1914.235537 0.00000 41395.343 5012.19294 0.0000 0.00000 0.000000 0.00000 211214.036 771.94114 5792.9344 155407.942 586.647915 904.81625 5221.03431 26527.2485 118750.28 103149.05
2 HL 2685.55082 3282.5779 4598.1600 4183.367213 1465.89302 0.000000 66.245848 0.000000 161.991801 61.34601 161.991801 0.000000 485.975403 404.979503 80.995901 80.995901 161.991801 6164.020846 4211.78683 17549.958130 2601.72383 1143.4715367 1292.08891 2101.51526 8785.9960 157.980575 25628.0113 2257.43413 426.060627 3572.830049 410.593080 11519.416962 23630.893343 47042.419019 2594.830952 5964.8488 3901.738003 0.000000 0.000000 376.79150 0.000000 833.100691 1.251683e+05 3797.9859885 4500.351000 231.24480 901.51959 8990.54496 21686.09505 0.0000000 50.655417 0.000000 5081.5230881 766.069601 8594.091339 4754.510950 578.6497823 0.000000 0.000000 540.128957 5906.6921396 1897.982677 0.000000 0.000000 0.00000 517.142472 0.000000 90.021493 0.000000 0.000000 395.929041 51.1553056 0.000000 5501.47987 569.641498 1180.455105 1258.479657 0.00000 31700.549 8406.06103 650.9810 198.52612 1888.006678 183.67574 130532.228 108.74974 3400.4110 58514.733 4600.624542 1019.75167 0.00000 20734.9505 163994.61 181005.92
3 HL 3937.68099 5174.0505 14309.5447 17201.448539 6027.55676 0.000000 1566.266081 246.848582 9575.025066 966.94533 5745.015039 5106.680035 5745.015039 8298.355057 5745.015039 8936.690061 3830.010026 2595.831304 0.00000 3842.016327 932.01765 0.0000000 0.00000 0.00000 12463.7614 2256.666225 105760.7753 165061.07726 2014.690206 296.397390 808.979015 0.000000 684.694530 0.000000 1120.551505 47009.4381 0.000000 0.000000 0.000000 809.86996 0.000000 6565.731474 1.992851e+03 2831.4265541 0.000000 911.22915 0.00000 0.00000 0.00000 0.0000000 0.000000 0.000000 345.2403404 1811.236269 0.000000 1561.277973 0.0000000 0.000000 736.098023 3192.598806 0.0000000 0.000000 0.000000 0.000000 0.00000 9897.983156 0.000000 3015.232206 0.000000 1210.472305 3120.347631 2015.7947507 0.000000 89720.16482 0.000000 0.000000 0.000000 984.42025 23569.292 794.98586 570.0480 0.00000 0.000000 482.52095 42461.843 571.37679 3573.1872 25446.846 1519.791401 0.00000 0.00000 57004.8004 153509.90 112514.3
and here is my code :
data2=read.table("/../data.txt",sep="\t",header=TRUE )
data2 %>%
ggplot( aes(x=name, y=value, value1, value2, value3, value4, value5, value6, value7, value8, value9, value10, value11, value12, value13, value14, value15, value16, value17, value18, value19, value20, value21, value22, value23, value24, value25, value26, value27, value28, value29, value30, value31, value32, value33, value34, value35, value36, value37, value38, value39, value40, value41, value42, value43, value44, value45, value46, value47, value48, value49, value50, value51, value52, value53, value54, value55, value56, value57, value58, value59, value60, value61, value62, value63, value64, value65, value66, value67, value68, value69, value70, value71, value72, value73, value74, value75, value76, value77, value78, value79, value80, value81, value82, value83, value84, value85, value86, value87, value88, value89, value90, value91, value92, value93, fill=name)) +
geom_boxplot() +
scale_fill_viridis(discrete = TRUE, alpha=0.6) +
geom_jitter(color="black", size=0.4, alpha=0.9) +
theme_ipsum() +
theme(
legend.position="none",
plot.title = element_text(size=11)
) +
ggtitle("Distribution of ... ") +
xlab("")
I got a plot but not all of my data appeared. I suspect only the first column (value) is taken into account.
What did I miss? Does anyone know a trick to get all my dots?
Thanks a lot!
You can try reshaping data to long:
library(ggplot2)
library(dplyr)
library(tidyr)
#Code
data2 %>%
rename(key=value) %>%
pivot_longer(-key) %>%
ggplot(aes(x=key,y=value,fill=name))+
geom_boxplot() +
#scale_fill_viridis(discrete = TRUE, alpha=0.6) +
geom_jitter(color="black", size=0.4, alpha=0.9) +
#theme_ipsum() +
theme(
legend.position="none",
plot.title = element_text(size=11)
) +
ggtitle("Distribution of total EBV gene expression for each PTCL subtype ") +
xlab("")
Output:

Calculationg median of observations in particular set of columns in R

I have an sf object containing the following columns of data:
HR60 HR70 HR80 HR90 HC60 HC70 HC80 HC90
0.000000 0.000000 8.855827 0.000000 0.0000000 0.0000000 0.3333333 0.0000000
0.000000 0.000000 17.208742 15.885624 0.0000000 0.0000000 1.0000000 1.0000000
1.863863 1.915158 3.450775 6.462453 0.3333333 0.3333333 1.0000000 2.0000000
...
How can I calculate the median of HR60 to HR90 columns for all observations and place it in a different column, let's say HR-median? I tried to use apply(), but this kind of works for the whole dataset only and I need only these 4 columns to be considered.
We can select those columns
df1$HR_median <- apply(subset(df1, select = HR60:HR90), 1, median)

How can I calculate the progressive mean in a vector BUT restarting when a condition is met?

Given the following vector,
x<-c(0,0,0,5.0,5.1,5.0,6.5,6.7,6.0,0,0,0,0,3.8,4.0,3.6)
I would like to have a vector with the cumulative mean, like
cumsum(x)/seq_along(x)
but restarting the computation each time that the difference between two subsequent values is grater than 1.3 or less than -1.3. My aim is to obtain a vector like
d<-c(0,0,0,5,5.05,5.03,6.5,6.6,6.37,0,0,0,0,3.8,3.9,3.8)
You can use cumsum(abs(diff(x)) > 1.3)) to define groups, which are used in aggregate to restart cumsum(x)/seq_along(x) each time when the difference is grater than 1.3 or less than -1.3.
unlist(aggregate(x, list(c(0, cumsum(abs(diff(x)) > 1.3))),
function(x) cumsum(x)/seq_along(x))[,2])
# [1] 0.000000 0.000000 0.000000 5.000000 5.050000 5.033333 6.500000 6.600000
# [9] 6.400000 0.000000 0.000000 0.000000 0.000000 3.800000 3.900000 3.800000
Maybe you can try ave + findInterval like below
ave(x,findInterval(seq_along(x),which(abs(diff(x))>1.3)+1),FUN = function(v) cumsum(v)/seq_along(v))
which gives
[1] 0.000000 0.000000 0.000000 5.000000 5.050000 5.033333 6.500000 6.600000
[9] 6.400000 0.000000 0.000000 0.000000 0.000000 3.800000 3.900000 3.800000

How should I interpret the results of function multinom in R?

I have a dataset with five categorical variables. And I ran a multinomial logistic regression with the function multinom in package nnet, and then derived the p values from the coefficients. But I do not know how to interpret the results.
The p values were derived according to UCLA's tutorial: https://stats.idre.ucla.edu/r/dae/multinomial-logistic-regression/ .
Just like this:
z <- summary(test)$coefficients/summary(test)$standard.errors
p <- (1 - pnorm(abs(z), 0, 1)) * 2
p
And I got this:
(Intercept) Age1 Age2 Age3 Age4 Unit1 Unit2 Unit3 Unit4 Unit5 Level1 Level2 Area1 Area2
Not severe 0.7388029 9.094373e-01 0 0.000000e+00 0.000000e+00 0 0.75159758 0 0 0.0000000 0.8977727 0.9333862 0.6285447 0.4457171
Very severe 0.0000000 1.218272e-09 0 6.599380e-06 7.811761e-04 0 0.00000000 0 0 0.0000000 0.7658748 0.6209889 0.0000000 0.0000000
Severe 0.0000000 8.744405e-08 0 1.052835e-06 3.299770e-04 0 0.00000000 0 0 0.0000000 0.8843606 0.4862364 0.0000000 0.0000000
Just so so 0.0000000 1.685045e-07 0 5.507560e-03 2.973261e-06 0 0.08427447 0 NaN 0.3010429 0.5552963 0.7291180 0.0000000 0.0000000
Not severe at all 0.0000000 0.000000e+00 0 0.000000e+00 0.000000e+00 0 NaN NaN 0 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
But how should I interpret these p values? Age3 is significantly related to Very severe? I am green to statistics and have no idea. Help me understand the results please. Thank you in advance.
I suggest using stargazer package to display coefficients and p-values (I believe that it is a more convenient and common way)
Regarding the interpretation of the results, in a multinomial model you can say: keeping all other variables constant, if Age3 is higher by one unit, the log odds for Very Severe relative to the reference category is higher/lower by that amount indicated by the value of the coefficient. The p-value just shows you whether the association between these two variables (predictor and response) is significant or not. Interpretation is the same that of other models.
Note: in case of p-value the null hypothesis is always that the coefficient is equal to zero (no effect at all). When p-value is less than 0.05, you can safely reject the null hypothesis and state that the predictor has an effect on the response variable.
I hope I could give you some hints

lapply and passing arguments

I'm trying to learn how to effectivly use the apply family in R. I have the following numeric vector
>aa
[1] 0.047619 0.000000 NaN 0.000000 0.000000 0.000000 0.000000 0.000000
[9] NaN NaN 0.000000 NaN NaN NaN NaN NaN
[17] 0.000000 0.000000 NaN NaN NaN NaN NaN NaN
[25] NaN 0.100000 0.000000 0.000000 0.000000 0.000000 1.000000 NaN
[33] NaN NaN NaN NaN NaN NaN 0.133333 NaN
[41] NaN 0.000000 0.000000 0.000000 NaN NaN NaN NaN
[49] NaN
and I'm trying to get the n factor out of pwr.t.test with each of these as an input to the d argument.
My attempt(s) have yielded this as the latest result, and frankly, I'm stumped...> lapply(aa,function(x) pwr.t.test(d=x,power=.8,sig.level=.05,type="one.sample",alternative="two.sided"))
with the following error message:
Error in uniroot(function(n) eval(p.body) - power, c(2 + 1e-10, 1e+07)) :
f() values at end points not of opposite sign
Any ideas on the right way to do this?
Short answer: The number of subjects needed is greater than the maximum that R will check for. Add some checks so that you don't run the function when d == 0 and it will work.
When d = 0, you need an infinite number of subjects to detect the difference. The error you are seeing is because R tries to calculate power numerically. The algorithm R uses first checks the bounds of the interval over which the possible values for N lie (about 2 to 1e+07). Because the function for power has the same sign at both endpoints of the interval and is monotonic in N, R throws an error saying that the root (the value of N you are looking for) cannot be found.

Resources