我对R不太在行,我运行了这个循环,得到了11,303,044行的巨大向量。我有另一个向量,它是由另一个维数为1681行的循环产生的。
我希望运行一个chisq.test
来比较它们的发行版。但由于它们的长度不同,所以它不起作用。
我试着从11,303,044个大小的向量中抽取1681个大小的样本来匹配第二个向量的大小长度,但是每次运行它时,我都得到不同的chisq.test
结果。
我想把这两个向量分成等量的间隔。
比方说
vector1:
temp.mat<-matrix((rnorm(11303044))^2, ncol=1)
head(temp.mat)
dim(temp.mat)
vector2:
temp.mat<-matrix((rnorm(1681))^2, ncol=1)
head(temp.mat)
dim(temp.mat)
如何在相同的时间间隔内将它们分割成相同的长度向量?
发布于 2013-10-10 15:09:44
chisq.test
是皮尔森(氏)卡方检验。它是为离散数据而设计的,有两个输入向量,它会强迫你传递给因子的输入,它测试的是独立性,而不是分布的均匀度。例如,这意味着数据的顺序将产生影响。
> set.seed(123)
> x<-sample(5,10,T)
> y<-sample(5,10,T)
> chisq.test(x,y)
Pearson's Chi-squared test
data: x and y
X-squared = 18.3333, df = 16, p-value = 0.3047
Warning message:
In chisq.test(x, y) : Chi-squared approximation may be incorrect
> chisq.test(x,y[10:1])
Pearson's Chi-squared test
data: x and y[10:1]
X-squared = 16.5278, df = 16, p-value = 0.4168
Warning message:
In chisq.test(x, y[10:1]) : Chi-squared approximation may be incorrect
所以我不认为chisq.test
是您想要的,因为它没有比较发行版。也许可以尝试一些类似ks.test
的方法,它可以处理不同的长度向量和连续的数据。
> set.seed(123)
> x<-rnorm(2000)^2
> y<-rnorm(100000)^2
> ks.test(x,y)
Two-sample Kolmogorov-Smirnov test
data: x and y
D = 0.0139, p-value = 0.8425
alternative hypothesis: two-sided
> ks.test(sqrt(x),y)
Two-sample Kolmogorov-Smirnov test
data: sqrt(x) and y
D = 0.1847, p-value < 2.2e-16
alternative hypothesis: two-sided
发布于 2013-10-10 15:05:24
mat1<-matrix((rnorm(1130300))^2, ncol=1) # only one-tenth the size of your vector
smat=sample(mat1, 100000) #and take only one-tenth of that
mat2<-matrix((rnorm(1681))^2, ncol=1)
qqplot(smat,mat2) #and repeat the sampling a few times
从统计的角度看,你所看到的似乎很有趣。在“偏离平均值”的较高水平上,大样本总是偏离“良好拟合”,这并不奇怪,因为它有更多的真正的极端值。
https://stackoverflow.com/questions/19307509
复制相似问题