Skip to main content
edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
deleted 145 characters in body
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

I'm trying to create a function that will calculate an Ht-Index for Quantifying the Fractal or Scaling Structure of Geographic Features (but am new to R)

which basically just finds nested means of continuous data (raster in this case) and separates them into 2 groups: heads and tails (values above and below the means). The Ht-Index is the number of times (-1) the 'heads' group can be subdivided without being greater than some threshold (e.g., 45%) of the distribution of both groups. I'm not sure how to efficiently do this in R but here is my failed attempt which creates an infinite loop iterating over the same input.

edited:

 
require(raster)
  
foo <- raster('/foobar.img')

hindex <- function(x){
iCounter <-0
repeat{
    head <- x[x>mean(x)]  # need to replace x each iteration for head and tail
    tail <- x[x<mean(x)]  
    headpct <- length(head)/sum(length(head),length(tail)) 
    if (headpct >.45) break # If head is > 45% of values stop
        else
            if (length(head)== 1) break # if head is only one value stop
    x <- head
    iCounter <- iCounter+1
    }
return(iCounter-1) 
}

Pretty straightforward problem. Any help would be greatly appreciated, especially with the loop syntax to prevent infinite loop over same inputs.

I'm trying to create a function that will calculate an Ht-Index for Quantifying the Fractal or Scaling Structure of Geographic Features (but am new to R)

which basically just finds nested means of continuous data (raster in this case) and separates them into 2 groups: heads and tails (values above and below the means). The Ht-Index is the number of times (-1) the 'heads' group can be subdivided without being greater than some threshold (e.g., 45%) of the distribution of both groups. I'm not sure how to efficiently do this in R but here is my failed attempt which creates an infinite loop iterating over the same input.

edited:

require(raster)
  
foo <- raster('/foobar.img')

hindex <- function(x){
iCounter <-0
repeat{
    head <- x[x>mean(x)]  # need to replace x each iteration for head and tail
    tail <- x[x<mean(x)]  
    headpct <- length(head)/sum(length(head),length(tail)) 
    if (headpct >.45) break # If head is > 45% of values stop
        else
            if (length(head)== 1) break # if head is only one value stop
    x <- head
    iCounter <- iCounter+1
    }
return(iCounter-1) 
}

Pretty straightforward problem. Any help would be greatly appreciated, especially with the loop syntax to prevent infinite loop over same inputs.

I'm trying to create a function that will calculate an Ht-Index for Quantifying the Fractal or Scaling Structure of Geographic Features (but am new to R)

which basically just finds nested means of continuous data (raster in this case) and separates them into 2 groups: heads and tails (values above and below the means). The Ht-Index is the number of times (-1) the 'heads' group can be subdivided without being greater than some threshold (e.g., 45%) of the distribution of both groups. I'm not sure how to efficiently do this in R but here is my failed attempt which creates an infinite loop iterating over the same input.

 
require(raster)
  
foo <- raster('/foobar.img')

hindex <- function(x){
iCounter <-0
repeat{
    head <- x[x>mean(x)]  # need to replace x each iteration for head and tail
    tail <- x[x<mean(x)]  
    headpct <- length(head)/sum(length(head),length(tail)) 
    if (headpct >.45) break # If head is > 45% of values stop
        else
            if (length(head)== 1) break # if head is only one value stop
    x <- head
    iCounter <- iCounter+1
    }
return(iCounter-1) 
}
deleted 20 characters in body
Source Link
KennyC
  • 115
  • 1
  • 7

I'm trying to create a function that will calculate an Ht-Index for Quantifying the Fractal or Scaling Structure of Geographic Features (but am new to R)

which basically just finds nested means of continuous data (raster in this case) and separates them into 2 groups: heads and tails (values above and below the means). The Ht-Index is the number of times (-1) the 'heads' group can be subdivided without being greater than some threshold (e.g., 45%) of the distribution of both groups. I'm not sure how to efficiently do this in R but here is my failed attempt which creates an infinite loop iterating over the same input.

editededited:

require(raster)
  
foo <- raster('/foobar.img')

hindex <- function(x){
repeat{
    iCounter <-0
repeat{
    head <- x[x>mean(x)]  # need to replace x each iteration for head and tail
    tail <- x[x<mean(x)]  
    headpct <- length(head)/sum(length(head),length(tail)) # Percentage of values that are in head
    if (headpct >.45) break # If head is > 45% of values stop
        else
            if (length(head)== 1) break # if head is only one value stop
    x <- head
    iCounter <- iCounter+1
    }
return(iCounter-1) 
}

Pretty straightforward problem. Any help would be greatly appreciated, especially with the loop syntax to prevent infinite loop over same inputs.

I'm trying to create a function that will calculate an Ht-Index for Quantifying the Fractal or Scaling Structure of Geographic Features (but am new to R)

which basically just finds nested means of continuous data (raster in this case) and separates them into 2 groups: heads and tails (values above and below the means). The Ht-Index is the number of times (-1) the 'heads' group can be subdivided without being greater than some threshold (e.g., 45%) of the distribution of both groups. I'm not sure how to efficiently do this in R but here is my failed attempt which creates an infinite loop iterating over the same input.

edited:

require(raster)
  
foo <- raster('/foobar.img')

hindex <- function(x){
repeat{
    iCounter <-0
    head <- x[x>mean(x)]  # need to replace x each iteration for head and tail
    tail <- x[x<mean(x)]  
    headpct <- length(head)/sum(length(head),length(tail)) # Percentage of values that are in head
    if (headpct >.45) break # If head is > 45% of values stop
        else
            if (length(head)== 1) break # if head is only one value stop
    iCounter <- iCounter+1
    }
return(iCounter-1) 
}

Pretty straightforward problem. Any help would be greatly appreciated, especially with the loop syntax to prevent infinite loop over same inputs.

I'm trying to create a function that will calculate an Ht-Index for Quantifying the Fractal or Scaling Structure of Geographic Features (but am new to R)

which basically just finds nested means of continuous data (raster in this case) and separates them into 2 groups: heads and tails (values above and below the means). The Ht-Index is the number of times (-1) the 'heads' group can be subdivided without being greater than some threshold (e.g., 45%) of the distribution of both groups. I'm not sure how to efficiently do this in R but here is my failed attempt which creates an infinite loop iterating over the same input.

edited:

require(raster)
  
foo <- raster('/foobar.img')

hindex <- function(x){
iCounter <-0
repeat{
    head <- x[x>mean(x)]  # need to replace x each iteration for head and tail
    tail <- x[x<mean(x)]  
    headpct <- length(head)/sum(length(head),length(tail)) 
    if (headpct >.45) break # If head is > 45% of values stop
        else
            if (length(head)== 1) break # if head is only one value stop
    x <- head
    iCounter <- iCounter+1
    }
return(iCounter-1) 
}

Pretty straightforward problem. Any help would be greatly appreciated, especially with the loop syntax to prevent infinite loop over same inputs.

added 56 characters in body
Source Link
KennyC
  • 115
  • 1
  • 7
Loading
added 1 character in body
Source Link
KennyC
  • 115
  • 1
  • 7
Loading
deleted 43 characters in body
Source Link
KennyC
  • 115
  • 1
  • 7
Loading
added 61 characters in body; edited title
Source Link
KennyC
  • 115
  • 1
  • 7
Loading
edited tags; edited title
Link
KennyC
  • 115
  • 1
  • 7
Loading
Source Link
KennyC
  • 115
  • 1
  • 7
Loading