Skip to content
Prev 313656 / 398502 Next

format.pval () and printCoefmat ()

Hi Pradip,

May be this helps:
dat1<-read.table(text="
?contrast_level1 contrast_level2 mean_level1 mean_level2 rel_diff??? p_mean cohens_d
1????????????? wh??????????? 2+hi??????? 18.7????? 11.91??? 0.574? 1.64e-05? 0.1753
2????????????? wh??????????? 2+rc??????? 18.7????? 14.46??? 0.297? 9.24e-06? 0.1101
3????????????? wh??????????? aian??????? 18.7????? 13.54??? 0.384? 9.01e-05? 0.1335
4????????????? wh??????????? asan??????? 18.7??????? 6.00??? 2.123 2.20e-119? 0.3326
5????????????? wh??????????? blck??????? 18.7??????? 5.83??? 2.213? 0.00e+00? 0.3490
6????????????? wh??????????? csam??????? 18.7??????? 7.93??? 1.363? 1.27e-47? 0.2793
7????????????? wh??????????? cub??????? 18.7????? 10.85??? 0.728? 6.12e-08? 0.2025
8????????????? wh??????????? dmcn??????? 18.7??????? 7.13??? 1.629? 1.59e-15? 0.2981
9????????????? wh??????????? hisp??????? 18.7??????? 9.72??? 0.928 3.27e-125? 0.2420
10????????????? wh??????????? mex??????? 18.7??????? 9.60??? 0.952 8.81e-103? 0.2420
11????????????? wh??????????? nhpi??????? 18.7????? 16.14??? 0.162? 1.74e-01? 0.0669
12????????????? wh??????????? othh??????? 18.7????????? NA????? NA??????? NA????? NA
13????????????? wh????????????? pr??????? 18.7????? 10.47??? 0.791? 3.64e-23? 0.2131
14????????????? wh??????????? spn??????? 18.7????? 15.15??? 0.237? 1.58e-02? 0.0922
",sep="",header=TRUE,stringsAsFactors=FALSE)
?Lines1<-capture.output(printCoefmat(dat1[,-c(1:2)],has.Pvalue=TRUE,eps.Pvalue=0.001))
Lines2<-gsub("\\s+$","",gsub("\\.$","",Lines1[1:15]))
res<-data.frame(dat1[,1:2],read.table(text=Lines2,header=TRUE))
#or
# res<-cbind(dat1[,1:2],read.table(text=Lines2,header=TRUE))


?res
#?? contrast_level1 contrast_level2 mean_level1 mean_level2 rel_diff p_mean
#1?????????????? wh??????????? 2+hi??????? 18.7?????? 11.91??? 0.574 0.0000
#2?????????????? wh??????????? 2+rc??????? 18.7?????? 14.46??? 0.297 0.0000
#3?????????????? wh??????????? aian??????? 18.7?????? 13.54??? 0.384 0.0001
------------------------------------------------------------- 

----------------------------------------------------------

# cohens_d
#1??? 0.1753
#2??? 0.1101
#3??? 0.1335
-------------------------------------------------
-------------------------------------------------

?str(res)
#'data.frame':??? 14 obs. of? 7 variables:
# $ contrast_level1: chr? "wh" "wh" "wh" "wh" ...
# $ contrast_level2: chr? "2+hi" "2+rc" "aian" "asan" ...
# $ mean_level1??? : num? 18.7 18.7 18.7 18.7 18.7 18.7 18.7 18.7 18.7 18.7 ...
# $ mean_level2??? : num? 11.91 14.46 13.54 6 5.83 ...
# $ rel_diff?????? : num? 0.574 0.297 0.384 2.123 2.213 ...
# $ p_mean???????? : num? 0e+00 0e+00 1e-04 0e+00 0e+00 0e+00 0e+00 0e+00 0e+00 0e+00 ...
# $ cohens_d?????? : num? 0.175 0.11 0.134 0.333 0.349 ...


A.K.

----- Original Message -----
From: "Muhuri, Pradip (SAMHSA/CBHSQ)" <Pradip.Muhuri at samhsa.hhs.gov>
To: 'David Winsemius' <dwinsemius at comcast.net>
Cc: R help <r-help at r-project.org>
Sent: Friday, December 14, 2012 5:18 PM
Subject: Re: [R] format.pval () and printCoefmat ()

Hi David,

Thank you so much for helping me with the code.

Your suggested code gives me the following results. Please see below. I don't understand why I am getting two? blocks of prints (5 columns, and then 7 columns), with some columns repeated.

Regards,

Pradip
#############################
+? ? ? ?  printCoefmat(y0410_1825_mf_alc[ -(1:2) ], has.Pvalue=TRUE, eps.Pvalue=0.0001)
+ )
?  mean_level1 mean_level2 rel_diff p_mean cohens_d? 
1? ? ?  18.744? ? ? 11.911? ? 0.574?  0.00? ? 0.175? 
2? ? ?  18.744? ? ? 14.455? ? 0.297?  0.00? ? 0.110? 
3? ? ?  18.744? ? ? 13.540? ? 0.384?  0.00? ? 0.133? 
4? ? ?  18.744? ? ?  6.002? ? 2.123?  0.00? ? 0.333? 
5? ? ?  18.744? ? ?  5.834? ? 2.213?  0.00? ? 0.349? 
6? ? ?  18.744? ? ?  7.933? ? 1.363?  0.00? ? 0.279? 
7? ? ?  18.744? ? ? 10.849? ? 0.728?  0.00? ? 0.203? 
8? ? ?  18.744? ? ?  7.130? ? 1.629?  0.00? ? 0.298? 
9? ? ?  18.744? ? ?  9.720? ? 0.928?  0.00? ? 0.242? 
10? ? ? 18.744? ? ?  9.600? ? 0.952?  0.00? ? 0.242? 
11? ? ? 18.744? ? ? 16.135? ? 0.162?  0.17? ? 0.067 .
12? ? ? 18.744? ? ? ? ? NA? ? ?  NA? ?  NA? ? ?  NA? 
13? ? ? 18.744? ? ? 10.465? ? 0.791?  0.00? ? 0.213? 
14? ? ? 18.744? ? ? 15.149? ? 0.237?  0.02? ? 0.092 .
---
Signif. codes:? 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
?  contrast_level1 contrast_level2 mean_level1 mean_level2 rel_diff? ? p_mean cohens_d
1? ? ? ? ? ? ?  wh? ? ? ? ? ? 2+hi? ? ? ? 18.7? ? ?  11.91? ? 0.574? 1.64e-05?  0.1753
2? ? ? ? ? ? ?  wh? ? ? ? ? ? 2+rc? ? ? ? 18.7? ? ?  14.46? ? 0.297? 9.24e-06?  0.1101
3? ? ? ? ? ? ?  wh? ? ? ? ? ? aian? ? ? ? 18.7? ? ?  13.54? ? 0.384? 9.01e-05?  0.1335
4? ? ? ? ? ? ?  wh? ? ? ? ? ? asan? ? ? ? 18.7? ? ? ? 6.00? ? 2.123 2.20e-119?  0.3326
5? ? ? ? ? ? ?  wh? ? ? ? ? ? blck? ? ? ? 18.7? ? ? ? 5.83? ? 2.213? 0.00e+00?  0.3490
6? ? ? ? ? ? ?  wh? ? ? ? ? ? csam? ? ? ? 18.7? ? ? ? 7.93? ? 1.363? 1.27e-47?  0.2793
7? ? ? ? ? ? ?  wh? ? ? ? ? ?  cub? ? ? ? 18.7? ? ?  10.85? ? 0.728? 6.12e-08?  0.2025
8? ? ? ? ? ? ?  wh? ? ? ? ? ? dmcn? ? ? ? 18.7? ? ? ? 7.13? ? 1.629? 1.59e-15?  0.2981
9? ? ? ? ? ? ?  wh? ? ? ? ? ? hisp? ? ? ? 18.7? ? ? ? 9.72? ? 0.928 3.27e-125?  0.2420
10? ? ? ? ? ? ? wh? ? ? ? ? ?  mex? ? ? ? 18.7? ? ? ? 9.60? ? 0.952 8.81e-103?  0.2420
11? ? ? ? ? ? ? wh? ? ? ? ? ? nhpi? ? ? ? 18.7? ? ?  16.14? ? 0.162? 1.74e-01?  0.0669
12? ? ? ? ? ? ? wh? ? ? ? ? ? othh? ? ? ? 18.7? ? ? ? ? NA? ? ?  NA? ? ? ? NA? ? ?  NA
13? ? ? ? ? ? ? wh? ? ? ? ? ? ? pr? ? ? ? 18.7? ? ?  10.47? ? 0.791? 3.64e-23?  0.2131
14? ? ? ? ? ? ? wh? ? ? ? ? ?  spn? ? ? ? 18.7? ? ?  15.15? ? 0.237? 1.58e-02?  0.0922

