简体   繁体   中英

factanal help and how to code using formula

I've got this equation to apply in R

fit <- factanal (f[filename : x+n], factors , rotation='varimax')

what do i put where? i know to put my filename where it says, but i'm getting my data from an excel table that i've made about suburbs in my city and different qualities about the suburbs and i've uploaded that to r

You should take a look at ?factanal to understand the meaning of every function argument.

For example,

  1. the first argument x needs to be a numeric matrix or an object that can be coerced to a numeric matrix (like a data.frame ).
  2. the second argument factors specifies the number of factors in the factor analysis.

Here is a example based on some randomly generated data.

# Sample data
set.seed(2017)
df <- data.frame(
    a = runif(10),
    b = runif(10),
    c = runif(10),
    d = runif(10),
    e = runif(10))

# Perform factor analysis
fit <- factanal(df, factors = 2, rotation = 'varimax')
#
#Call:
#factanal(x = df, factors = 2, rotation = "varimax")
#
#Uniquenesses:
#    a     b     c     d     e
#0.162 0.639 0.005 0.397 0.054
#
#Loadings:
#  Factor1 Factor2
#a          0.914
#b  0.601
#c -0.990   0.120
#d          0.777
#e  0.820   0.523
#
#               Factor1 Factor2
#SS loadings      2.017   1.727
#Proportion Var   0.403   0.345
#Cumulative Var   0.403   0.749
#
#Test of the hypothesis that 2 factors are sufficient.
#The chi square statistic is 1.14 on 1 degree of freedom.
#The p-value is 0.285

I don't know how you read in data from an Excel sheet (is it an XLS/XLSX or CSV file?), but you need to ensure that the first argument in factanal is a numeric matrix or data.frame .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM