2
我試圖將模型擬合到數據集中的每個位置。我運行下面的代碼(用樣品重新鏡像我使用的數據):錯誤:執行rlm時變量的類型(列表)無效
library(plyr)
library(MASS)
month.abbr <- c("Jan", "Feb", "Mar", "Apr", "May",
"Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
month <- factor(rep(month.abbr, length = 1200), levels = month.abbr)
county_code <- sample(1:100, 1200, replace = T)
store_rev <- sample(2000:85000, 1200, replace = T)
color_levels <-c('blue', 'red', 'green')
colors <- factor(rep(color_levels, length = 1200), levels = color_levels)
data <- data.frame(month, county_code, store_rev, colors)
product_aggregate_values <-ddply(data, ~month+county_code+colors, summarise, total_rev = sum(store_rev))
deseasf <- function(total_rev) rlm(total_rev~month-1, maxit = 50)
models <- ddply(product_aggregate_values, ~county_code + colors, deseasf)
failed <- ddply(models, function(x) !x$converged)
而且我得到以下錯誤:
Error: invalid type (list) for variable 'total_rev'
我想可能是因爲我使用product_aggregate_values作爲data.frame,但是當我嘗試使用daply創建它,並相應地調整代碼,我收到以下錯誤:
Error in splitter_a(.data, .margins, .expand) :
'pairlist' object cannot be coerced to type 'integer'
Error in inherits(.data, "split") : object 'models' not found
請花時間讓您的示例[reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)。提供一個樣本'數據'對象,以便我們知道您正在使用的對象類型。理想情況下,我們可以將您的代碼複製/粘貼到R中,並獲得與您相同的錯誤。這會讓你更容易幫助你。 – MrFlick 2015-01-20 19:11:12