Skip to main content
replaced http://stats.stackexchange.com/ with https://stats.stackexchange.com/
Source Link

I have two datasets:

  1. a $1*m$ matrix of "ideal" conditions for $m$ factors
  2. a $n*m$ matrix of $n$ observations (rows) for each of the $m$ factors

I would like to calculate for each observation in the second matrix, how far it is from the "ideal" condition. So the output would be $n$ values that represent "distances" from ideal conditions.

First question, is the Mahalanobis distance appropriate to use here? The $m$ factors are spatial in nature, and are related to each other.

Second question, how do I set this up in R? I have tried a few examples with mahalanobis(), mahalanobis.dist(), and pairwise.mahalnobis(), but I cannot see how these can be used with my example. When I've tried to use my matrices with these functions, I get an error:

Error in solve.default(cov, ...) : 
  Lapack routine dgesv: system is exactly singular: U[8,8] = 0

Which I have come to understand means that one of my matrices is singular and therefore cannot be inverted. I am not entirely sure how to get around this issue, or if it needs to be gotten around at all for my purposes.

I have also read this threadthis thread, but it's a bit over my head.

The overall goal of this is to use the results to map out "ideal" habitat ranges for a particular species.

Any help, thoughts, or suggestions would be greatly appreciated!

I have two datasets:

  1. a $1*m$ matrix of "ideal" conditions for $m$ factors
  2. a $n*m$ matrix of $n$ observations (rows) for each of the $m$ factors

I would like to calculate for each observation in the second matrix, how far it is from the "ideal" condition. So the output would be $n$ values that represent "distances" from ideal conditions.

First question, is the Mahalanobis distance appropriate to use here? The $m$ factors are spatial in nature, and are related to each other.

Second question, how do I set this up in R? I have tried a few examples with mahalanobis(), mahalanobis.dist(), and pairwise.mahalnobis(), but I cannot see how these can be used with my example. When I've tried to use my matrices with these functions, I get an error:

Error in solve.default(cov, ...) : 
  Lapack routine dgesv: system is exactly singular: U[8,8] = 0

Which I have come to understand means that one of my matrices is singular and therefore cannot be inverted. I am not entirely sure how to get around this issue, or if it needs to be gotten around at all for my purposes.

I have also read this thread, but it's a bit over my head.

The overall goal of this is to use the results to map out "ideal" habitat ranges for a particular species.

Any help, thoughts, or suggestions would be greatly appreciated!

I have two datasets:

  1. a $1*m$ matrix of "ideal" conditions for $m$ factors
  2. a $n*m$ matrix of $n$ observations (rows) for each of the $m$ factors

I would like to calculate for each observation in the second matrix, how far it is from the "ideal" condition. So the output would be $n$ values that represent "distances" from ideal conditions.

First question, is the Mahalanobis distance appropriate to use here? The $m$ factors are spatial in nature, and are related to each other.

Second question, how do I set this up in R? I have tried a few examples with mahalanobis(), mahalanobis.dist(), and pairwise.mahalnobis(), but I cannot see how these can be used with my example. When I've tried to use my matrices with these functions, I get an error:

Error in solve.default(cov, ...) : 
  Lapack routine dgesv: system is exactly singular: U[8,8] = 0

Which I have come to understand means that one of my matrices is singular and therefore cannot be inverted. I am not entirely sure how to get around this issue, or if it needs to be gotten around at all for my purposes.

I have also read this thread, but it's a bit over my head.

The overall goal of this is to use the results to map out "ideal" habitat ranges for a particular species.

Any help, thoughts, or suggestions would be greatly appreciated!

Bumped by Community user
Bumped by Community user
Tweeted twitter.com/StackStats/status/716193802415943680
Changed lay-out and formatted code. Also added a tag which is hopefully appropriate.
Source Link

I have two datasets: 1) a [1 x m] matrix of "Ideal" conditions for m factors, and 2) a [n x m] matrix of n observations (rows) for each of the m factors.

  1. a $1*m$ matrix of "ideal" conditions for $m$ factors
  2. a $n*m$ matrix of $n$ observations (rows) for each of the $m$ factors

I would like to calculate, for each observation in the second matrix, how far it is from the "Ideal""ideal" condition. So So the output would be n$n$ values that represent "distances" from ideal conditions.

