Re: [R] In factor analysis in the psych package, how can I work out which factors the columns in $scores relate to? How do I know what each of the scores is scoring?

2012-12-09 Thread Brent Caldwell
Dear Professor Carlson
Thank you so much! The $Structure command displays the loadings with the same 
style of column heading as the $scores (i.e.  [,1]   [,2][,3]   
[,4][,5]   [,6]   [,7]   [,8] [,9]  [,10]   
[,11]), and makes me so much more confident that the columns in the $scores are 
displayed in the same order as the columns in $loadings, even though $loadings 
has  different column headings to $scores (the column headings of $loadings are 
MR4   MR3MR2  MR6   MR7  MR5   
MR1  MR8 MR10  MR9 MR11).
Thank you!
Best wishes
Brent



-Original Message-
From: David L Carlson [mailto:dcarl...@tamu.edu] 
Sent: Thursday, 6 December 2012 2:45 p.m.
To: Brent Caldwell; 'r-help@R-project.org'
Cc: 'William R Revelle'
Subject: RE: [R] In factor analysis in the psych package, how can I work out 
which factors the columns in $scores relate to? How do I know what each of the 
scores is scoring?

I think you are safe in assuming that the first factor is used to compute the 
first factor score column. The factor.scores() procedure is used by fa() to 
compute the factor scores so it provides details regarding how they are 
computed beyond the information in the fa() help page. As I understand the help 
file, the default rotation is oblimin so 

In the oblique case, the factor loadings are referred to as Pattern 
coefficients and are related to the Structure coefficients by S = P and thus P 
= S1. When estimating factor scores, fa and factanal differ in that fa finds 
the factors from the Structure matrix and factanal seems to find them from the 
Pattern matrix. Thus, although in the orthogonal case, fa and factanal agree 
perfectly in their factor score estimates, they do not agree in the case of 
oblique factors. Setting oblique.scores = FALSE will produce factor score 
estimate that match those of factanal.

So you might want to look at $Structure.

The $scores part of the output is a matrix without column names (they are just 
numbered). The V1, V2, . . . is added by the write.csv() function and is not 
part of the actual output from fa(). 

---
David

 -Original Message-
 From: Brent Caldwell [mailto:brent.caldw...@otago.ac.nz]
 Sent: Wednesday, December 05, 2012 7:08 PM
 To: dcarl...@tamu.edu; 'r-help@R-project.org'
 Cc: William R Revelle (reve...@northwestern.edu)
 Subject: RE: [R] In factor analysis in the psych package, how can I 
 work out which factors the columns in $scores relate to? How do I know 
 what each of the scores is scoring?
 
 Dear Prof Carlson
 Thank you very much.  As far as I can tell, factor.scores requires an 
 object from class grm, itm, rason, or tpm; which I think are part of 
 the irt package with which I am unfamiliar.
 I had used the psych package to do the following factor analysis:
 fa.11factors.rawdata - fa(WISDMrawdataframe,nfactors=11) # 
 WISDMrawdataframe has 37 columns and 2408 rows, and contain 1051 rows 
 that are NA (having NA in this dataframe allows the raw data to have 
 the same length as my vector of ID numbers so I can work out which 
 participants the data belong to) fa.11factors.rawdata$loadings #on the 
 computer screen this gives me the
 loadings with column namesMR4MR3MR2MR6MR7MR5
 MR1MR8MR10   MR9MR11
 fa.11factors.rawdata$scores # on the computer screen this gives me the
 scores with column names  [,1]   [,2][,3]
 [,4][,5]   [,6]   [,7]   [,8] [,9]
 [,10]   [,11]
 Am I safe in assuming that the scores in the first column relate to 
 the loadings in the column called MR4?
 If this is a safe assumption, then I can work out which factor the
 scores relate to, by looking at which items load onto MR4MR3MR2
 MR6MR7MR5MR1MR8MR10   MR9MR11
 Thank you, I've taken your advice and cc'd this to Prof William 
 Revelle Thank you Best wishes Brent
 
 -Original Message-
 From: David L Carlson [mailto:dcarl...@tamu.edu]
 Sent: Thursday, 6 December 2012 10:33 a.m.
 To: Brent Caldwell; 'r-help@R-project.org'
 Subject: RE: [R] In factor analysis in the psych package, how can I 
 work out which factors the columns in $scores relate to? How do I know 
 what each of the scores is scoring?
 
 Without seeing what options you have specified in your call to fa(), 
 it is not possible to answer the question. There are detailed 
 discussions in ?fa and ?factor.scores in the psych package, but for 
 the final word you should probably contact the package maintainer:
 
 Package: psych
 Version: 1.2.8
 Date: 2012-08-08
 Title: Procedures for Psychological, Psychometric, and Personality
 Research
 Author: William Revelle reve...@northwestern.edu
 Maintainer: William Revelle reve...@northwestern.edu
 
 --
 David L Carlson
 Associate Professor of Anthropology