Pradip K. Muhuri, PhD
Statistician
Substance Abuse & Mental Health Services Administration
The Center for Behavioral Health Statistics and Quality
Division of Population Surveys
1 Choke Cherry Road, Room 2-1071
Rockville, MD 20857
?
Tel: 240-276-1070
Fax: 240-276-1260
e-mail: Pradip.Muhuri at samhsa.hhs.gov
?
The?Center for Behavioral Health Statistics and Quality your feedback.? Please click on the following link to complete a brief customer survey:?? http://cbhsqsurvey.samhsa.gov

-----Original Message-----
From: David Winsemius [mailto:dwinsemius at comcast.net] 
Sent: Friday, December 14, 2012 3:22 PM
To: Muhuri, Pradip (SAMHSA/CBHSQ)
Cc: R help
Subject: Re: [R] format.pval () and printCoefmat ()
On Dec 14, 2012, at 11:48 AM, Muhuri, Pradip (SAMHSA/CBHSQ) wrote:

            
They are probably factor columns.
Presumably that call will produce desired results since it is on only one column. (I'm not sure why you think format.pval contributed to your NA output.)
Why not use `cbind.data.frame` rather than trying to get `printCoefmat` to do something it (apparently) wasn't designed to do?

cbind(? y0410_1825_mf_alc[ 1:2],? 
? ? ? ? printCoefmat(y0410_1825_mf_alc[ -(1:2) ], has.Pvalue=TRUE, eps.Pvalue=0.0001)
? ?  )