Skip to content

{ Tag Archives } R

《结构方程模型及其应用》(侯, 温, & 成,2004)部分章节R代码

用John FOX教授的sem包试写了这本教材的几个例子,结果都与LISREL8报告的Minimum Fit Function Chi-Square吻合。不过LISREL其它拟合指标用的是Normal Theory Weighted Least Squares Chi-Square ,所以看上去比Minimum Fit Function Chi-Square报告的结果要好那么一些些。LISREL历史上推的GFI/AGFI曾因为经常将差报好被批评,圈内朋友私下嘲笑这样LISREL就更好卖了,买软件的用户也高兴将差报好,只有读Paper的人上当。
目前只写了chap3_1..到Chap3_2_...,一共5(或6)个例子。尺有所短,寸有所长--sem包不会自动报告所有修正指数,不能做样本量不一样多的多组模型,对复杂的模型要写的代码太多。不过,在已经尝试的几个例子里,有一个是LISREL跑不出来但sem包能跑出结果的。目前sem包还没有达到结构方程众多商业软件的成熟水准,但R庞大的义工武器库已经使sem包至少已经在Missing Data Multiple Imputation、Bootstrapping等等应用上胜出一筹。所以例子中还附带了缺失数据一讲Multiple Impuation的R示范代码。
欢迎各位有兴趣作类似尝试的同学将结果email我, 可以陆续更新到下面的GPL版权代码集合中。
代码下载:lixiaoxu.googlepages.com (中大镜像)
[update] AMos, Mplus 与 SAS/STAT CALIS 缺省报告与使用的都是 Minimum Fit Function Chi-Square,可通过各种软件(Albright & Park, 2009)的结果对比查验。Normal Theory Weighted Least Squares Chi-Square并非总是比Minimum Fit Function Chi-Square报告更“好”的拟合结果(虽然常常如此)。Olsson, Foss, 和 Breivik (2004) 用模拟数据对比了二者,确证Minimum Fit Function Chi-Square计算得到的拟合指标在小样本之外的情形都比Normal Theory Weighted Least Squares Chi-Square的指标更适用。
R的sem包目前在迭代初值的计算上还做得不够好。我遇到的几个缺省初值下迭代不收敛案例,将参数设定合理范围的任意初值(比如TX,TY都设成0-1之间的正实数)之后都收敛了。
--
Albright, J. J., [...]

Also tagged

Paper for 1st Chinese useR! Conference: Web Powered by R, or R Powered by Web

欢迎在本部的同学明天上午到现场看李崇亮同学演示,地点见会议主页
论文下载(Googlepages, 中文大学镜像)
RWebFriend for Wordpress 在线示例(yo2.cn上的示例,  奇想录上的临时示例)
Google Presentation 在线演示

[update2009.07.11]文中MediaWiki与R集成的实验平台已不再开放编辑权限,原例转到另一个平台上(界面是西班牙语,找不到英语界面的平台)。希望能有帮手提供linux服务器自建一个平台。

Also tagged

气泡图击败Data Snoop

转自:泡网
Data Snoop, 民科的神奇直线(google 始作俑者):

气泡图,数据击败Data Snoop:

R tip:
n=20;plot(rnorm(n),rnorm(n),cex=sqrt(abs(rnorm(n)))*10,pch=1,col=1:n);

Also tagged

“Confidence interval of R-square”, but, which one?

In linear regression, confidence interval (CI) of population DV is narrower than that of predicted DV. With the assumption of generalizability, CI of at is
,
while CI of is
.
The pivot methods of both are quite similar as following.
,
so .
,
so

of linear regression is the point estimate of

for fixed IV(s) model. [...]

Also tagged

Wordpress (and WPMU) Plugin for R Web Interface

Download: RwebFriend.zip [Update] Including Chinese UTF8 Version

Plugin Name: RwebFriend

Plugin URL: http://lixiaoxu.lxxm.com/RwebFriend

Description: Set Rweb url options and transform [rcode]...[/rcode] or <rcode>...</rcode> tag-pair into TEXTAREA which supports direct submit to web interface of R. *Credit notes:codes of two relevant plugins are studied and imported. One of the plugins deals with auto html tags within TEXTAREA tag-pair, [...]

Also tagged

Type III ANOVA in R

Type III ANOVA SS for factor A within interaction of factor B is defined as , wherein A:B  is the pure interaction effect orthogonal to main effects of A, B, and intercept. There are some details in R to get pure interaction dummy IV(s).
Data is from SAS example PROC GLM, Example 30.3: Unbalanced ANOVA for [...]

Also tagged , ,

R: str(…) 与 getS3method(…,…)

感谢R专家XIE Yihui同学在线答疑

me: 请教两个R的技术:1.R中有没有对象浏览器之类的工具?一举看完一个对象的子子孙孙 2.怎么看深入的源代码> prcomp
function (x, ...)
UseMethod("prcomp")
<environment: namespace:stats>
Yihui: 1. str()是很常用的一个函数,它可以充分查看对象的子子孙孙 2. 很多函数要么是S3 method,要么是调用C code,所以一般不能直接看源代码
S3 method可以用getS3method()去查看,比如prcomp就是S3方法,那么可以看它的default方法是什么:
> getS3method('prcomp','default')
function (x, retx = TRUE, center = TRUE, scale. = FALSE, tol = NULL,
...)
{
x <- as.matrix(x)
x <- scale(x, center = center, scale = scale.)
cen <- attr(x, "scaled:center")
sc <- attr(x, "scaled:scale")
if (any(sc == 0))
stop("cannot rescale a constant/zero [...]

Also tagged

Understanding QQ plots

## Try distributions like rchisq, rt, runif, rf to view its heavy, or light, left, or right tail.

n <- 30;
ry <- rnorm(n);
qqnorm(ry);qqline(ry);
max(ry)
min(ry)
##view and guess what are x(s) and y(s)
I <- rep(1,n);
qr <- ((ry%*%t(I) > I %*% t(ry))+.5*(ry %*% t(I) == I%*%t(ry)))%*%I *(1/n);##qr are the sample quantiles
points(qr,ry,col="blue"); ##to view the fact, try the following
points(qr,qr*0,col="green",pch="|");
rx <- qnorm(qr);
points(rx,ry,col="red",pch="O");
##Red [...]

Also tagged

03DEC2007 R-workshop sponsored by dept of psy, ZSU(=SYSU, Guang-Zhou)

Here is the updated PPT for the talk in the afternoon--which includes the zipped example codes and set-up steps for the workshop in the evening within the 3rd page. The listed anonymous on-line test (result statistics) on p-value interpretation was cited indirectly From Gigerenzer, Krauss, & Vitouch (2004).
There is an advert on http://www.psy.sysu.edu.cn/detail_news.asp?id=258 and a [...]

Also tagged

Classic Neyman-Pearson approach demo

It notes here that N-P approach does not utilize the information in the accurate p value. Actually, at the time N-P approach was firstly devised, the accurate p value was not available usually. Now almost all statistic softwares provide accurate p values and the N-P approach becomes obsolete. Wilkinson & APA TFSI (1999) [...]

Also tagged