[R] In factor analysis in the psych package, how can I work out which factors the columns in $scores relate to? How do I know what each of the scores is scoring?

2012-12-05 Thread Brent Caldwell
Hi
I have used fa() to perform a factor analysis of a psychological battery which 
is thought to have 11 factors.  I can identify which factors the loadings 
relate to easily enough because I can see which items are loading onto each of 
the columns in the $loading output.  However, how can I identify which items or 
loadings are being used to create each of the columns in the $scores output?  I 
have used generalised linear models which have shown that some of the scores 
are significant predictors of treatment outcome, but I can't work out which of 
the 11 factors they are scoring?

when I export to csv the $loadings I get the following columns in this order:
 MR4, MR3, MR2, MR6, MR7, MR5, MR1, MR8, MR10, MR9, MR11 

When I export to csv the $scores I get the following columns in this order:
V1, V2, V3, V4, V5, V6, V7, V8, V9, V10,V11 

Are the scores in the column V1 derived from the loadings in column MR1 ?  
Or are the scores in the first column of $scores (ie V1) derived from the 
loadings in the first column of $loadings (ie MR4)?

Thank you very much for your guidance, and your patience with my confusion
Best wishes
Brent


Brent Caldwell, MBChB, DPH, MPH.
Research Fellow
Department of Medicine
University of Otago, Wellington
New Zealand
U  brent.caldw...@otago.ac.nz
b  04 918 6041
   021 87 22 64
  23a Mein Street, PO Box 7343, Newtown, WELLINGTON 6021, NEW ZEALAND
brent.ower.caldwell
  Zonnic study

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] In factor analysis in the psych package, how can I work out which factors the columns in $scores relate to? How do I know what each of the scores is scoring?

2012-12-05 Thread Brent Caldwell
Dear Prof Carlson
Thank you very much.  As far as I can tell, factor.scores requires an object 
from class grm, itm, rason, or tpm; which I think are part of the irt package 
with which I am unfamiliar.
I had used the psych package to do the following factor analysis:
fa.11factors.rawdata - fa(WISDMrawdataframe,nfactors=11)
# WISDMrawdataframe has 37 columns and 2408 rows, and contain 1051 rows that 
are NA (having NA in this dataframe allows the raw data to have the same length 
as my vector of ID numbers so I can work out which participants the data belong 
to)
fa.11factors.rawdata$loadings #on the computer screen this gives me the 
loadings with column namesMR4MR3MR2MR6MR7MR5MR1
MR8MR10   MR9MR11
fa.11factors.rawdata$scores # on the computer screen this gives me the scores 
with column names  [,1]   [,2][,3]   [,4]
[,5]   [,6]   [,7]   [,8] [,9]  [,10]   [,11]
Am I safe in assuming that the scores in the first column relate to the 
loadings in the column called MR4?  
If this is a safe assumption, then I can work out which factor the scores 
relate to, by looking at which items load onto MR4MR3MR2MR6MR7  
  MR5MR1MR8MR10   MR9MR11
Thank you, I've taken your advice and cc'd this to Prof William Revelle
Thank you
Best wishes
Brent

-Original Message-
From: David L Carlson [mailto:dcarl...@tamu.edu] 
Sent: Thursday, 6 December 2012 10:33 a.m.
To: Brent Caldwell; 'r-help@R-project.org'
Subject: RE: [R] In factor analysis in the psych package, how can I work out 
which factors the columns in $scores relate to? How do I know what each of the 
scores is scoring?

Without seeing what options you have specified in your call to fa(), it is not 
possible to answer the question. There are detailed discussions in ?fa and 
?factor.scores in the psych package, but for the final word you should probably 
contact the package maintainer: 

