2014-06-16 8 views
5

मुझे बैयसग्ल्म का उपयोग करते समय पूर्वानुमान कार्य के साथ कुछ समस्याएं आ रही हैं। मैंने कुछ पोस्ट पढ़ी हैं जो कहते हैं कि यह समस्या उत्पन्न हो सकती है जब नमूना डेटा के बाहर नमूना डेटा की तुलना में अधिक स्तर होते हैं, लेकिन मैं फिट और पूर्वानुमान कार्यों के लिए एक ही डेटा का उपयोग कर रहा हूं। पूर्वानुमान नियमित ग्लैम के साथ ठीक काम करता है, लेकिन बेयस्ग्लम के साथ नहीं। उदाहरण:बेयस भविष्यवाणी करते हैं, सीमाओं से सब्सक्राइब

control <- y ~ x1 + x2 

# this works fine: 
glmObject <- glm(control, myData, family = binomial()) 
predicted1 <- predict.glm(glmObject , myData, type = "response") 

# this gives an error: 
bayesglmObject <- bayesglm(control, myData, family = binomial()) 
predicted2 <- predict.bayesglm(bayesglmObject , myData, type = "response") 
Error in X[, piv, drop = FALSE] : subscript out of bounds 

# Edit... I just discovered this works. 
# Should I be concerned about using these results? 
# Not sure why is fails when I specify the dataset 
predicted3 <- predict(bayesglmObject, type = "response") 

किसी बेयस्ग्लम ऑब्जेक्ट के साथ भविष्यवाणी करने का तरीका नहीं पता लगाया जा सकता है। कोई विचार? धन्यवाद!

उत्तर

2

bayesglm कमांड में पैरामीटर "drop.unused.levels" के लिए डिफ़ॉल्ट सेटिंग के साथ एक कारण हो सकता है। डिफ़ॉल्ट रूप से, यह पैरामीटर TRUE पर सेट है। इसलिए यदि अप्रयुक्त स्तर हैं, तो मॉडल निर्माण के दौरान इसे छोड़ दिया जाता है। हालांकि, पूर्वानुमान फ़ंक्शन अभी भी मूल डेटा का उपयोग कारक चर में मौजूद अप्रयुक्त स्तरों के साथ करता है। इससे मॉडल बिल्डिंग के लिए इस्तेमाल किए गए डेटा और पूर्वानुमान के लिए उपयोग किए जाने वाले डेटा के बीच स्तर में मतभेद होते हैं (यहां तक ​​कि यह वही डेटा प्रसिद्धि है - आपका मामला, myData)। मैं एक उदाहरण नीचे दिया गया है:

n <- 100 
    x1 <- rnorm (n) 
    x2 <- as.factor(sample(c(1,2,3),n,replace = TRUE)) 

    # Replacing 3 with 2 makes the level = 3 as unused 
    x2[x2==3] <- 2 

    y <- as.factor(sample(c(1,2),n,replace = TRUE)) 

    myData <- data.frame(x1 = x1, x2 = x2, y = y) 
    control <- y ~ x1 + x2 

    # this works fine: 
    glmObject <- glm(control, myData, family = binomial()) 
    predicted1 <- predict.glm(glmObject , myData, type = "response") 

    # this gives an error - this uses default drop.unused.levels = TRUE 
    bayesglmObject <- bayesglm(control, myData, family = binomial()) 
    predicted2 <- predict.bayesglm(bayesglmObject , myData, type = "response") 

    Error in X[, piv, drop = FALSE] : subscript out of bounds 

    # this works fine - value of drop.unused.levels is set to FALSE 
    bayesglmObject <- bayesglm(control, myData, family = binomial(),drop.unused.levels = FALSE) 
    predicted2 <- predict.bayesglm(bayesglmObject , myData, type = "response") 

मुझे लगता है कि एक बेहतर तरीका पहले से डेटा फ्रेम से अप्रयुक्त स्तर ड्रॉप और मॉडल के निर्माण और भविष्यवाणी दोनों के लिए इसका इस्तेमाल करने के droplevels उपयोग करने के लिए किया जाएगा।

संबंधित मुद्दे