2

I need to transform my dataset into a burt table, I just don't know how to do it because I only know how with the indicator matrix.

This is what my data looks like

          GEO                    IDENTITY            AGE  SEX Value
3649 Atlantic Total , Aboriginal identity 18 to 24 years Male   950
3653 Atlantic Total , Aboriginal identity 18 to 24 years Male   506
3657 Atlantic Total , Aboriginal identity 18 to 24 years Male     0
3661 Atlantic Total , Aboriginal identity 18 to 24 years Male     0
3665 Atlantic Total , Aboriginal identity 18 to 24 years Male     0
3669 Atlantic Total , Aboriginal identity 18 to 24 years Male   950
3673 Atlantic Total , Aboriginal identity 18 to 24 years Male     0
3677 Atlantic Total , Aboriginal identity 18 to 24 years Male     0
3681 Atlantic Total , Aboriginal identity 18 to 24 years Male     0
3685 Atlantic Total , Aboriginal identity 18 to 24 years Male     0

There a thousand combinations with the frequency in the last column and I don't know how to manipulate this data frame to get an indicator matrix or get a burt table directly.

more info on my data after trying to use

 matdata2 = model.matrix(mydata2)
Error in terms.default(object) : no terms component nor attribute

to transform into an indicator matrix.

 dput(head(mydata2))
structure(list(Ref_Date = c(2012L, 2012L, 2012L, 2012L, 2012L, 
2012L), GEO = structure(c(2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Alberta", 
"Atlantic", "British Columbia", "Canada", "Manitoba", "Northwest Territories", 
"Nunavut", "Ontario", "Quebec", "Saskatchewan", "Yukon"), class = "factor"), 
    IDENTITY = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("First Nations (North American Indian)", 
    "First Nations (North American Indian), not a Registered or Treaty Indian", 
    "First Nations (North American Indian), Registered or Treaty Indian", 
    "Inuk (Inuit)", "Métis", "Total , Aboriginal identity"), class = "factor"), 
    AGE = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("18 to 24 years", 
    "25 to 54 years", "55 years and over", "Total, 18 years and over"
    ), class = "factor"), SEX = structure(c(3L, 3L, 3L, 3L, 3L, 
    3L), .Label = c("Both sexes", "Female", "Male"), class = "factor"), 
    HEALTH = structure(c(2L, 4L, 3L, 12L, 1L, 10L), .Label = c("Ever seriously considered committing suicide", 
    "Excellent or very good perceived mental health", "Fair or poor perceived mental health", 
    "Good perceived mental health", "Never seriously considered committing suicide", 
    "Not specified, seriously considered committing suicide", 
    "Not specified, seriously considered committing suicide in the past 12 months", 
    "Perceived mental health not specified", "Seriously considered committing suicide but not in the past 12 months", 
    "Seriously considered committing suicide in the past 12 months", 
    "Total, perceived mental health", "Total, suicidal thoughts"
    ), class = "factor"), Value = c(2190, 2572, 2572, 355, 2572, 
    2572)), .Names = c("Ref_Date", "GEO", "IDENTITY", "AGE", 
"SEX", "HEALTH", "Value"), row.names = c(4229L, 4233L, 4237L, 
4245L, 4249L, 4253L), class = "data.frame")
Revoltic
  • 121
  • 2
  • 1
    what's a burt table? `model.matrix` is the way to get an indicator matrix ... – Ben Bolker Oct 30 '15 at 23:21
  • i dont think i can turn this data into and indicator using `model.matrix`, at least its not working with my data set It doesnt seem to be able to deal with my categorical variables? – Revoltic Oct 31 '15 at 00:14
  • we need more information/ a reproducible example. What does "not working" mean? What did you try with `model.matrix`? Can you use `dput(head(your_data_set))` to provide us with more complete information ? – Ben Bolker Oct 31 '15 at 00:20
  • matdata2 = model.matrix(mydata2) Error in terms.default(object) : no terms component nor attribute – Revoltic Oct 31 '15 at 01:00
  • That's not how `model.matrix` works! From http://stackoverflow.com/questions/25412897/r-change-categorical-data-to-dummy-variables : `model.matrix(~ -1 + . , data=mydata2, contrasts.arg = lapply(wholedata[sapply(mydata2, is.factor)], contrasts, contrasts=FALSE)) ` – Ben Bolker Oct 31 '15 at 02:12

1 Answers1

0

You can get a Burt table by creating dummy variables. See this question. for how to do this in R.

Heladio Amaya
  • 968
  • 10
  • 20