Skip to main content
fixed buggy code
Source Link
RoyalTS
  • 233
  • 2
  • 15

I have repeated samples from the following process: Most samples will only contain points that are randomly distributed on a 2-dimensional plane. Sometimes, however, the sample will contain not only randomly distributed points but also some points that will be arranged roughly on a line. I say roughly because the points I observe may not all be on the line exactly but be randomly displaced somewhat. Here's the R code for a little toy example to demonstrate what I mean:

line_active <- TRUE

line_n <- 50
noise_n <- 100
perturbation.sd <- 0.01

# background noise
noise_x <- runif(noise_n)
noise_y <- runif(noise_n)

# line coordinates
start <- list(x=0.2,y=0.1)
end <- list(x=0.8,y=0.9)

if(line_active) {
  line_pos <- runif(line_n)
  line_x <- start$x+line_pos*(end$x - start$x)
  line_y <- start$y+line_pos*(end$y - start$y)
  
  line_x_perturbed <- line_x+rnorm(length(line_x),0,perturbation.sd)
  line_y_perturbed <- line_y+rnorm(length(line_y),0,perturbation.sd)
} else {
  line_x_perturbed <- c()
  line_y_perturbed <- c()
}

points <- data.frame(x=all_xx=c(noise_x,y=all_yline_x_perturbed),y=c(noise_y,line_y_perturbed))

# plot!
plot(points$x,points$y)
points(line_x_perturbed,line_y_perturbed,col='red')

My questions are:

  1. How would I go about detecting whether or not there is a line in any sample I'm looking at?
  2. How would I go about detecting the slope and intercept of the line if it is there?
  3. How much more tricky does this problem get if the noise does not come from some known distribution but has to be estimated?

I have repeated samples from the following process: Most samples will only contain points that are randomly distributed on a 2-dimensional plane. Sometimes, however, the sample will contain not only randomly distributed points but also some points that will be arranged roughly on a line. I say roughly because the points I observe may not all be on the line exactly but be randomly displaced somewhat. Here's the R code for a little toy example to demonstrate what I mean:

line_active <- TRUE

line_n <- 50
noise_n <- 100
perturbation.sd <- 0.01

# background noise
noise_x <- runif(noise_n)
noise_y <- runif(noise_n)

# line coordinates
start <- list(x=0.2,y=0.1)
end <- list(x=0.8,y=0.9)

if(line_active) {
  line_pos <- runif(line_n)
  line_x <- start$x+line_pos*(end$x - start$x)
  line_y <- start$y+line_pos*(end$y - start$y)
  
  line_x_perturbed <- line_x+rnorm(length(line_x),0,perturbation.sd)
  line_y_perturbed <- line_y+rnorm(length(line_y),0,perturbation.sd)
} else {
  line_x_perturbed <- c()
  line_y_perturbed <- c()
}

points <- data.frame(x=all_x,y=all_y)

# plot!
plot(points$x,points$y)
points(line_x_perturbed,line_y_perturbed,col='red')

My questions are:

  1. How would I go about detecting whether or not there is a line in any sample I'm looking at?
  2. How would I go about detecting the slope and intercept of the line if it is there?
  3. How much more tricky does this problem get if the noise does not come from some known distribution but has to be estimated?

I have repeated samples from the following process: Most samples will only contain points that are randomly distributed on a 2-dimensional plane. Sometimes, however, the sample will contain not only randomly distributed points but also some points that will be arranged roughly on a line. I say roughly because the points I observe may not all be on the line exactly but be randomly displaced somewhat. Here's the R code for a little toy example to demonstrate what I mean:

line_active <- TRUE

line_n <- 50
noise_n <- 100
perturbation.sd <- 0.01

# background noise
noise_x <- runif(noise_n)
noise_y <- runif(noise_n)

# line coordinates
start <- list(x=0.2,y=0.1)
end <- list(x=0.8,y=0.9)

if(line_active) {
  line_pos <- runif(line_n)
  line_x <- start$x+line_pos*(end$x - start$x)
  line_y <- start$y+line_pos*(end$y - start$y)
  
  line_x_perturbed <- line_x+rnorm(length(line_x),0,perturbation.sd)
  line_y_perturbed <- line_y+rnorm(length(line_y),0,perturbation.sd)
} else {
  line_x_perturbed <- c()
  line_y_perturbed <- c()
}

points <- data.frame(x=c(noise_x,line_x_perturbed),y=c(noise_y,line_y_perturbed))

# plot!
plot(points$x,points$y)
points(line_x_perturbed,line_y_perturbed,col='red')

My questions are:

  1. How would I go about detecting whether or not there is a line in any sample I'm looking at?
  2. How would I go about detecting the slope and intercept of the line if it is there?
  3. How much more tricky does this problem get if the noise does not come from some known distribution but has to be estimated?
made the code slightly more R-like
Source Link
RoyalTS
  • 233
  • 2
  • 15

