I am using Rmarkdown and Kniter in Rstudio to make MS Word document. However, my results are from MSM package. This is my code in the .rmd sript:
knitr::kable(pmatrix.msm(xdata.msm),caption = "Transition probability matrix.")
I am getting this error:
Error in as.data.frame.default(x) :
cannot coerce class ""msm.est"" to a data.frame
Calls: <Anonymous> ... format_args -> as.data.frame -> as.data.frame.default
How do I nicely print the MSM model results in Word. Please help me to solve. this.
Update:
Conversion to dataframe gives: Error in as.data.frame.default(x[[i]], optional = TRUE) : cannot coerce class ""msm.est"" to a data.frame.
I need to add caption to pmatrix.msm(xdata.msm)
.
This is my msm object:
dput(xdata.msm)
structure(c(0.867104394602623, 0.0297597288741373, 0.0111688422294673,
0.0436200880979502, 0.937379027520689, 0.0642139547902726, 0.0892755172994266,
0.0328612436051735, 0.92461720298026), .Dim = c(3L, 3L), .Dimnames = list(
c("State 1", "State 2", "State 3"), c("State 1", "State 2",
"State 3")), class = "msm.est")
Update: as.data.frame.matrix()
works for some but not for all. please see this object:
dput(pnext.msm(xdata.msm))
structure(list(estimates = structure(c(0, 0.493157008697057,
0.141450173196988, 0.312417736561033, 0, 0.858549826803012, 0.687582263438967,
0.506842991302943, 0), .Dim = c(3L, 3L), .Dimnames = list(c("State 1",
"State 2", "State 3"), c("State 1", "State 2", "State 3"))),
L = structure(c(0, 0.404769718769504, 0.0851255671695353,
0.229501053449466, 0, 0.775032294188692, 0.599692174664181,
0.416275351504334, 0), .Dim = c(3L, 3L)), U = structure(c(0,
0.583724648495666, 0.224967705811308, 0.400307825335819,
0, 0.914874432830465, 0.770498946550534, 0.595230281230496,
0), .Dim = c(3L, 3L))), .Names = c("estimates", "L", "U"), class = "msm.est")
Warning in seq_len(ncols) : first element used of 'length.out' argument
Error in seq_len(ncols) :
argument must be coercible to non-negative integer