正如所有 R 语言一样,有很多方法可以做你想做的事。首先是查看函数的帮助菜单(在本例中为 ?alpha)。在那里,您将看到从 alpha 函数返回的许多对象。 (这是帮助文件的值部分中列出的内容。)
当您打印 alpha 的输出时,您只会看到这些对象的一个子集。但是,要查看返回的对象的完整列表,请使用“str”命令
my.results <- alpha(my.data)
str(my.results) #or just list the names of the objects
names(my.alpha)
[1] "total" "alpha.drop" "item.stats" "response.freq" "keys" "scores" "nvar" "boot.ci"
[9] "boot" "Unidim" "Fit" "call" "title"
然后您可以选择捕获这些对象中的任何一个以供自己使用。
因此
my.alpha <- alpha(ability) #use the ability data set in the psych package
my.alpha #will give the normal (and nicely formatted output)
totals <- my.alpha$total #just get one object from my.alpha
totals #show that object
将产生一行(没有花哨的输出):
raw_alpha std.alpha G6(smc) average_r S/N ase mean sd
0.8292414 0.8307712 0.8355999 0.2347851 4.909159 0.006384736 0.5125148 0.2497765
您可以对任何返回的对象执行此操作。我们大多数编写包的人都会打印我们认为是函数输出的基本元素,但会包含其他有用的信息。我们还允许其他功能(例如摘要)打印出其他信息。
所以,使用上面的例子,
summary(my.alpha) #prints the rounded to 2 decimals my.alpha$total object
Reliability analysis
raw_alpha std.alpha G6(smc) average_r S/N ase mean sd
0.83 0.83 0.84 0.23 4.9 0.0064 0.51 0.25
最后一句警告。我们中的许多人并没有发现 alpha 是一个特别有用的统计量来描述量表的结构。您可能想阅读有关如何使用 psych 包查找系数 omega 的教程,网址为
http://personality-project.org/r/psych/HowTo/R_for_omega.pdf