I have repeated samples from the following process: Most samples will only contain points that are randomly distributed on a 2-dimensional plane. Sometimes, however, the sample will contain not only randomly distributed points but also some points that will be arranged roughly on a line. I say roughly because the points I observe may not all be on the line exactly but be randomly displaced somewhat. Here's the R code for a little toy example to demonstrate what I mean:

line_active <- TRUE    

line_n <- 50
noise_n <- 100
perturbation.sd <- 0.01    

# background noise
noise_x <- runif(noise_n)
noise_y <- runif(noise_n)    

# line coordinates
start <- list(x=0.2,y=0.1)
end <- list(x=0.8,y=0.9)    

if(line_active) {
  line_pos <- runif(line_n)
  line_x <- start$x+line_pos*(end$x - start$x)
  line_y <- start$y+line_pos*(end$y - start$y)
  
  line_x_perturbed <- line_x+rnorm(length(line_x),0,perturbation.sd)
  line_y_perturbed <- line_y+rnorm(length(line_y),0,perturbation.sd)
} else {
  line_x_perturbed <- c()
  line_y_perturbed <- c()
}    

all_x <- c(noise_x,line_x_perturbed)
all_ypoints <- cdata.frame(noise_yx=all_x,line_y_perturbedy=all_y)    

# plot!
plot(all_x,all_ypoints$x,points$y)
points(line_x_perturbed,line_y_perturbed,col='red')

My questions are:

  1. How would I go about detecting whether or not there is a line in any sample I'm looking at?
  2. How would I go about detecting the slope and intercept of the line if it is there?
  3. How much more tricky does this problem get if the noise does not come from some known distribution but has to be estimated?

I have repeated samples from the following process: Most samples will only contain points that are randomly distributed on a 2-dimensional plane. Sometimes, however, the sample will contain not only randomly distributed points but also some points that will be arranged roughly on a line. I say roughly because the points I observe may not all be on the line exactly but be randomly displaced somewhat. Here's the R code for a little toy example to demonstrate what I mean:

line_active <- TRUE    

line_n <- 50
noise_n <- 100
perturbation.sd <- 0.01    

# background noise
noise_x <- runif(noise_n)
noise_y <- runif(noise_n)    

# line coordinates
start <- list(x=0.2,y=0.1)
end <- list(x=0.8,y=0.9)    

if(line_active) {
  line_pos <- runif(line_n)
  line_x <- start$x+line_pos*(end$x - start$x)
  line_y <- start$y+line_pos*(end$y - start$y)
  
  line_x_perturbed <- line_x+rnorm(length(line_x),0,perturbation.sd)
  line_y_perturbed <- line_y+rnorm(length(line_y),0,perturbation.sd)
} else {
  line_x_perturbed <- c()
  line_y_perturbed <- c()
}    

all_x <- c(noise_x,line_x_perturbed)
all_y <- c(noise_y,line_y_perturbed)    

# plot!
plot(all_x,all_y)
points(line_x_perturbed,line_y_perturbed,col='red')

My questions are:

  1. How would I go about detecting whether or not there is a line in any sample I'm looking at?
  2. How would I go about detecting the slope and intercept of the line if it is there?
  3. How much more tricky does this problem get if the noise does not come from some known distribution but has to be estimated?

I have repeated samples from the following process: Most samples will only contain points that are randomly distributed on a 2-dimensional plane. Sometimes, however, the sample will contain not only randomly distributed points but also some points that will be arranged roughly on a line. I say roughly because the points I observe may not all be on the line exactly but be randomly displaced somewhat. Here's the R code for a little toy example to demonstrate what I mean:

line_active <- TRUE

line_n <- 50
noise_n <- 100
perturbation.sd <- 0.01

# background noise
noise_x <- runif(noise_n)
noise_y <- runif(noise_n)

# line coordinates
start <- list(x=0.2,y=0.1)
end <- list(x=0.8,y=0.9)

if(line_active) {
  line_pos <- runif(line_n)
  line_x <- start$x+line_pos*(end$x - start$x)
  line_y <- start$y+line_pos*(end$y - start$y)
  
  line_x_perturbed <- line_x+rnorm(length(line_x),0,perturbation.sd)
  line_y_perturbed <- line_y+rnorm(length(line_y),0,perturbation.sd)
} else {
  line_x_perturbed <- c()
  line_y_perturbed <- c()
}

points <- data.frame(x=all_x,y=all_y)

# plot!
plot(points$x,points$y)
points(line_x_perturbed,line_y_perturbed,col='red')

My questions are:

  1. How would I go about detecting whether or not there is a line in any sample I'm looking at?
  2. How would I go about detecting the slope and intercept of the line if it is there?
  3. How much more tricky does this problem get if the noise does not come from some known distribution but has to be estimated?
edited tags
Link
RoyalTS
  • 233
  • 2
  • 15
Source Link
RoyalTS
  • 233
  • 2
  • 15
Loading