Help with asterisk p-value

Hi everybody,

I would like to ask for help. I have data like that and I used this code for my data. I would like to ask whether I could add asterisk for p-value (in p1) besides the value of the coefficient (in c1).

Thank you in advance. I really appreciate any help.

library(GRS.test)

panel<-select(df,date,rmrf,SMB,HML,p1:p3)

factor.mat = panel[1:nrow(panel),2:4]

ret.mat = panel[1:nrow(panel),5:ncol(panel)]

c1<-GRS.test(ret.mat,factor.mat)$coef

p1<-GRS.test(ret.mat,factor.mat)$pval
df<-data.frame(

rmrf = c(-0.12,-0.01,0.15,0.01,-0.09,-0.05,

-0.1,-0.22,-0.23,0,-0.21,-0.05,0.11,0.18,-0.17,-0.25,

-0.1,-0.01,-0.05,-0.2,0.14,0.14,0.27,0.08,0.03,0.16,0.06,

0,-0.15,-0.03),

SMB = c(0,-0.05,0.13,0.34,0.02,0.02,0.01,

-0.01,-0.02,0,-0.03,0.01,0.04,0.12,0.01,0.02,-0.01,-0.03,

0.04,0.05,-0.04,-0.04,0.02,0.04,-0.03,-0.06,0.08,

0.09,-0.04,0.02),

HML = c(-0.02,0.07,0.1,0.28,0.01,0,-0.05,0,

-0.11,-0.08,-0.1,0,-0.02,-0.08,0.02,0.06,0.05,0.01,

0.02,0.01,-0.01,0.01,0.04,0,0,0.08,0.09,0.01,-0.03,

0.03),

RMW = c(-0.04,0.05,-0.02,-0.03,0.03,0,-0.04,

-0.01,-0.06,0.01,-0.02,0.04,0.14,0.01,0,-0.04,0,-0.03,

0.01,0.01,0.03,0.01,-0.03,0.04,0.05,-0.01,-0.02,0.02,

0,0.03),

CMA = c(0.02,-0.04,0.02,0.04,0.01,0,0.01,

-0.05,-0.03,-0.04,0,-0.02,-0.01,-0.09,0,-0.02,0,0.04,

-0.03,-0.03,0.06,0,0.02,0,0.01,0.01,0,-0.02,0.01,0),

p1 = c(-0.12,0.02,0.09,0.32,-0.14,-0.01,

-0.14,-0.25,-0.25,0.02,-0.22,0.03,-0.1,0.37,-0.12,-0.26,

-0.09,-0.04,-0.02,-0.13,0.1,0.09,0.31,0.07,0.02,0.16,

0.08,0.17,-0.19,-0.02),

p2 = c(-0.02,-0.12,0.02,0.21,-0.11,-0.06,

-0.08,-0.2,-0.26,0.02,-0.21,-0.18,-0.04,0.4,0.03,-0.33,

-0.19,-0.14,0.01,0.12,0.03,-0.01,0.19,0.35,-0.05,0.11,

0.14,0.16,-0.12,-0.03),

p3 = c(-0.21,-0.04,0.22,0.86,-0.06,-0.03,

0.09,-0.34,-0.3,-0.15,-0.27,-0.2,0.33,0.2,-0.15,-0.29,

-0.12,-0.05,-0.03,-0.19,0.19,0.1,0.54,0.01,0.02,0.07,

0.06,0.23,-0.14,-0.07),

date = as.factor(c("2007-07-31",

"2007-08-31","2007-09-28","2007-10-31","2007-11-30",

"2007-12-28","2008-01-31","2008-02-29","2008-03-31",

"2008-04-29","2008-05-30","2008-06-30","2008-07-31",

"2008-08-29","2008-09-30","2008-10-31",

"2008-11-28","2008-12-31","2009-01-23","2009-02-27",

"2009-03-31","2009-04-29","2009-05-29","2009-06-30",

"2009-07-31","2009-08-31","2009-09-30","2009-10-30",

"2009-11-30","2009-12-31"))

)

This is the table I would like to get.
image


(thresh_matrix <- ifelse(p1 < 0.05 ,"***",""))

outvals <- purrr::map_chr(seq_along(thresh_matrix),
           ~paste0(round(c1[.],digits=7),thresh_matrix[.]))

thresh_matrix[] <- outvals

thresh_matrix
# intercept    rmrf           SMB            HML        
# p1 "-0.0043416" "0.9433171***" "0.7605886***" "0.0451065"
# p2 "-0.0148221" "0.7622273***" "1.2288618***" "-0.600917"
# p3 "-0.0080243" "1.1064236***" "1.5629898***" "0.5440917"
1 Like

Thank you so much for your help.
Best regards,

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