sample.int中的错误(长度(x),大小,替换,概率):当'replace = FALSE'

时间:2016-03-05 21:47:48

标签: r

我正试图从kohonen包中运行SOM。当我使用10x10尺寸时。它有效,当我将2d潜在尺寸增加到20x20或更大时,它给了我以下错误。有人能帮我吗?为什么会这样?如果我有包含9个变量的167个数据,那么理想的2D潜在维度是多少?非常感谢你

> dim(data)
[1] 167   9
> dim(data_scale)
[1] 167   9
> class(data)
[1] "data.frame"
> class(data_scale)
[1] "matrix"
> som_grid<-somgrid(xdim = 10, ydim = 10 , topo = "hexagonal")
> som_model<-som(data_scale, grid=som_grid, rlen=1000, alpha=c(0.05,0.01),n.hood="circular", keep.data=TRUE)
> som_grid<-somgrid(xdim = 20, ydim = 10 , topo = "hexagonal")
> som_grid<-somgrid(xdim = 20, ydim = 20 , topo = "hexagonal")
> som_model<-som(data_scale, grid=som_grid, rlen=1000, alpha=c(0.05,0.01),n.hood="circular", keep.data=TRUE)
Error in sample.int(length(x), size, replace, prob) : 
  cannot take a sample larger than the population when 'replace = FALSE'

1 个答案:

答案 0 :(得分:0)

您有167个观察结果。你不能拥有比观察更多的细胞(20x20)。 尝试改变:

som_grid<-somgrid(xdim = 12, ydim = 12 , topo = "hexagonal")

它应该有用。