ANOSIM: Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) - vegan

I am trying to perform Anosim {vegan} on my ecological data and I keep getting the same error message. I don't think this is a duplicate question from another one already posted and would like to fully show what's happening.
I have got my numeric dataframe ("sps") consisting of 17 rows (sites) and 313 columns (species), and a second dataframe ("env.data") containing a column with 17 factors. I would therefore want to test if there are any significant differences between my 17 groups.
Here is a sample of my data:
> sps[,2:5]
A. faranauti A. tecta A. lyra A. arbuscula
Sargasso Sea 0 0 2 0
Equatorial Brazil 0 0 0 0
Canarias Sea 0 0 0 0
Corner Seamounts 0 0 0 2
Gulf of Mexico 0 0 0 0
Labrador Sea 0 0 0 0
Equatorial Africa 0 0 0 0
Tropic Seamount 0 0 0 107
NewEngland Seamount Chain 0 0 0 0
Norwegian Basin 0 0 0 0
Eastern North Atlantic 0 0 3 0
Logachev and BritishIsles 0 0 0 4
Reykjanes Ridge 0 0 0 0
MAR North 0 0 0 14
Flemish Cap 0 0 0 217
MAR South 1 1 0 0
Azores Seamount Chain 0 0 0 12
> class(sps)
[1] "data.frame"
> head(env.data)
idcell geo_area
1 1 Sargasso Sea
2 2 Equatorial Brazil
3 3 Canarias Sea
4 4 Corner Seamounts
5 5 Gulf of Mexico
6 6 Labrador Sea
> str(env.data)
'data.frame': 17 obs. of 2 variables:
$ idcell : Factor w/ 17 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
$ geo_area: Factor w/ 17 levels "Canarias Sea",..: 15 5 1 2 7 8 4 17 12 13..
Following {vegan}, I have first calculated a dissimilarity matrix with Sorensen as the distance method. I then use this dissimilarity matrix as my input for anosim:
dist.sorensen <- vegdist(sps, method= "bray", binary = TRUE, na.rm= TRUE,
diag = TRUE)
sorensen.anosim <- anosim(dat=dist.sorensen, env.data$geo_area, permutations
= 999)
> summary(sorensen.anosim )
Call:
anosim(dat = dist.sorensen, grouping = env.data$geo_area, permutations =
999)
Dissimilarity: binary bray
ANOSIM statistic R:
Significance: 0.001
Permutation: free
Number of permutations: 999
Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) :
'x' must be atomic
I have also tried anosim with the raw species data and I get the same error:
raw.anosim <- anosim(sps, env.data$geo_area, permutations = 999, distance =
"bray")
Any ideas? My "sps" dataframe (x) is numeric. My "env.data" dataset (groupings) has a factor column with 17 levels. I can't see where the error comes from, unless it's intrinsic to my data. Many of the 313 species listed in my original dataframe have been recorded only once across my 17 sites (very probably due to sampling bias). However, I get clusters after performing "vegdist (Sorensen index)" and "hclust".

Related

Why are the eigenvalues of eig() sorted in ascending order?

I'm trying to find eigenvalues of a matrix with eig.
I define the matrix with example data:
A = magic(5)
A =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
and
D = eig(A,'matrix')
D =
65.0000 0 0 0 0
0 -21.2768 0 0 0
0 0 -13.1263 0 0
0 0 0 21.2768 0
0 0 0 0 13.1263
But if I use
C = cov(A)
and get eigenvalues from the covariance matrix, this is the result:
DC = eig(C,'matrix')
DC =
-0.0000 0 0 0 0
0 35.4072 0 0 0
0 0 44.9139 0 0
0 0 0 117.5861 0
0 0 0 0 127.0928
Why are the eigenvalues from the covariance matrix sorted in ascending order?
Sorting is merely a choice of convenience. There's no such thing as a 'real' position of an eigenvector, just as (x,y) is just as valid as (y,x). Since a lot of matrix techniques work on eigenvectors in order of decreasing eigenvalue (i.e. most important first), it makes sense to structure them accordingly.

Convert Group of Picture structure to the appropriate one for HEVC HM encoder

