Skip to main content
Tweeted twitter.com/#!/StackStats/status/414017058922569728
added 195 characters in body
Source Link
luciano
  • 14.6k
  • 36
  • 97
  • 129

I have a predictor variable (water height in metres) and a response variable (feeding rates of birds). The relationship between them looks similar that shown in the plot below.

iris_subtidal_effect <- iris[,3:5] 4]
library(plyr); tidal_effect <- rename(tidal_effect, c("Petal.Length" = "feeding.rate", "Petal.Width" =  "water.height"))
iris_extra
tidal_effect_extra <- data.frame(Petalwater.Widthheight = sample(seq(2.5, 3, 0.1), 50, replace = T), Petalfeeding.Lengthrate = sample(seq(4, 4.5, 0.1), 50, replace = T), Species = rep("Species 4", 50))

iris_sub_extratidal_effect_extra <- rbind(iris_subtidal_effect, iris_extratidal_effect_extra)

library(ggplot2)
ggplot(iris_sub_extratidal_effect_extra, aes(Petalwater.Widthheight, Petalfeeding.Lengthrate)) + geom_point() + xlab("water.height (m)")

enter image description hereenter image description here

I'm considering cutting the predictor variablewater height into a three level factor. As can be seen in plot above, the obvious point at which to cut the predictor variable arewater height is about 0.7, 2.5 and 3, which means that the distance between the minimum/maximum values at each level of the factor are not equal

I can cut the predictor variable like this:

iris_sub_extra$Petal.Width.cut <- cut(iris_sub_extra$Petaltidal_effect_extra$water.height.cut <- cut(tidal_effect_extra$water.Widthheight, breaks = c(0, 0.7, 2.5, 3), labels = c("thin""low", "wide""mid", "very wide""high"))

And then perform this model:

lm(Petalfeeding.Lengthrate ~  Petalwater.Widthheight.cut, iris_sub_extratidal_effect_extra)

My question: is there anything wrong with cutting a predictor variablewater height into groups in which distances between the minimum/maximum values at each level of the factor are not equal?

I have a predictor variable and a response variable. The relationship between them looks similar that shown in the plot below.

iris_sub <- iris[,3:5] 
 
iris_extra <- data.frame(Petal.Width = sample(seq(2.5, 3, 0.1), 50, replace = T), Petal.Length = sample(seq(4, 4.5, 0.1), 50, replace = T), Species = rep("Species 4", 50))

iris_sub_extra <- rbind(iris_sub, iris_extra)

library(ggplot2)
ggplot(iris_sub_extra, aes(Petal.Width, Petal.Length)) + geom_point()

enter image description here

I'm considering cutting the predictor variable into a three level factor. As can be seen in plot above, the obvious point at which to cut the predictor variable are about 0.7, 2.5 and 3, which means that the distance between the minimum/maximum values at each level of the factor are not equal

I can cut the predictor variable like this:

iris_sub_extra$Petal.Width.cut <- cut(iris_sub_extra$Petal.Width, breaks = c(0, 0.7, 2.5, 3), labels = c("thin", "wide", "very wide"))

And then perform this model:

lm(Petal.Length ~  Petal.Width.cut, iris_sub_extra)

My question: is there anything wrong with cutting a predictor variable into groups in which distances between the minimum/maximum values at each level of the factor are not equal?

I have a predictor variable (water height in metres) and a response variable (feeding rates of birds). The relationship between them looks similar that shown in the plot below.

tidal_effect <- iris[,3:4]
library(plyr); tidal_effect <- rename(tidal_effect, c("Petal.Length" = "feeding.rate", "Petal.Width" =  "water.height"))

tidal_effect_extra <- data.frame(water.height = sample(seq(2.5, 3, 0.1), 50, replace = T), feeding.rate = sample(seq(4, 4.5, 0.1), 50, replace = T))

tidal_effect_extra <- rbind(tidal_effect, tidal_effect_extra)

library(ggplot2)
ggplot(tidal_effect_extra, aes(water.height, feeding.rate)) + geom_point() + xlab("water.height (m)")

enter image description here

I'm considering cutting water height into a three level factor. As can be seen in plot above, the obvious point at which to cut water height is about 0.7, 2.5 and 3, which means that the distance between the minimum/maximum values at each level of the factor are not equal

I can cut the predictor variable like this:

tidal_effect_extra$water.height.cut <- cut(tidal_effect_extra$water.height, breaks = c(0, 0.7, 2.5, 3), labels = c("low", "mid", "high"))

And then perform this model:

lm(feeding.rate ~  water.height.cut, tidal_effect_extra)

My question: is there anything wrong with cutting water height into groups in which distances between the minimum/maximum values at each level of the factor are not equal?

Source Link
luciano
  • 14.6k
  • 36
  • 97
  • 129

Ok to cut continuous variable into irregular intervals?

I have a predictor variable and a response variable. The relationship between them looks similar that shown in the plot below.

iris_sub <- iris[,3:5] 
 
iris_extra <- data.frame(Petal.Width = sample(seq(2.5, 3, 0.1), 50, replace = T), Petal.Length = sample(seq(4, 4.5, 0.1), 50, replace = T), Species = rep("Species 4", 50))

iris_sub_extra <- rbind(iris_sub, iris_extra)

library(ggplot2)
ggplot(iris_sub_extra, aes(Petal.Width, Petal.Length)) + geom_point()

enter image description here

I'm considering cutting the predictor variable into a three level factor. As can be seen in plot above, the obvious point at which to cut the predictor variable are about 0.7, 2.5 and 3, which means that the distance between the minimum/maximum values at each level of the factor are not equal

I can cut the predictor variable like this:

iris_sub_extra$Petal.Width.cut <- cut(iris_sub_extra$Petal.Width, breaks = c(0, 0.7, 2.5, 3), labels = c("thin", "wide", "very wide"))

And then perform this model:

lm(Petal.Length ~  Petal.Width.cut, iris_sub_extra)

My question: is there anything wrong with cutting a predictor variable into groups in which distances between the minimum/maximum values at each level of the factor are not equal?