Warning Errors on R studio when running trying to compute Akaike Information Criterion

rgwings

I am new to Rstudio and Stack and am trying to calculate the AIC for my model with 8 variables (One dummy) but only 10 observations (Not sure if this is the issue). The code I have run so far is:

library("MASS")

energy_data <- read.table('energy.txt', header = T)
full <- lm(y~., data = energy_data)

Following this, I get the warning

Warning messages:

1: In model.response(mf, "numeric") :
  using type = "numeric" with a factor response will be ignored
2: In Ops.factor(y, z$residuals) : ‘-’ not meaningful for factors

I have looked at other forum threads but I am not sure if they apply in my case.

I have also tried to run this as a CSV file but in this case I get the error:

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

Again this has been asked before but I am unsure how to address in my case.txt data CSV data

Thanks in advance!

Sam Dickson

The problem is the , in the y column, which causes it to be a factor. You can fix it by removing the , using gsub, but in order to do that you have to change it to character first. Once you remove the ,, you'll need to change it to numeric.

library(MASS)

energy_data <- read.table(text="x1  x2  x3  x4  x5  x6  x7  x8  y
361 79.7    2.983013699 1.683972603 4.35    2573.2  2048    0   77,465.59
369 86.9    2.814684932 1.701424658 4.7 2599    2094.5  0   76,705.04
375 100 2.780956284 2.006202186 3.7 2634.2  2141    0.5 72,704.99
384 119.3   3.594931507 1.448   2.75    2669.4  2266    1   70,061.93
392 123.5   3.354246575 1.522657534 2.5 2704.6  2391    0.5 69,587.52
402 114.5   3.17438562  1.653780822 2.1 2739.8  2418    0   70,138.85
410 109.3   3.691912568 1.346284153 1.75    2775    2445    0   70,405.99
418 120.8   3.725232877 1.818520548 1.5 2859.7  2586    0   70,879.50
421 136.6   3.681369863 1.79890411  1.5 2944.4  2726    0   70,436.26
431 135.2   3.960821918 1.959369863 1.2 3029.1  2867    0   70,161.83", header=T, sep="\t")

energy_data$y <- as.numeric(gsub(",","",as.character(energy_data$y)))
full <- lm(y~., data = energy_data)

You can also solve it by editing the file you read in to remove ,.

energy_data <- read.table(text="x1  x2  x3  x4  x5  x6  x7  x8  y
361 79.7    2.983013699 1.683972603 4.35    2573.2  2048    0   77465.59
369 86.9    2.814684932 1.701424658 4.7 2599    2094.5  0   76705.04
375 100 2.780956284 2.006202186 3.7 2634.2  2141    0.5 72704.99
384 119.3   3.594931507 1.448   2.75    2669.4  2266    1   70061.93
392 123.5   3.354246575 1.522657534 2.5 2704.6  2391    0.5 69587.52
402 114.5   3.17438562  1.653780822 2.1 2739.8  2418    0   70138.85
410 109.3   3.691912568 1.346284153 1.75    2775    2445    0   70405.99
418 120.8   3.725232877 1.818520548 1.5 2859.7  2586    0   70879.50
421 136.6   3.681369863 1.79890411  1.5 2944.4  2726    0   70436.26
431 135.2   3.960821918 1.959369863 1.2 3029.1  2867    0   70161.83", header=T, sep="\t")

full <- lm(y~., data = energy_data)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Is the akaike information criterion (AIC) unit-dependent?

Errors when running my code in Android Studio

ionic framework: errors when trying running "ionic upload" command

SEM with lavaan in R, problems specifying model with correlated subscales. WARNING: Could not compute standard errors

Encountering " WARN ProcfsMetricsGetter: Exception when trying to compute pagesize" error when running Spark

Compiler Errors when trying to install a button in android studio

compileClassPAth errors when trying to add library in android studio

Errors occuring when running simple Hello World in Visual Studio 2017

Compile error when running cargo bench (criterion/serde)

Printing check mark is triggering warning when running R cmd checks

Calculate Akaike Information Criteria (AIC) by hand in Python

Eclipse not giving warning when running java code which has compilation errors

Errors when running program

Keep getting errors when trying to knit a PDF using R Markdown

Errors when trying to create and use a random permutation test function in R

error when trying to do a running sum in r with sqldf

Errors when trying to use ValueListenableBuilder

Errors when trying to run Arduino

Errors when trying to connect to kubernetes

R Studio: print output when running interactively but not when knitting

Constantly getting 0 when trying to compute pi

Errors when running Crystal Play

Blank screen when running and no errors

Errors when running tests in parallel

(Visual Studio) Lot of linker errors when trying to link microsoft libraries statically with SFML libs

Visual Studio 16.8.2 - Analyzer with Code Fix project template produces errors when trying to debug unit test

Bunch of errors when trying to build app on android studio. How to fix?

Warning errors when adding line breaks to email?

Trying to display stats in table form, keep getting "Warning: validateDOMNesting(...):" errors