Search code examples
rglmlm

Error in model.frame.default(formula = y ~ ., data = Peak_data, drop.unused.levels = TRUE) : variable lengths differ (found for 'GSP')


It is an error related to variable lengths differing. I have read previous forums in regards to this but I am not too sure if they apply to me. I have 6 independent variables and TCMD as my dependent variable and a samples size of 10. I am trying to undertake Akaike Criterion Information for my data using:

library("MASS")
Peak_data <- read.table(text="GSP   ACPEN   SOLPEN  NOH  ASP    EPI TCMD
361 0   0   2497838.8   11276.06    79.7    14828.45
369 0   0   2471221     14200.75    86.9    14483.62
375 0   1   2497838.8   15756.69    100     12445.13
384 0   1   2524456.6   19674.65    119.3   13060.37
392 0   1   2551074.4   15613.37    123.5   13000.04
402 0   1   2577692.2   14292.03    114.5   13308.07
410 0   1   2604310     21585.35    109.3   14038.92
418 0   1   2630927.8   34850.07    120.8   15258.51
421 1   1   2657545.6   30050.26    136.6   13933.98
431 1   1   2684163.4   30969.31    135.2   14236.64
",header = T)
full <- lm(y~., data = Peak_data)
Error in model.frame.default(formula = y ~ ., data = Peak_data, drop.unused.levels = TRUE) : 


variable lengths differ (found for 'GSP')

I get this error preventing me from performing backwards AIC using:

stepAIC(full, direction='backward')

Any help is much appreciated!

Thanks in advance!


Solution

  • Your code syntax is correct but the dependent variable naming is wrong. You can use the following code

    library("MASS")
    full <- lm(TCMD~., data = Peak_data)
    stepAIC(full, direction='backward')