empirical t-values with bootsempls in R, transform console output to vector

205 views Asked by At

If I run bootsempls() function of the semPLS package in R, I get an object of class "bootsempls", "boot", lets name the object "mymodel_boot".

If I run

>mymodel_boot

         Estimate      Bias Std.Error Lower Upper
lam_1_1     0.923 -0.000188   0.01400 0.892 0.946
lam_1_2     0.918 -0.000971   0.01778 0.876 0.945
lam_2_1     0.860 -0.001325   0.02647 0.799 0.903
lam_2_2     0.897  0.000579   0.01604 0.864 0.926
lam_2_3     0.799 -0.000253   0.03476 0.723 0.859
lam_3_1     0.793 -0.003462   0.06742 0.636 0.897
lam_3_2     0.942  0.001877   0.00892 0.927 0.963
beta_1_3    0.429  0.003359   0.07722 0.280 0.579
beta_2_3    0.294 -0.000880   0.07339 0.147 0.435

I get the table above.

To compute t-values, I now want to divide the original coefficients by the corresponding standard error.

The original coefficients can be targeted by

> mymodel_boot$t0
[1] 0.9227120 0.9180390 0.8599884 0.8973823 0.7993398 0.7927142 0.9424423 0.4292315 0.2941801

Is there any way to target the Std.Error like that, which is printed in the previous codeblock, so I could just divide these and get a vector of t-values?

I have read the help page of bootsempls, but can't find a component that returns only the Std.Err and now I am confused, because I thought its a common procedure to estimate t-values and there is no smarter way than to copy paste each Std.Err from the console? I can't believe that.

If the Std.Err can't be targeted through the $ operator, is there any way I can transform the Std.Err column in the console output into a vector?

1

There are 1 answers

3
David Arenburg On BEST ANSWER

Good question. The usual way is to use attributes and str in order to find such attributes in unknown classes (I guess this is how you found t0?), but this resulted in nothing for me. So I've decided to check the print method. A quick look at

methods(print)

Showed me print.bootsempls*

Next step was:

getAnywhere(print.bootsempls)

Which resulted in:

A single object matching ‘print.bootsempls’ was found
It was found in the following places
  registered S3 method for print from namespace semPLS
  namespace:semPLS
with value

function (x, digits = 3, ...) 
{
    t <- x$t
    t0 <- x$t0
    result <- data.frame(Estimate = t0, Bias = colMeans(t, ...) - 
        t0, Std.Error = apply(t, 2, sd, ...))
    rownames(result) <- attr(t, "path")
    cat("Call: ")
    dput(x$call)
    cat("\n")
    print(result, digits = digits, ...)
    invisible(x)
}
<environment: namespace:semPLS>

Which solved the mystery. So apperantly the print method calculates the S.E. and it isn't stored anywhere. In order to replicate the output you showed and store it as a data.frmae object (and also to calculate S.E.) you will have to simply do the following:

t <- mymodel_boot$t
t0 <- mymodel_boot$t0
result <- data.frame(Estimate = t0, 
                     Bias = colMeans(t) - t0,
                     Std.Error = apply(t, 2, sd))