Help - export full results

Hello,
i'm a beginner and not able to export the full result of a command.
I'm trying to estimate an Ro of the current epidemic.
So, here an example
library(R0)
epid.count = c(1,1,4,5,8,12,27,38,43,52,66,100)
GT.x <- generation.time("gamma", c(2,1.5))
res.R <- estimate.R(epid.count, GT=GT.x, methods=c("EG","ML","SB","TD"))
print(res.R)

At this point I'm not able to see all the results.
Reproduction number estimate using Exponential Growth method.
R : 2.287246[ 2.086577 , 2.512827 ]

Reproduction number estimate using Maximum Likelihood method.
R : 1.885677[ 1.622073 , 2.176419 ]

Reproduction number estimate using Time-Dependent method.
3.486779 3.811135 2.458036 2.446274 2.48364 2.521225 1.95077 1.647686 1.631888 1.721446 ...Here Stops

Reproduction number estimate using Sequential Bayesian method.
1 3.05 2.14 2.1 2.02 2.36 2.1 1.81 1.7 1.66 ... Here Stops

I tried to export the results but I can see only wht is already displayed in the Console:
cat("Tests Output", file = "tests.txt")
capture.output(res.R, file = "tests.txt", append = TRUE)

Thanks for your help!

The documentation for estimate.R says the results for each method are stored in the estimates component of res.R. You can see the structure of that by running

str(res.R$estimates)

If res.R$estimates is a data frame, you can see the results with

View(res.R$estimates)

If res.R$estimates is itself a list then I would guess that the result of each method is stored with a name related to the method, maybe res.R$estimates$EG for exponential growth. So, start with the str() function I mentioned and post the results here if you get stuck.

This is the result of using str(res.R$estimates) for the time-dipendent method (TD).
It actually shows the results but still without the full serie of R (in my example 12).

> str(res.R$estimates$TD)
List of 16

  • $ R : Named num [1:12] 3.49 3.81 2.46 2.45 2.48 ...*
  • ..- attr(, "names")= chr [1:12] "1" "2" "3" "4" ...
  • $ conf.int :'data.frame': 12 obs. of 2 variables:*
  • ..$ lower: num [1:12] 1 1 1.25 1.4 1.64 ...*
  • ..$ upper: num [1:12] 6 7 3.76 3.61 3.4 ...*
  • $ P : num [1:12, 1:12] 0 0 0 0 0 0 0 0 0 0 ...*
  • $ p : num [1:12, 1:12] 0 0 0 0 0 0 0 0 0 0 ...*
  • $ GT :List of 4*
  • ..$ GT : num [1:14] 0 0.3905 0.2855 0.1626 0.0841 ...*
  • ..$ time: int [1:14] 0 1 2 3 4 5 6 7 8 9 ...*
  • ..$ mean: num 2.24*
  • ..$ sd : num 1.45*
  • ..- attr(, "class")= chr "R0.GT"
  • $ epid :List of 2*
  • ..$ incid: num [1:12] 1 1 4 5 8 12 27 38 43 52 ...*
  • ..$ t : num [1:12] 1 2 3 4 5 6 7 8 9 10 ...*
  • $ import : num [1:12] 0 0 0 0 0 0 0 0 0 0 ...*
  • $ pred : num [1:12] 1 1.36 2.48 5.49 8.5 ...*
  • $ begin : num 1*
  • $ begin.nb : int 1*
  • $ end : int(0) *
  • $ end.nb : int 12*
  • $ data.name : chr "c(1, 1, 4, 5, 8, 12, 27, 38, 43, 52, 66, 100)"*
  • $ call : language est.R0.TD(epid = c(1, 1, 4, 5, 8, 12, 27, 38, 43, 52, 66, 100), GT = list(GT = c(0, 0.39053614575831, 0.285454662| truncated ...*
  • $ method : chr "Time-Dependent"*
  • $ method.code: chr "TD"*
    • attr(, "class")= chr "R0.R"

While View(res.R$estimates$TD) report the following error:
Error in as.data.frame.default(x) : cannot coerce class ‘"R0.R"’ to a data.frame

I should have suggested that you try

summary(res.R)

to get your information. If that does not work, then I don't have anything else to suggest other than extracting individual parts of objects like res.R$estimates$TD. I am sorry I can't suggest anything more specific. I am not familiar with this package.

1 Like

I find the solution.
Typing:

summary(res.R$estimates$TD)
Length Class Mode
R 12 -none- numeric
conf.int 2 data.frame list
P 144 -none- numeric
p 144 -none- numeric
GT 4 R0.GT list
epid 2 -none- list
import 12 -none- numeric
pred 12 -none- numeric
begin 1 -none- numeric
begin.nb 1 -none- numeric
end 0 -none- numeric
end.nb 1 -none- numeric
data.name 1 -none- character
call 9 -none- call
method 1 -none- character
method.code 1 -none- character

Then using list it shows the full serie of R anc confindent interval

list(res.R$estimates$TD$R)
[[1]]
1 2 3 4 5 6 7 8
3.486779 3.811135 2.458036 2.446274 2.483640 2.521225 1.950770 1.647686
9 10 11 12
1.631888 1.721446 1.913671 0.000000

list(res.R$estimates$TD$conf.int)
[[1]]
lower upper
1 1.000234 6.001405
2 1.000604 7.004231
3 1.251801 3.755404
4 1.404649 3.611953
5 1.637209 3.400357
6 1.862050 3.219928
7 1.536986 2.382329
8 1.312000 1.996522
9 1.303383 1.968940
10 1.393965 2.048987
11 1.551868 2.289006
12 0.000000 0.000000

Thanks for your help, I really appreciate it!
Giovanni

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.