First question, is the Mahalanobis distance appropriate to use here? The m The $m$ factors are spatial in nature, and are related to each other.

Second question, how do I set this up in R? I I have tried a few examples with mahalanobis()mahalanobis(), mahalanobis.dist()mahalanobis.dist(), and pairwise.mahalnobis()pairwise.mahalnobis(), but I cannot see how these can be used with my example. When When I've tried to use my matrices with these functions, I get an error:

Error in solve.default(cov, ...) : 
  Lapack routine dgesv: system is exactly singular: U[8,8] = 0

Which I have come to understand means that one of my matrices is singular and therefore cannot be inverted. I I am not entirely sure how to get around this issue, or if it needs to be gotten around at all for my purposes.

I have also read this thread, but it's a bit over my head.

The overall goal of this is to use the results to map out "Ideal""ideal" habitat ranges for a particular species.

Any help, thoughts, or suggestions would be greatly appreciated!

I have two datasets: 1) a [1 x m] matrix of "Ideal" conditions for m factors, and 2) a [n x m] matrix of n observations (rows) for each of the m factors.

I would like to calculate, for each observation in the second matrix, how far it is from the "Ideal" condition. So the output would be n values that represent "distances" from ideal conditions.

First question, is the Mahalanobis distance appropriate to use here? The m factors are spatial in nature, and are related to each other.

Second question, how do I set this up in R? I have tried a few examples with mahalanobis(), mahalanobis.dist(), and pairwise.mahalnobis(), but I cannot see how these can be used with my example. When I've tried to use my matrices with these functions, I get an error:

Error in solve.default(cov, ...) : 
  Lapack routine dgesv: system is exactly singular: U[8,8] = 0

Which I have come to understand means that one of my matrices is singular and therefore cannot be inverted. I am not entirely sure how to get around this issue, or if it needs to be gotten around at all for my purposes.

I have also read this thread, but it's a bit over my head.

The overall goal of this is to use the results to map out "Ideal" habitat ranges for a particular species.

Any help, thoughts, or suggestions would be greatly appreciated!

I have two datasets:

  1. a $1*m$ matrix of "ideal" conditions for $m$ factors
  2. a $n*m$ matrix of $n$ observations (rows) for each of the $m$ factors

I would like to calculate for each observation in the second matrix, how far it is from the "ideal" condition. So the output would be $n$ values that represent "distances" from ideal conditions.

First question, is the Mahalanobis distance appropriate to use here? The $m$ factors are spatial in nature, and are related to each other.

Second question, how do I set this up in R? I have tried a few examples with mahalanobis(), mahalanobis.dist(), and pairwise.mahalnobis(), but I cannot see how these can be used with my example. When I've tried to use my matrices with these functions, I get an error:

Error in solve.default(cov, ...) : 
  Lapack routine dgesv: system is exactly singular: U[8,8] = 0

Which I have come to understand means that one of my matrices is singular and therefore cannot be inverted. I am not entirely sure how to get around this issue, or if it needs to be gotten around at all for my purposes.

I have also read this thread, but it's a bit over my head.

The overall goal of this is to use the results to map out "ideal" habitat ranges for a particular species.

Any help, thoughts, or suggestions would be greatly appreciated!

Source Link

How to set up a Mahalanobis distance problem in R

I have two datasets: 1) a [1 x m] matrix of "Ideal" conditions for m factors, and 2) a [n x m] matrix of n observations (rows) for each of the m factors.

I would like to calculate, for each observation in the second matrix, how far it is from the "Ideal" condition. So the output would be n values that represent "distances" from ideal conditions.

First question, is the Mahalanobis distance appropriate to use here? The m factors are spatial in nature, and are related to each other.

Second question, how do I set this up in R? I have tried a few examples with mahalanobis(), mahalanobis.dist(), and pairwise.mahalnobis(), but I cannot see how these can be used with my example. When I've tried to use my matrices with these functions, I get an error:

Error in solve.default(cov, ...) : 
  Lapack routine dgesv: system is exactly singular: U[8,8] = 0

Which I have come to understand means that one of my matrices is singular and therefore cannot be inverted. I am not entirely sure how to get around this issue, or if it needs to be gotten around at all for my purposes.

I have also read this thread, but it's a bit over my head.

The overall goal of this is to use the results to map out "Ideal" habitat ranges for a particular species.

Any help, thoughts, or suggestions would be greatly appreciated!