0

I am trying to solve the following problem:

A person can be classified as either GroupA, GroupB or GroupC.

I want to know how attribute1 (or attribute2) affects the proportion of observations in these groups. Note that attribute1:attribute2 has a 1:N relationship. Attribute1 has five possible values, A,B,C,D,E whilst attribute2 has two possible values: A,B.

Simulated data:

obsGroupA <- round(runif(40, 240, 63535))
obsGroupB <- round(runif(40, 2478, 95063))
obsGroupC <- round(runif(40, 3102, 104799))
propGroupA <- obsGroupA/(obsGroupA + obsGroupB + obsGroupC)
propGroupB <- obsGroupB/(obsGroupA + obsGroupB + obsGroupC)
propGroupC <- obsGroupC/(obsGroupA + obsGroupB + obsGroupC)
#propGroupA + propGroupB + propGroupC
attributeA <- c("A", "B", "C", "D", "E")[runif(40, 1, 5)]
attributeB <- ifelse(attributeA %in% c("A", "B", "E"), "A", "B")  

Model attempt:

#y <- cbind(obsGroupA, obsGroupB, obsGroupC)
y <- cbind(propGroupA, propGroupB, propGroupC)
model <- glm(y ~ attributeA)

I get the following error:

Error in x[good, , drop = FALSE] : (subscript) logical subscript too long

Any ideas how I can perform a statistical test in R?
Any references to the correct statistical test would also be appreciated.

Thanks.

2
  • You seem to have two problems: i) you don't know what you are doing from a statistical point of view, and ii) you don't know how to get R to do what you want. You will get help with i) on Cross Validated but not neccessarily ii) and you'll need to focus the question more on the what statistical approach should I use side of this question for this to be on-topic on Cross Validated. Mar 5, 2015 at 3:30
  • I'm voting to close this question as off-topic because it is not about programming in the first instance. OP needs statistical help and that will determine what needs to be done in software. Mar 5, 2015 at 3:31

1 Answer 1

1

Well, you should first look a bit into regression analysis like has been commented. You have some issues in understanding there. But, this is what you want:

obsGroupA <- round(runif(40, 240, 63535))
obsGroupB <- round(runif(40, 2478, 95063))
obsGroupC <- round(runif(40, 3102, 104799))
propGroupA <- obsGroupA/(obsGroupA + obsGroupB + obsGroupC)
propGroupB <- obsGroupB/(obsGroupA + obsGroupB + obsGroupC)
propGroupC <- obsGroupC/(obsGroupA + obsGroupB + obsGroupC)
#propGroupA + propGroupB + propGroupC
attributeA <- c("A", "B", "C", "D", "E")[runif(40, 1, 5)]
attributeB <- ifelse(attributeA %in% c("A", "B", "E"), "A", "B")

y <- data.frame(propGroupA, propGroupB, propGroupC,attributeA,attributeB)
model <- glm(propGroupA ~ attributeA ,data=y )
summary(model)
2
  • Thanks - that will do for now. I wasn't sure if there was something like a chi-squared contingency test. I suppose as @Gavin Simpson suggests, this was more of a statistical problem. I think the error I got above, was because I had 3 variables in the y <- cbind() statement. I can change this to y <- cbind(propGroupA, 1-propGroupA). As these are proportions, I believe the Statistics: An introduction using R, by Michael J. Crawely book suggests using family=binomial in the glm() statement. Mar 5, 2015 at 4:35
  • It isn't a binomial though... a binomial is a 0/1 variable. In this case you have a continuous variable as your 'y' so you don't want to change to "family = binomial". And you don't need a chi-squared. And you don't need to change y to what you suggested. Trust me. I have a PhD in economics and spent too much time on regression analysis. If you want to find the effect of the proportion of A of Attributes A & B, its PropA = AttA + AttB. If you want prop B it's PropB = AttA + AttB
    – Jason
    Mar 5, 2015 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.