5 दिनों के भीतर है और अभी भी कोई जवाब नहीं का उपयोग कर वस्तु त्रुटि गुमजब कदम() उपयोगकर्ता परिभाषित समारोह
- के रूप में साइमन की इस टिप्पणी से देखा जा सकता है, यह एक प्रतिलिपि प्रस्तुत करने योग्य और बहुत ही अजीब मुद्दा है। ऐसा लगता है कि यह मुद्दा केवल तब उठता है जब एक उच्च गतिशील शक्ति के साथ एक कदमवार प्रतिगमन एक समारोह में लपेटा जाता है।
मैं थोड़ी देर के लिए इसके साथ संघर्ष कर रहा हूं और किसी भी मदद की सराहना की जाएगी। मैं एक ऐसा फ़ंक्शन लिखने की कोशिश कर रहा हूं जो कई कदमवार प्रतिक्रियाओं को चलाता है और उन सभी को एक सूची में आउटपुट करता है। हालांकि, आर को मेरे कार्य तर्कों में निर्दिष्ट डेटासेट पढ़ने में परेशानी हो रही है। मुझे विभिन्न बोर्डों (here, here, और here) पर कई समान त्रुटियां मिलीं, हालांकि उनमें से कोई भी कभी हल नहीं हुआ। यह उपयोगकर्ता द्वारा परिभाषित फ़ंक्शन में चरण() को कॉल करने के साथ कुछ अजीब मुद्दों पर आता है। मैं अपने कोड का परीक्षण करने के लिए निम्न स्क्रिप्ट का उपयोग कर रहा हूं। पूरी बात कई बार चलाने के लिए जब तक एक त्रुटि पैदा होती है (मुझ पर भरोसा, यह):
test.df <- data.frame(a = sample(0:1, 100, rep = T),
b = as.factor(sample(0:5, 100, rep = T)),
c = runif(100, 0, 100),
d = rnorm(100, 50, 50))
test.df$b[10:100] <- test.df$a[10:100] #making sure that at least one of the variables has some predictive power
stepModel <- function(modeling.formula, dataset, outfile = NULL) {
if (is.null(outfile) == FALSE){
sink(file = outfile,
append = TRUE, type = "output")
print("")
print("Models run at:")
print(Sys.time())
}
model.initial <- glm(modeling.formula,
family = binomial,
data = dataset)
model.stepwise1 <- step(model.initial, direction = "backward")
model.stepwise2 <- step(model.stepwise1, scope = ~.^2)
output <- list(modInitial = model.initial, modStep1 = model.stepwise1, modStep2 = model.stepwise2)
sink()
return(output)
}
blah <- stepModel(a~., dataset = test.df)
यह निम्न त्रुटि संदेश देता है (यदि त्रुटि अभी दिखाई नहीं देता, रखने के लिए फिर से चल रहा test.df स्क्रिप्ट के साथ-साथ stepModel() के लिए कॉल, यह अंततः दिखाई देगा):
Error in is.data.frame(data) : object 'dataset' not found
मैं निर्धारित किया है जब तक model.stepwise2 बनाया करने के लिए शुरू होता है कि सब कुछ ठीक ऊपर चलाता है। किसी भी तरह, अस्थायी वस्तु 'डेटासेट' पहले चरणबद्ध प्रतिगमन के लिए ठीक काम करता है, लेकिन दूसरे द्वारा मान्यता प्राप्त होने में विफल रहता है। मैंने इसे फंक्शन के हिस्से पर टिप्पणी करके पाया, जैसा कि नीचे देखा जा सकता है। इस कोड को ठीक चलेगा, साबित करते हुए कि वस्तु 'डाटासेट' मूल रूप से पहचाना जा रहा था:
stepModel1 <- function(modeling.formula, dataset, outfile = NULL) {
if (is.null(outfile) == FALSE){
sink(file = outfile,
append = TRUE, type = "output")
print("")
print("Models run at:")
print(Sys.time())
}
model.initial <- glm(modeling.formula,
family = binomial,
data = dataset)
model.stepwise1 <- step(model.initial, direction = "backward")
# model.stepwise2 <- step(model.stepwise1, scope = ~.^2)
# sink()
# output <- list(modInitial = model.initial, modStep1 = model.stepwise1, modStep2 = model.stepwise2)
return(model.stepwise1)
}
blah1 <- stepModel1(a~., dataset = test.df)
संपादित - इससे पहले कि किसी को भी पूछता है, सब सारांश() फ़ंक्शन वहाँ थे क्योंकि पूर्ण समारोह (मैं यह इतना संपादित कि आप त्रुटि पर ध्यान केंद्रित कर सकते हैं) में एक और टुकड़ा है जो एक फ़ाइल को परिभाषित करता है जिसमें आप चरणबद्ध ट्रेस आउटपुट कर सकते हैं। मैं सिर्फ उन्हें से छुटकारा मिला
संपादित 2 - सत्र की जानकारी
sessionInfo() आर संस्करण 2.15.1 (2012-06-22) प्लेटफार्म: x86_64-पीसी-mingw32/64 (64-बिट)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] tcltk stats graphics grDevices utils datasets methods base
other attached packages:
[1] sqldf_0.4-6.4 RSQLite.extfuns_0.0.1 RSQLite_0.11.3 chron_2.3-43
[5] gsubfn_0.6-5 proto_0.3-10 DBI_0.2-6 ggplot2_0.9.3.1
[9] caret_5.15-61 reshape2_1.2.2 lattice_0.20-6 foreach_1.4.0
[13] cluster_1.14.2 plyr_1.8
loaded via a namespace (and not attached):
[1] codetools_0.2-8 colorspace_1.2-1 dichromat_2.0-0 digest_0.6.2 grid_2.15.1
[6] gtable_0.1.2 iterators_1.0.6 labeling_0.1 MASS_7.3-18 munsell_0.4
[11] RColorBrewer_1.0-5 scales_0.2.3 stringr_0.6.2 tools_2.15
संपादित 3 - यह, समारोह के रूप में सभी एक ही आपरेशन प्रदर्शन करती है तो बस एक समारोह का उपयोग किए बिना। यह ठीक हर बार चलेंगे, तब भी जब एल्गोरिथ्म अभिसरण नहीं करता है:
modeling.formula <- a~.
dataset <- test.df
outfile <- NULL
if (is.null(outfile) == FALSE){
sink(file = outfile,
append = TRUE, type = "output")
print("")
print("Models run at:")
print(Sys.time())
}
model.initial <- glm(modeling.formula,
family = binomial,
data = dataset)
model.stepwise1 <- step(model.initial, direction = "backward")
model.stepwise2 <- step(model.stepwise1, scope = ~.^2)
output <- list(modInitial = model.initial, modStep1 = model.stepwise1, modStep2 = model.stepwise2)
मैंने इस त्रुटि को पुन: उत्पन्न करने की कोशिश की और ऐसा नहीं कर सका। मैं विंडोज 7 पर आर 2.15.3 64-बिट चला रहा हूं और यह कार्य संतोषजनक रूप से तब तक चला जब तक कि यह 'सिंक()' पर कॉल तक नहीं पहुंच गया, जिस बिंदु पर यह 'सिंक() में: निकालने के लिए कोई सिंक नहीं हुआ। क्या आप कह सकते हैं कि आप किस संस्करण का उपयोग कर रहे हैं? – Simon
@ सिमॉन - मैं सिर्फ अपने फ़ंक्शन में आउटफाइल तर्क डालता हूं। इसने त्रुटि मेरे लिए फिर से दिखाई दी। मैं अब प्रश्न के लिए सिस्टम और सत्र जानकारी जोड़ रहा हूं। – zap2008
अब यह बेहद अजीब है ... त्रुटि यादृच्छिक रूप से दिखाई दे रही है। अगर मैं 10 बार अपना कोड चलाता हूं तो यह दो बार हो जाता है ... – zap2008