[R] Psych package: why am I receiving "NA" for many of the factor scores?
William Revelle
lists at revelle.net
Fri Jan 16 00:22:38 CET 2015
Dear Elizabeth,
A correction to my suggestion:
scaled <- scale(mydata)
wts <- f4$weights
scores <-t( apply(scaled,1,function(x) colSums(x*wts,na.rm=TRUE))) #you need the colSums not the sum function
Also, your confusion in getting the NAs with missing data was due to a bug in the fa function in the way it just ignored the missing statement.
Thanks for catching that. It is now fixed and should be on CRAN real soon.
Bill
> On Jan 14, 2015, at 9:39 AM, William Revelle <lists at revelle.net> wrote:
>
> Dear Elizabeth,
>
> Factor scores in the fa function are found by multiplying the standardized data by the factor weights using matrix multiplication. This will give scores only for subjects with complete data.
>
> However, if you want, you can create them yourself by standardizing your data and then multiplying them by the weights:
>
> mydata <- rProjectSurveyDataJustVariables
>
> f4 <- fa(my.data,4) #modify this to match your call
> wts <- f4$wts
> scaleddata <- scale(mydata)
> scores <- apply(scaleddata,1,function(x) sum(x * wts,na.rm=TRUE))
>
> #this will work with complete data, and impute factor scores for those cases with incomplete data. If the data are missing completely at random, this should give a reasonable answer. However, if the missingness has some structure to it, the imputed scores will be biased.
>
> This is a reasonable option to add to the fa function and I will do so.
>
> A side note. If you need help with a package, e.g., psych, you get faster responses by writing to the package author. I just happened to be browsing R-help when your question came in.
>
> Let me know if this solution works for you.
>
> Bill
>
>
>
>> On Jan 13, 2015, at 7:46 PM, Elizabeth Barrett-Cheetham <ebarrettcheetham at gmail.com> wrote:
>>
>>
>> Hello R Psych package users,
>>
>> Why am I receiving "NA" for many of the factor scores for individual
>> observations? I'm assuming it is because there is quite a bit of missing
>> data (denoted by NA). Are there any tricks in the psych package for getting
>> a complete set of factor scores?
>>
>> My input is:
>> rProjectSurveyDataJustVariables = read.csv("R Project Survey Data Just
>> Variables.csv", header = TRUE)
>> solution <- fa(r = rProjectSurveyDataJustVariables, nfactors = 4, rotate =
>> "oblimin", fm = "ml", scores = "tenBerge", warnings = TRUE, oblique.scores =
>> TRUE)
>> solution
>>
>> Thank you.
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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 Revelle http://personality-project.org/revelle.html
> Professor http://personality-project.org
> Department of Psychology http://www.wcas.northwestern.edu/psych/
> Northwestern University http://www.northwestern.edu/
> Use R for psychology http://personality-project.org/r
> It is 5 minutes to midnight http://www.thebulletin.org
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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 Revelle http://personality-project.org/revelle.html
Professor http://personality-project.org
Department of Psychology http://www.wcas.northwestern.edu/psych/
Northwestern University http://www.northwestern.edu/
Use R for psychology http://personality-project.org/r
It is 5 minutes to midnight http://www.thebulletin.org
More information about the R-help
mailing list