I'm using HM-16 and Scalable HM 12.3.
I have this GOP order as seen below. As you can see I have QP value for each slice type.
Encode Order Type POC QP
0 I-SLICE 0 23
1 P-SLICE 3 26
2 B-SLICE 2 27
3 b-SLICE 1 28
4 P-SLICE 6 26
5 B-SLICE 5 27
6 b-SLICE 4 28
And I want to convert it to a code like the following where I must define QPoffset CbQPoffset CrQPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2 temporal_id #ref_pics_active #ref_pics reference pictures predict deltaRPS #ref_idcs reference idcs.
# Type POC QPoffset CbQPoffset CrQPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2 temporal_id #ref_pics_active #ref_pics reference pictures predict deltaRPS #ref_idcs reference idcs
Frame1: P 16 1 0 0 0.6 0 0 0 2 3 -16 -24 -32 0
Frame2: B 8 2 0 0 0.2 0 0 1 2 3 -8 -16 8 1 8 4 1 1 0 1
Can you please help me to convert it?
Is there any other way to define the number of B-frames or b-frames in a GOP?
I found the solution considering HM reference manual.
I reorder the frames starting from a B-frame considering only one reference frame. All B frames reference previous I-frame or P-frames.
The new GOP structure is the one below.
It's important to mention here, that a B-frame can't have a P-frame that is encoded later. More explicitly, a B-frame with POC number e.g. 1 can't reference a P-frame with a grater value of POC number e.g. 3.
# Type POC QPoffset CbQPoffset CrQPoffset QPfactor tcOffsetDiv2 betaOffsetDiv2 temporal_id #ref_pics_active #ref_pics reference pictures predict deltaRPS #ref_idcs reference idcs
Frame1: B 1 2 0 0 0.4624 0 0 0 1 1 -1 0
Frame2: B 2 1 0 0 0.4624 0 0 0 1 1 -2 2 1
Frame3: P 3 0 0 0 0.4624 0 0 0 1 1 -3 2 2
Frame4: B 4 2 0 0 0.4624 0 0 0 1 1 -1 2 2
Frame5: B 5 1 0 0 0.4624 0 0 0 1 1 -2 2 3
Frame6: P 6 0 0 0 0.4624 0 0 0 1 1 -3 2 3

Create a matrix from a vector such that its height and width are powers of multiples in matlab

I have tried multiple solutions in matlab to convert a vector for example
A = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]
into
B= [ 1 2 3 4 ]
5 6 7 8
9 10 11 12
13 14 15 16
17 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
Here the desired matrix is 8x4 or rather the height or width is any multiple of 4. This would mean the nearest greater multiple of 4 if we keep any one dimension(height or width) fixed for fitting all elements and padding the extra elements with zeroes. I have tried reshape like so
reshape([c(:) ; zeros(rem(nc - rem(numel(c),nc),nc),1)],nc,[])
Here c is the original vector or matrix, nc is the number of columns.
It simply changes the number of rows and cols but does not take into account the possible powers required by the condition for height and width. I don't have the Communications Toolbox which has the vec2mat function.
Another possible alternative thought is to initialize a matrix with all zeroes and then assign. But at this point I'm stuck. So please help me matlab experts.
i think this what you mean:
n = 4;
A = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17];
B = zeros(n,ceil(numel(A)/n^2)*n);
B(1:numel(A)) = A;
B = B'
B = [ 1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0]

Matlab:How to find the indices of rows without any zero in a matrix?

How to find the indices of rows without any zero in a matrix?
Example:
A = [
14 0 6 9 8 17
85 14 1 3 0 99
0 0 0 0 0 0
29 4 5 8 7 46
0 0 0 0 0 0
17 0 5 0 0 49
]
the desired result :
V =[4]
Since Adiel did not post an answer, I'll make their comment a CW: the command
V = find(all(A,2))
does the job, because all(A,2) processes every row, returning 1 if there are any nonzero entries. Then find returns the indices of nonzero entries, which are the desired row numbers.
Similarly, V = find(all(A,1)) works column-wise.

MATLAB, what is the best way to trace a boarder in a matrix that is changing each step?

I want to calculate the average slope or gradient at each iteration in such a matrix.
a=[ 10 9 8 7 6 5 5;
9 9 8 7 8 5 5;
8 8 7 7 5 5 5;
7 7 7 6 5 5 5;
6 6 6.6 5 5 5 5;
6 6 6.1 5 5 5 5;
6.3 5 5 5 5 5 5]
Where I am wanting to find the slope or gradient between the a(1,1) position during each step and at each point that boarders a value of 5. Each iteration the position of the 5's changes and so do the other values.
After doing so I will then average the slope. I haven't encountered a problem like this yet and I could not find a Matlab command to simplify.
First you must find out which the coast elements are. From your definition, an element is a coast element if it border (from the right) with a 5. If the sea level is 5, and is the lowest possible value i.e. no element goes beyond sea level, then you must first find all the land elements as,
land=a>5;
This returns,
ans =
1 1 1 1 1 0 0
1 1 1 1 1 0 0
1 1 1 1 0 0 0
1 1 1 1 0 0 0
1 1 1 0 0 0 0
1 1 1 0 0 0 0
1 0 0 0 0 0 0
Now, the coast elements are 1s that are followed by a 0. Take the column difference of the land matrix,
coastTmp=diff(land,1,2);
returning,
ans =
0 0 0 0 -1 0
0 0 0 0 -1 0
0 0 0 -1 0 0
0 0 0 -1 0 0
0 0 -1 0 0 0
0 0 -1 0 0 0
-1 0 0 0 0 0
and find the -1s,
coast=find(coastTmp==-1);
which are,
coast =
7
19
20
24
25
29
30
From here it is easy. The gradient is the difference of a(1,1) with all the coast elements, i.e.
slope=a(coast)-a(1,1); % negative slope here
giving,
slope =
-3.700000000000000
-3.400000000000000
-3.900000000000000
-3.000000000000000
-4.000000000000000
-4.000000000000000
-2.000000000000000
and of course the mean is,
mean(slope);