Package: psych
Version: 1.2.8
Date: 2012-08-08
Title: Procedures for Psychological, Psychometric, and Personality
Research
Author: William Revelle reve...@northwestern.edu
Maintainer: William Revelle reve...@northwestern.edu

--
David L Carlson
Associate Professor of Anthropology
Texas AM University
College Station, TX 77843-4352

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- 
 project.org] On Behalf Of Brent Caldwell
 Sent: Wednesday, December 05, 2012 2:53 PM
 To: r-help@R-project.org
 Subject: [R] In factor analysis in the psych package, how can I work 
 out which factors the columns in $scores relate to? How do I know what 
 each of the scores is scoring?
 
 Hi
 I have used fa() to perform a factor analysis of a psychological 
 battery which is thought to have 11 factors.  I can identify which 
 factors the loadings relate to easily enough because I can see which 
 items are loading onto each of the columns in the $loading output.
 However, how can I identify which items or loadings are being used to 
 create each of the columns in the $scores output?  I have used 
 generalised linear models which have shown that some of the scores are 
 significant predictors of treatment outcome, but I can't work out 
 which of the 11 factors they are scoring?
 
 when I export to csv the $loadings I get the following columns in this
 order:
  MR4, MR3, MR2, MR6, MR7, MR5, MR1, MR8, MR10, MR9, MR11
 
 When I export to csv the $scores I get the following columns in this
 order:
 V1, V2, V3, V4, V5, V6, V7, V8, V9, V10,V11
 
 Are the scores in the column V1 derived from the loadings in column 
 MR1 ?
 Or are the scores in the first column of $scores (ie V1) derived from 
 the loadings in the first column of $loadings (ie MR4)?
 
 Thank you very much for your guidance, and your patience with my 
 confusion Best wishes Brent
 
 
 Brent Caldwell, MBChB, DPH, MPH.
 Research Fellow
 Department of Medicine
 University of Otago, Wellington
 New Zealand
 U  brent.caldw...@otago.ac.nz
 b  04 918 6041
021 87 22 64
   23a Mein Street, PO Box 7343, Newtown, WELLINGTON 6021, NEW ZEALAND
 brent.ower.caldwell
   Zonnic study
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] trying to understand the names of the loadings and factor scores from fa()

2012-12-02 Thread Brent Caldwell
Hi
I'm trying to understand the names of the output I get from extracting the 
loadings and the factor scores from fa()

when I export to csv the $loadings I get the following columns in this order:
 MR4, MR3, MR2, MR6, MR7, MR5, MR1, MR8, MR10, MR9, MR11 

When I export to csv the $scores I get the following columns in this order:
V1, V2, V3, V4, V5, V6, V7, V8, V9, V10,V11 

Are the scores in the column V1 derived from the loadings in column MR1 ?  
Or are the scores in the first column of $scores (ie V1) derived from the 
loadings in the first column of $loadings (ie MR4)?

Thank you very much for your guidance
Best wishes
Brent

Brent Caldwell, MBChB, DPH, MPH.
Research Fellow
Department of Medicine
University of Otago, Wellington
U  brent.caldw...@otago.ac.nz
b  04 918 6041
   021 87 22 64
  23a Mein Street, PO Box 7343, Newtown, WELLINGTON 6021, NEW ZEALAND 
brent.ower.caldwell
  Zonnic study

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Plotting an adjusted survival curve

2012-11-27 Thread Brent Caldwell
Dear Terry and David
Thank you so much for your rapid and helpful replies!
I've changed tack slightly and decided to focus on the effect modifiers which 
had the greatest effect on the outcome of the trial (HowmanyZonnic_Q and 
WISDMPDM)
I've tried to follow your example on page 16 of the manuscript you emailed me, 
but I get an error which I think is related to trying to do maths on two 
matrices which are of different dimensions I think???
This is my code:
KM.object.coxph5 - coxph(Surv(whenfailed,failed) ~ 
strata(Treatment)+HowmanyZonnic_Q+WISDMPDM,survmat)
asdist - table(HowmanyZonnic_Q,WISDMPDM)
uage - as.numeric(dimnames(asdist)[[1]])
tdata - expand.grid(HowmanyZonnic_Q=uage, WISDMPDM=uage) #This appears to be a 
table of all the possible combinations of HowmanyZonnic_Q and WISDMPDM
par(mfrow=c(1,2))
sfit4a - survfit(KM.object.coxph5, newdata=tdata, se.fit=FALSE)
sfit4a$surv - sfit4a$surv %*% c(asdist/sum(asdist)) #Error in sfit4a$surve %*% 
c(asdist/sum(asdist)) :   non-conformable arguments
#sfit4a$surv is a table of 10 rows and 25 columns
#c(asdist/sum(asdist)) is a vector with a length of 420
I hope I am not sapping your patience with this question
Thank you - you guys are awesome
Best wishes
Brent

