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:
- How would I go about detecting whether or not there is a line in any sample I'm looking at?
- How would I go about detecting the slope and intercept of the line if it is there?
- How much more tricky does this problem get if the noise does not come from some known distribution but has to be estimated?