पारित होने पर पारित होने पर मैंने question से डेटा का विश्लेषण करने के बारे में पूछा लेकिन महीने तक डेटा को कताई करके नकली स्पाइक्स और कटोरे उत्पन्न नहीं करना चाहते थे। उदाहरण के लिए यदि कोई प्रत्येक महीने के आखिरी दिन बिल चुकाता है लेकिन एक मौके पर कुछ दिन देर से भुगतान करता है तो एक महीने शून्य व्यय को प्रतिबिंबित करेगा और अगले महीने सामान्य खर्च को दोगुना कर देगा। सभी नकली जंक।संचयी योग प्लॉट पर नियमित समय बिंदुओं पर एक इंटरपोलेशन की ढलानों को मैं कैसे प्राप्त करूं?
मेरे प्रश्न में answers में से एक ने बाइनिंग में हिकोओं को दूर करने के लिए संचयी योग पर रैखिक स्पलीन चिकनाई का उपयोग करके इंटरपोलेशन की अवधारणा को समझाया। मैं इसके बारे में चिंतित हूं और इसे आर में लागू करना चाहता हूं लेकिन ऑनलाइन कोई उदाहरण नहीं मिल रहा है। मैं सिर्फ भूखंड मुद्रित नहीं करना चाहता हूं। मैं प्रत्येक बार बिंदु (शायद हर दिन) पर तात्कालिक ढलान प्राप्त करना चाहता हूं लेकिन उस ढलान को एक स्पिन से लिया जाना चाहिए जो कुछ दिनों से पहले कुछ बिंदुओं (या शायद कुछ हफ्तों या कुछ महीने) से इनपुट इनपुट करता है समय बिंदु के बाद। दूसरे शब्दों में, के अंत में मैं डेटा फ्रेम जैसे कुछ प्राप्त करना चाहता हूं जिसमें एक कॉलम प्रति दिन या प्रति सप्ताह मरीज़ है लेकिन यह अनियमितताओं के अधीन नहीं है जैसे कि मैंने कुछ दिन देर से भुगतान किया है या क्या महीने में 5 ऑपरेटिव दिन होने के कारण (सामान्य 4 के विपरीत)।
यहां कुछ सरल सिमुलेशन और साजिश है जो मैं दिखा रहा हूं कि मैं क्या कर रहा हूं।
library(lubridate)
library(ggplot2)
library(reshape2)
dates <- seq(as.Date("2010-02-01"), length=24, by="1 month") - 1
dates[5] <- dates[5]+3 #we are making one payment date that is 3 days late
dates#look how the payment date is the last day of every month except for
#2010-05 where it takes place on 2010-06-03 - naughty boy!
amounts <- rep(50,each=24)# pay $50 every month
register <- data.frame(dates,amounts)#this is the starting register or ledger
ggplot(data=register,aes(dates,amounts))+geom_point()#look carefully and you will see that 2010-05 has no dots in it and 2010-06 has two dots
register.by.month <- ddply(register,.(y=year(dates),month=month(dates)),summarise,month.tot=sum(amounts))#create a summary of totals by month but it lands up omiting a month in which nothing happened. Further badness is that it creates a new dataframe where one is not needed. Instead I created a new variable that allocates each date into a particular "zone" such as month or
register$cutmonth <- as.Date(cut(register$dates, breaks = "month"))#until recently I did not know that the cut function can handle dates
table(register$cutmonth)#see how there are two payments in the month of 2010-06
#now lets look at what we paid each month. What is the total for each month
ggplot(register, aes(cutmonth, amounts))+ stat_summary(fun.y = sum, geom = "bar")#that is the truth but it is a useless truth
#so lets use cummulated expense over time
register$cumamount <- cumsum(register$amounts)
cum <- ggplot(data=register,aes(dates,cumamount))+geom_point()
cum+stat_smooth()
#That was for everything the same every month, now lets introduce a situation where there is a trend that in the second year the amounts start to go up,
increase <- c(rep(1,each=12),seq(from=1.01,to=1.9,length.out=12))
amounts.up <- round(amounts*increase,digits=2)#this is the monthly amount with a growth of amount in each month of the second year
register <- cbind(register,amounts.up)#add the variable to the data frarme
register$cumamount.up <- cumsum(register$amounts.up) #work out th cumulative sum for the new scenario
ggplot(data=register,aes(x=dates))+
geom_point(aes(y=amounts, colour="amounts",shape="amounts"))+
geom_point(aes(y=amounts.up, colour="amounts.up",shape="amounts.up"))# the plot of amount by date
#I am now going to plot the cumulative amount over time but now that I have two scenarios it is easier to deal with the data frame in long format (melted) rather than wide format (casted)
#before I can melt, the reshape2 package unforutnately can't handle date class so will have to turn them int o characters and then back again.
register[,c("dates","cutmonth")] <- lapply(register[,c("dates","cutmonth")],as.character)
register.long <- melt.data.frame(register,measure.vars=c("amounts","amounts.up"))
register.long[,c("dates","cutmonth")] <- lapply(register.long[,c("dates","cutmonth")],as.Date)
ggplot(register.long, aes(cutmonth,value))+ stat_summary(fun.y = sum, geom = "bar")+facet_grid(. ~ variable) #that is the truth but it is a useless truth,
cum <- ggplot(data=register,aes(dates,cumamount))+geom_point()
#that is the truth but it is a useless truth. Furthermore it appears as if 2010-06 is similar to what is going on in 2011-12
#that is patently absurd. All that happened was that the 2010-05 payment was delayed by 3 days.
#so lets use cummulated expense over time
ggplot(data=register.long,aes(dates,c(cumamount,cumamount.up)))+geom_point() + scale_y_continuous(name='cumulative sum of amounts ($)')
तो सरल साजिश के लिए परिवर्तनीय interpolate.daily वर्ष के हर दिन के लिए लगभग $ 50/30.4 = $ 1.64 प्रति दिन होगा। दूसरी साजिश के लिए जहां हर महीने भुगतान की जाने वाली राशि दूसरे महीने में हर महीने बढ़ने लगती है, पहले वर्ष में प्रत्येक दिन प्रति दिन $ 1.64 की दैनिक दर दिखाएगी और दूसरे वर्ष की तारीखों में दैनिक दरों को देखेंगे धीरे-धीरे $ 1.64 प्रति दिन से $ 3.12 प्रति दिन बढ़ रहा है।
अंत तक इस तरह से पढ़ने के लिए आपको बहुत बहुत धन्यवाद। जैसा कि मैं था, तुम इतनी चिंतित होनी चाहिए!
मुझे लगता है कि आप बुरी सलाह मिला - यह करने के लिए किया जाएगा एक अधिक सामान्य सांख्यिकीय रास्ता कर्नेल घनत्व अनुमान का उपयोग करने के लिए। – hadley
@ हडली मेरे प्रश्न के उत्तरदाताओं में से एक [घनत्व अनुमान और कर्नल के बारे में बात की थी] (http://stats.stackexchange.com/a/2737/104)। हां, मुझे यह बहुत कुछ समझ में नहीं आया और उन्होंने मैटलैब में एक कार्यान्वयन प्रदान किया जिसे मैंने कभी काम नहीं किया है। – Farrel
वैसे यह ggplot2 में छोटा है - बस 'geom = "घनत्व का उपयोग करें" ' – hadley