-Original Message-
From: Terry Therneau [mailto:thern...@mayo.edu] 
Sent: Tuesday, 27 November 2012 4:03 a.m.
To: r-help@r-project.org; Brent Caldwell
Cc: David Winsemius
Subject: Re: Plotting an adjusted survival curve

First a statistical issue: The survfit routine will produce predicted survival 
curves for any requested combination of the covariates in the original model.  
This is not the same thing as an adjusted survival curve.  Confusion on this 
is prevalent, however.  True adjustment requires a population average over the 
confounding factors and is closely related to the standardized incidence ratio 
concept found in epidemiology.

To answer your technical question:
fit - coxph(Surv(.
mysurv - survfit(fit, newdata= mydata) This will give a set of predicted 
curves, one for each observation in mydata.  If we assume 2 treatments and 4 
ethnicities, this means that there are 8 possible predicted curves.  You can 
certainly take the curves for trt=1, white and trt=2, white, plot them 
together on one graph, and call this your adjusted survival curves; the 
mydata data set would have two observations.  This is not a correct label but 
is certainly common.

Terry Therneau

On 11/26/2012 05:00 AM, r-help-requ...@r-project.org wrote:
 Dear R-users
 I am trying to make an adjusted Kaplan-Meier curve (using the Survival 
 package) but I am having difficulty with plotting it so that the plot only 
 shows the curves for the adjusted results.
 My data come from a randomised controlled trial, and I would like the 
 adjusted Kaplan-Meier curve to only show two curves for the adjusted 
 survival: one for those on treatment (Treatment==1) and another curve for 
 those on placebo (Treatment==0).

 My problem is that when I plot the survfit of my coxph, I think it 
 displays a curve for every single individual factor in my coxph, 
 whereas I would like it to only display the adjusted curves for when 
 Treatment==1 and Treatment==0.  How can I do this?

 A simplified example of my code with only one effect-modifier is:

 simple.cox.ethnicity- coxph(Surv(whenfailed,failed) ~ 
 factor(Treatment) + factor(ethnicity)) #I've my data are attached 
 already
 survfit.simple.cox.ethnicity- survfit(simple.cox.ethnicity,survmat) 
 #survmat is a data.frame that contains Treatment and ethnicity 
 plot(survfit.simple.cox.ethnicity, col=c(red,black), 
 main=survfit.simple.cox, xlab=survival time, ylab=propotion 
 surviving)

 Thank you so much for your help.
 Yours gratefully,
 Brent Caldwell

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Psych package: fa.diagram, how to re-arrange layout so numbers do not over-write each other

2012-11-26 Thread Brent Caldwell
Dear R help
I have conducted a fa() analysis,  and  I want to use fa.diagram to assess the 
extent to which the 11 latent factors predict the 37 items in a psychological 
battery.  However, the display on the screen has very large font size for the 
coefficients of the relationship between the 11 factors and the 37 items, so 
the numbers overlap and are therefore illegible.  When I output this to a pdf 
the problem is exacerbated even further (see attachments).  I tried to use 
cex=0.8 and cex=0.4 in the pdf argument but it made no difference - what can I 
do?
The code I used is:
fa.diagram(fa.11factors.rawdata)
# Start PDF device driver to save output to fa_diagram.pdf
pdf(file=I:\\ZAPi\\Tables-of-R-output\\fa_diagram.pdf, height=10, width=5)
fa.diagram(fa.11factors.rawdata)
#box() # Create box around plot
dev.off() # Turn off device driver (to flush output to PDF)

pdf(file=I:\\ZAPi\\Tables-of-R-output\\fa_diagram_cex.pdf, height=8, width=5)
fa.diagram(fa.11factors.rawdata,cex=0.8)
#box() # Create box around plot
dev.off() # Turn off device driver (to flush output to PDF)
Thank you so much for your time
Yours sincerely
Brent Caldwell



fa_diagram_cex.pdf
Description: fa_diagram_cex.pdf


fa_diagram.pdf
Description: fa_diagram.pdf
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Psych package: fa.diagram, how to re-arrange layout so numbers do not over-write each other

2012-11-26 Thread Brent Caldwell
Dear Bill
Wow!  Thank you so much for your rapid reply - you are such a kind person, 
thank you!
I'll try fa.rgraph - thanks
Thanks
Best wishes
Brent

-Original Message-
From: William R Revelle [mailto:reve...@northwestern.edu] 
Sent: Tuesday, 27 November 2012 5:54 p.m.
To: Brent Caldwell
Cc: r-help@R-project.org
Subject: Re: [R] Psych package: fa.diagram, how to re-arrange layout so numbers 
do not over-write each other

Brent,
  No, cex doesn't work (as you have discovered).  That is a bug.
I will work on it.

In the meantime, try Rgraphviz called from fa.rgaph or use the output from 
fa.graph which produces a dot file for processing with any graphic package 
(including graphviz) which handles the dot language.

 

Bill

On Nov 26, 2012, at 10:08 PM, Brent Caldwell brent.caldw...@otago.ac.nz wrote:

 Dear R help
 I have conducted a fa() analysis,  and  I want to use fa.diagram to assess 
 the extent to which the 11 latent factors predict the 37 items in a 
 psychological battery.  However, the display on the screen has very large 
 font size for the coefficients of the relationship between the 11 factors and 
 the 37 items, so the numbers overlap and are therefore illegible.  When I 
 output this to a pdf the problem is exacerbated even further (see 
 attachments).  I tried to use cex=0.8 and cex=0.4 in the pdf argument but it 
 made no difference - what can I do?
 The code I used is:
 fa.diagram(fa.11factors.rawdata)
 # Start PDF device driver to save output to fa_diagram.pdf 
 pdf(file=I:\\ZAPi\\Tables-of-R-output\\fa_diagram.pdf, height=10, width=5)
   fa.diagram(fa.11factors.rawdata)
   #box() # Create box around plot
   dev.off() # Turn off device driver (to flush output to PDF)
 
 pdf(file=I:\\ZAPi\\Tables-of-R-output\\fa_diagram_cex.pdf, height=8, 
 width=5)
   fa.diagram(fa.11factors.rawdata,cex=0.8)
   #box() # Create box around plot
   dev.off() # Turn off device driver (to flush output to PDF) Thank you 
 so much for your time Yours sincerely Brent Caldwell
 
 fa_diagram_cex.pdffa_diagram.pdf__
 
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

William Revellehttp://personality-project.org/revelle.html
Professor  http://personality-project.org
Department of Psychology   http://www.wcas.northwestern.edu/psych/
Northwestern Universityhttp://www.northwestern.edu/
Use R for psychology http://personality-project.org/r
It is 5 minutes to midnighthttp://www.thebulletin.org

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Plotting an adjusted kaplan-meier curve

2012-11-25 Thread Brent Caldwell
Dear R-users
I am trying to make an adjusted Kaplan-Meier curve (using the Survival package) 
but I am having difficulty with 
plotting it so that the plot only shows the curves for the adjusted results.  
My data come from a randomised controlled trial, and I would like the adjusted 
Kaplan-Meier 
curve to only show two curves for the adjusted survival: one for those on 
treatment (Treatment==1) 
and another curve for those on placebo (Treatment==0).

My problem is that when I plot the survfit of my coxph, I think it displays a 
curve for 
every single individual factor in my coxph, whereas I would like it to only 
display the 
adjusted curves for when Treatment==1 and Treatment==0.  How can I do this?

A simplified example of my code with only one effect-modifier is:

simple.cox.ethnicity - coxph(Surv(whenfailed,failed) ~ factor(Treatment) + 
factor(ethnicity)) #I've my data are attached already
survfit.simple.cox.ethnicity - survfit(simple.cox.ethnicity,survmat) #survmat 
is a data.frame that contains Treatment and ethnicity
plot(survfit.simple.cox.ethnicity, col=c(red,black), 
main=survfit.simple.cox, xlab=survival time, ylab=propotion surviving)

Thank you so much for your help.
Yours gratefully,
Brent Caldwell

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.