Going from a frequency table to a burt table

时间:2015-10-30 22:45:46

标签: r

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")

1 个答案:

答案 0 :(得分:0)

您可以通过创建虚拟变量来获取Burt表。有关如何在R中执行此操作,请参见this question.