Using a single observation in a LM()

Hello All I have been working at this problem all week I am looking for some help

here is my data set

dput(RData2019)
structure(list(Game Hour = structure(c(1553785200, 1553972400,
1554044400, 1554145200, 1554231600, 1554318000, 1555095600, 1555250400,
1555354800, 1555441200, 1555527600, 1555700400, 1555786800, 1555855200,
1556650800, 1556715600, 1556910000, 1556996400, 1557064800, 1558119600,
1558191600, 1558274400, 1558378800, 1558465200, 1558530000, 1559242800,
1559329200, 1559401200, 1559484000, 1559674800, 1559761200, 1559847600,
1559934000, 1559998800, 1560024000, 1560088800, 1560798000, 1560884400,
1560970800, 1561035600, 1561143600, 1561233600, 1561298400, 1562094000,
1562180400, 1562266800, 1562871600, 1562958000, 1563044400, 1563112800,
1563303600, 1563390000, 1564513200, 1564599600, 1564772400, 1564858800,
1564927200, 1565895600, 1565982000, 1566068400, 1566136800, 1566241200,
1566306000, 1566327600, 1566410400, 1567105200, 1567191600, 1567278000,
1567346400, 1568142000, 1568228400, 1568314800, 1568401200, 1568487600,
1568556000, 1569351600, 1569438000, 1569502800, 1569610800, 1569697200,
1569765600), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
Date = structure(c(1553731200, 1553904000, 1553990400, 1554076800,
1554163200, 1554249600, 1555027200, 1555200000, 1555286400,
1555372800, 1555459200, 1555632000, 1555718400, 1555804800,
1556582400, 1556668800, 1556841600, 1556928000, 1557014400,
1558051200, 1558137600, 1558224000, 1558310400, 1558396800,
1558483200, 1559174400, 1559260800, 1559347200, 1559433600,
1559606400, 1559692800, 1559779200, 1559865600, 1559952000,
1559952000, 1560038400, 1560729600, 1560816000, 1560902400,
1560988800, 1561075200, 1561161600, 1561248000, 1562025600,
1562112000, 1562198400, 1562803200, 1562889600, 1562976000,
1563062400, 1563235200, 1563321600, 1564444800, 1564531200,
1564704000, 1564790400, 1564876800, 1565827200, 1565913600,
1.566e+09, 1566086400, 1566172800, 1566259200, 1566259200,
1566345600, 1567036800, 1567123200, 1567209600, 1567296000,
1568073600, 1568160000, 1568246400, 1568332800, 1568419200,
1568505600, 1569283200, 1569369600, 1569456000, 1569542400,
1569628800, 1569715200), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
COMP = c(NA, NA, 8, 14, 31, 35, 1, 66, 256, 211, 418, 12,
NA, 51, 413, 244, NA, 14, 158, NA, NA, 79, 643, 661, 531,
179, 15, NA, 100, 58, 48, 29, 2, NA, NA, 145, 105, 80, 213,
77, 4, 20, 364, 59, NA, NA, 175, 15, NA, 102, 40, 131, 98,
183, 8, NA, 110, 55, 8, NA, 153, 41, 28, 20, 47, 44, 2, NA,
188, 72, 85, 126, 24, NA, 319, 29, 37, 20, NA, NA, NA), DOLLAR = c(NA,
8, 11, 28, 53, 178, NA, 291, 94, 126, 299, 8, 14, NA, 550,
284, NA, 15, 318, 4, 4, 2, 136, 146, 144, 638, 2, 10, 129,
105, 73, 60, NA, 16, 63, 124, 76, 93, 252, 53, NA, 14, 375,
48, NA, 17, 408, 4, 3, NA, 79, 209, 200, 362, NA, 5, 46,
150, NA, 10, 221, 129, 124, 115, 256, 425, NA, 30, 16, 27,
221, 41, 4, 16, 100, 299, 547, 194, NA, NA, NA), GROUP = c(16105,
12544, 4797, 219, 318, 2075, 1631, 3657, 1491, 587, 658,
4245, 4803, 611, 1148, 4549, 4932, 4946, 3493, 6389, 4995,
3224, 2252, 1044, 5427, 1522, 3200, 3314, 1313, 2412, 1054,
989, 3234, 1941, 8773, 1637, 338, 1034, 2115, 2276, 3453,
5601, 1581, 334, 1424, 3156, 10897, 4233, 6199, 1449, 1389,
1391, 852, 1356, 2086, 2807, 628, 543, 2293, 2768, 568, 325,
241, 89, 464, 199, 711, 3561, 215, 1594, 786, 1175, 2375,
4312, 1942, 991, 2879, 2889, 10219, 17066, 14482), NGHTLY = c(1783,
1212, 534, 266, 432, 718, 300, 52, 358, 300, 350, 430, 640,
70, 620, 686, 554, 520, 112, 890, 838, 440, 190, 690, 961,
830, 592, 741, 120, 542, 372, 508, 458, 240, 964, 491, 498,
424, 743, 541, 664, 1000, 264, 80, 221, 544, 1436, 901, 1047,
526, 388, 621, 506, 388, 434, 865, 162, 794, 598, 454, 226,
160, 79, 220, 245, 775, 120, 394, 260, 612, 354, 648, 585,
736, 408, 1124, 985, 783, 1318, 1603, 1625), SEASON = c(22513,
16816, 17685, 15645, 15701, 15955, 15910, 16891, 13489, 14938,
13662, 16018, 16188, 15719, 13797, 14205, 14568, 17482, 17307,
17734, 16517, 16210, 13789, 13925, 12942, 15922, 15158, 17478,
15122, 14359, 14617, 13983, 14529, 15101, 17754, 14907, 16076,
14377, 15112, 12966, 15872, 15567, 15497, 15747, 14603, 17954,
18757, 16566, 16892, 17158, 14017, 16347, 14909, 14856, 14451,
17142, 14261, 15415, 15356, 16382, 13622, 14740, 14055, 13464,
15015, 13301, 15922, 14480, 16200, 14630, 15261, 13995, 15293,
14997, 16867, 16347, 18355, 16550, 17631, 17623, 21466),
SINGLE = c(10128, 16738, 14986, 2898, 2498, 4786, 8219, 7098,
3889, 2930, 2872, 16736, 20003, 11390, 4118, 5012, 7259,
10363, 11295, 11182, 10221, 13988, 3748, 4998, 4349, 9899,
14438, 7083, 6764, 5659, 6306, 6219, 8196, 6492, 13814, 4467,
5217, 4630, 6326, 3764, 11178, 13269, 5902, 5922, 14558,
26173, 8084, 12267, 20328, 10333, 4635, 10017, 5590, 7527,
11377, 11219, 4804, 4818, 7982, 12412, 5114, 3223, 3982,
2866, 4990, 3392, 8289, 17601, 6746, 2802, 4688, 3863, 11159,
14108, 9307, 5930, 8214, 5646, 7996, 8473, 12116), Day = c("Thursday",
"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Friday",
"Sunday", "Monday", "Tuesday", "Wednesday", "Friday", "Saturday",
"Sunday", "Tuesday", "Wednesday", "Friday", "Saturday", "Sunday",
"Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday", "Sunday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday", "Saturday", "Sunday", "Monday",
"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
"Sunday", "Tuesday", "Wednesday", "Thursday", "Thursday",
"Friday", "Saturday", "Sunday", "Tuesday", "Wednesday", "Tuesday",
"Wednesday", "Friday", "Saturday", "Sunday", "Thursday",
"Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday", "Sunday",
"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
"Sunday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
"Sunday"), OpeningDay = c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), OpeningWeekend = c(1,
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0), PreASB = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0), SpecEvent = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -81L))

I am trying to do a LM() with the days of the week Friday Saturday Sunday as independent Variables to help predict SINGLE attendance.

Code I am trying to Run

RData2019$Friday <- as.factor(RData2019$Friday)

this is the error i get
Error in $<-.data.frame(*tmp*, Friday, value = integer(0)) :
replacement has 0 rows, data has 81

Simply Put Friday is one of the observations in the Variable Day I am looking for a way to pull out or isolate these observations to be included in the LM()

For Record I have tried labels and Subsets and I have not been successful. Thank you for all your help in advance.

I am not sure of your goal. Do you want to make a subset of your data that has only the rows where Day == Friday? Here are two methods for doing that.

FridayOnly <- Rdata2019[Rdata2019$Day == "Friday",]
#with dplyr
library(dplyr)
FridayOnly <- filter(Rdata2019,Day == "Friday")
1 Like

It sounds like you want three dummy variables, for Friday, Saturday and Sunday. The estimated coefficients will be the differences for each of those days compared to the rest of the week (Monday, Tuesday, Wednesday and Thursday).

RData2019 |> mutate(Friday = if_else(Day == "Friday", 1, 0),
                    Saturday = if_else(Day == "Saturday", 1, 0),
                    Sunday = if_else(Day == "Sunday", 1, 0))

I copied your dput output (changing Game Hour to Game_Hour) and then ran

 RData2019$foo <- as.factor(RData2019$Day)
> unique(RData2019$foo)
[1] Thursday  Saturday  Sunday    Monday    Tuesday   Wednesday Friday   
Levels: Friday Monday Saturday Sunday Thursday Tuesday Wednesday

which seems to work fine.

Thank so much for all your help

Changing Game_hour how would i go about this

RData2019 <- rename(RData2019, Game_Hour = `Game Hour`)

@ FJCC I have tried this code

ibrary(dplyr)

Fridayonly <- Filter(RData2019,Day == "Friday")

Error I received

Error in get(as.character(FUN), mode = "function", envir = envir) :
object 'RData2019' of mode 'function' was not found

@Econ I have not tried your mutate yet but this is the error I received when using rename

RData2019 < - rename(RData2019, Game_Hour = 'Game Hour')
Error in -.POSIXt(left) : unary '-' is not defined for "POSIXt" objects

@Starz i get tripped up on the rename portion.

R is case sensitive and you want the filter() function in dplyr, not Filter() in base R.

library(dplyr)
Fridayonly <- filter(RData2019, Day == "Friday")

Also, you appear to have inserted a space between < and - when renaming, and did not use back ticks:

`Game Hour` not 'Game Hour'

@ Econ it seems like the Code worked

Code & Console result

RData2019 |> mutate(Friday = if_else(Day == "Friday",1,0),

  •                 Saturday = if_else(Day == "Saturday",1,0),
    
  •                 Sunday = if_else(Day == "Sunday",1,0))
    

A tibble: 81 × 25

Game Hour Date COMP DOLLAR GROUP

1 2019-03-28 15:00:00 2019-03-28 00:00:00 NA NA 16105
2 2019-03-30 19:00:00 2019-03-30 00:00:00 NA 8 12544
3 2019-03-31 15:00:00 2019-03-31 00:00:00 8 11 4797
4 2019-04-01 19:00:00 2019-04-01 00:00:00 14 28 219
5 2019-04-02 19:00:00 2019-04-02 00:00:00 31 53 318
6 2019-04-03 19:00:00 2019-04-03 00:00:00 35 178 2075
7 2019-04-12 19:00:00 2019-04-12 00:00:00 1 NA 1631
8 2019-04-14 14:00:00 2019-04-14 00:00:00 66 291 3657
9 2019-04-15 19:00:00 2019-04-15 00:00:00 256 94 1491
10 2019-04-16 19:00:00 2019-04-16 00:00:00 211 126 587

… with 71 more rows, and 20 more variables: NGHTLY ,

SEASON , SINGLE , Day , OpeningDay ,

OpeningWeekend , PreASB , BOSNYY ,

Holiday , DayGame , WeekdayDayGame ,

Bobblehead , Wearable , OtherGiveaway ,

Kids , Concert , SpecEvent , Friday ,

Saturday , Sunday

:information_source: Use print(n = ...) to see more rows, and colnames() to see all variable names

Then when I try to call it a Factor I get this error
Assigned data as.factor(RData2019$Friday) must be compatible with existing data.
:heavy_multiplication_x: Existing data has 81 rows.
:heavy_multiplication_x: Assigned data has 0 rows.
:information_source: Only vectors of size 1 are recycled.
Run rlang::last_error() to see where the error occurred.
Warning message:
Unknown or uninitialised column: Friday.

I realize I might not be able to factor this one in so I will just try to write in these dummies in the model and let you know what I get

Thank you Econ once I have the friday subsetted in my data is it possible to include it in my model

Okay I have the levels were do I go once I am here

unique(RData2019$foo)
[1] Thursday Saturday Sunday Monday Tuesday
[6] Wednesday Friday
7 Levels: Friday Monday Saturday Sunday Thursday ... Wednesday

Take a look at @EconProf's suggestion for making dummy variables above.

I want to begin by saying I appreciate all the help it seems like rstudio just does not want me running models with this data I have successfully gotten the filter, and levels, and dummy variables to work but I still can not run models

First code with dummy variables
Model2 <- lm(SINGLE ~ OpeningDay + Friday, data = RData2019)

Error

Model2 <- lm(SINGLE ~ OpeningDay + Friday, data = RData2019)
Error in eval(predvars, data, env) : object 'Friday' not found

what I am hoping is that i just called this out wrong

Model1 was ran with the subset

model1 <- lm(SINGLE ~ OpeningDay + Fridayonly, data = RData2019)

Error in model.frame.default(formula = SINGLE ~ OpeningDay + Fridayonly, :
invalid type (list) for variable 'Fridayonly'

Then I tried to include the Friday only subset inside the model as data

model1 <- lm(SINGLE ~ OpeningDay + Fridayonly, data = RData2019,Fridayonly)

Error in model.frame.default(formula = SINGLE ~ OpeningDay + Fridayonly, :
invalid type (list) for variable 'Fridayonly'

You guys are truly lifesavers and i appreciate all the help you have given me thus far

@EconProf showed you how to make the data only contain rows for Friday. If you want to compare Friday to other days, that's not what you want...since you need the other days there to have something to compare to.

Following @EconProf's earlier suggestion to make three dummy variables (which I think you have done successfully), try just using the Friday variable without making it into a factor.

1 Like

I have included a reprex of the linear regression with your data. The dependent variable is Single, which is a continuous variable, and the independent variables are OpeningDay and Friday, both dummies (1 or 0). There are no continuous independent variables. Is that your intention?

The estimated model has single game attendance other than opening day and Fridays equal to 7962. It is higher on opening day by 2166 and higher on Fridays by 2521.

Edit: I just noticed that there is only one game with OpeningDay = 1. That means you are estimating the effect of opening day on attendance based on just a single observation!

library(tidyverse)

RStat2019 <- structure(list(`Game Hour` = structure(c(1553785200, 1553972400,
1554044400, 1554145200, 1554231600, 1554318000, 1555095600, 1555250400,
1555354800, 1555441200, 1555527600, 1555700400, 1555786800, 1555855200,
1556650800, 1556715600, 1556910000, 1556996400, 1557064800, 1558119600,
1558191600, 1558274400, 1558378800, 1558465200, 1558530000, 1559242800,
1559329200, 1559401200, 1559484000, 1559674800, 1559761200, 1559847600,
1559934000, 1559998800, 1560024000, 1560088800, 1560798000, 1560884400,
1560970800, 1561035600, 1561143600, 1561233600, 1561298400, 1562094000,
1562180400, 1562266800, 1562871600, 1562958000, 1563044400, 1563112800,
1563303600, 1563390000, 1564513200, 1564599600, 1564772400, 1564858800,
1564927200, 1565895600, 1565982000, 1566068400, 1566136800, 1566241200,
1566306000, 1566327600, 1566410400, 1567105200, 1567191600, 1567278000,
1567346400, 1568142000, 1568228400, 1568314800, 1568401200, 1568487600,
1568556000, 1569351600, 1569438000, 1569502800, 1569610800, 1569697200,
1569765600), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
Date = structure(c(1553731200, 1553904000, 1553990400, 1554076800,
1554163200, 1554249600, 1555027200, 1555200000, 1555286400,
1555372800, 1555459200, 1555632000, 1555718400, 1555804800,
1556582400, 1556668800, 1556841600, 1556928000, 1557014400,
1558051200, 1558137600, 1558224000, 1558310400, 1558396800,
1558483200, 1559174400, 1559260800, 1559347200, 1559433600,
1559606400, 1559692800, 1559779200, 1559865600, 1559952000,
1559952000, 1560038400, 1560729600, 1560816000, 1560902400,
1560988800, 1561075200, 1561161600, 1561248000, 1562025600,
1562112000, 1562198400, 1562803200, 1562889600, 1562976000,
1563062400, 1563235200, 1563321600, 1564444800, 1564531200,
1564704000, 1564790400, 1564876800, 1565827200, 1565913600,
1.566e+09, 1566086400, 1566172800, 1566259200, 1566259200,
1566345600, 1567036800, 1567123200, 1567209600, 1567296000,
1568073600, 1568160000, 1568246400, 1568332800, 1568419200,
1568505600, 1569283200, 1569369600, 1569456000, 1569542400,
1569628800, 1569715200), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
COMP = c(NA, NA, 8, 14, 31, 35, 1, 66, 256, 211, 418, 12,
NA, 51, 413, 244, NA, 14, 158, NA, NA, 79, 643, 661, 531,
179, 15, NA, 100, 58, 48, 29, 2, NA, NA, 145, 105, 80, 213,
77, 4, 20, 364, 59, NA, NA, 175, 15, NA, 102, 40, 131, 98,
183, 8, NA, 110, 55, 8, NA, 153, 41, 28, 20, 47, 44, 2, NA,
188, 72, 85, 126, 24, NA, 319, 29, 37, 20, NA, NA, NA), DOLLAR = c(NA,
8, 11, 28, 53, 178, NA, 291, 94, 126, 299, 8, 14, NA, 550,
284, NA, 15, 318, 4, 4, 2, 136, 146, 144, 638, 2, 10, 129,
105, 73, 60, NA, 16, 63, 124, 76, 93, 252, 53, NA, 14, 375,
48, NA, 17, 408, 4, 3, NA, 79, 209, 200, 362, NA, 5, 46,
150, NA, 10, 221, 129, 124, 115, 256, 425, NA, 30, 16, 27,
221, 41, 4, 16, 100, 299, 547, 194, NA, NA, NA), GROUP = c(16105,
12544, 4797, 219, 318, 2075, 1631, 3657, 1491, 587, 658,
4245, 4803, 611, 1148, 4549, 4932, 4946, 3493, 6389, 4995,
3224, 2252, 1044, 5427, 1522, 3200, 3314, 1313, 2412, 1054,
989, 3234, 1941, 8773, 1637, 338, 1034, 2115, 2276, 3453,
5601, 1581, 334, 1424, 3156, 10897, 4233, 6199, 1449, 1389,
1391, 852, 1356, 2086, 2807, 628, 543, 2293, 2768, 568, 325,
241, 89, 464, 199, 711, 3561, 215, 1594, 786, 1175, 2375,
4312, 1942, 991, 2879, 2889, 10219, 17066, 14482), NGHTLY = c(1783,
1212, 534, 266, 432, 718, 300, 52, 358, 300, 350, 430, 640,
70, 620, 686, 554, 520, 112, 890, 838, 440, 190, 690, 961,
830, 592, 741, 120, 542, 372, 508, 458, 240, 964, 491, 498,
424, 743, 541, 664, 1000, 264, 80, 221, 544, 1436, 901, 1047,
526, 388, 621, 506, 388, 434, 865, 162, 794, 598, 454, 226,
160, 79, 220, 245, 775, 120, 394, 260, 612, 354, 648, 585,
736, 408, 1124, 985, 783, 1318, 1603, 1625), SEASON = c(22513,
16816, 17685, 15645, 15701, 15955, 15910, 16891, 13489, 14938,
13662, 16018, 16188, 15719, 13797, 14205, 14568, 17482, 17307,
17734, 16517, 16210, 13789, 13925, 12942, 15922, 15158, 17478,
15122, 14359, 14617, 13983, 14529, 15101, 17754, 14907, 16076,
14377, 15112, 12966, 15872, 15567, 15497, 15747, 14603, 17954,
18757, 16566, 16892, 17158, 14017, 16347, 14909, 14856, 14451,
17142, 14261, 15415, 15356, 16382, 13622, 14740, 14055, 13464,
15015, 13301, 15922, 14480, 16200, 14630, 15261, 13995, 15293,
14997, 16867, 16347, 18355, 16550, 17631, 17623, 21466),
SINGLE = c(10128, 16738, 14986, 2898, 2498, 4786, 8219, 7098,
3889, 2930, 2872, 16736, 20003, 11390, 4118, 5012, 7259,
10363, 11295, 11182, 10221, 13988, 3748, 4998, 4349, 9899,
14438, 7083, 6764, 5659, 6306, 6219, 8196, 6492, 13814, 4467,
5217, 4630, 6326, 3764, 11178, 13269, 5902, 5922, 14558,
26173, 8084, 12267, 20328, 10333, 4635, 10017, 5590, 7527,
11377, 11219, 4804, 4818, 7982, 12412, 5114, 3223, 3982,
2866, 4990, 3392, 8289, 17601, 6746, 2802, 4688, 3863, 11159,
14108, 9307, 5930, 8214, 5646, 7996, 8473, 12116), Day = c("Thursday",
"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Friday",
"Sunday", "Monday", "Tuesday", "Wednesday", "Friday", "Saturday",
"Sunday", "Tuesday", "Wednesday", "Friday", "Saturday", "Sunday",
"Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday", "Sunday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday", "Saturday", "Sunday", "Monday",
"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
"Sunday", "Tuesday", "Wednesday", "Thursday", "Thursday",
"Friday", "Saturday", "Sunday", "Tuesday", "Wednesday", "Tuesday",
"Wednesday", "Friday", "Saturday", "Sunday", "Thursday",
"Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday", "Sunday",
"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
"Sunday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
"Sunday"), OpeningDay = c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), OpeningWeekend = c(1,
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0), PreASB = c(1, 1, 1, 1, 1, 1, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Concert = c(0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0), SpecEvent = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -81L))

RStat2019 <- RStat2019 |> rename(GameHour = `Game Hour`)

RStat2019 <- RStat2019 |> 
  mutate(Friday = if_else(Day == "Friday", 1, 0),
         Saturday = if_else(Day == "Saturday", 1, 0),
         Sunday = if_else(Day == "Sunday", 1, 0))

RStat2019 |> lm(formula = SINGLE ~ OpeningDay + Friday)
#> 
#> Call:
#> lm(formula = SINGLE ~ OpeningDay + Friday, data = RStat2019)
#> 
#> Coefficients:
#> (Intercept)   OpeningDay       Friday  
#>        7962         2166         2521

Created on 2022-10-28 with reprex v2.0.2

2 Likes

@ ECon Thank you for your help on this . I have recopied your code from the lm() because I figured I had done the rest these are these are the error codes I recieved

Code

RStat2019 |> lm(formula = SINGLE ~ OpeningDay + Friday)

Error

Error in is.data.frame(data) : object 'RStat2019' not found

I appreciate you finding coefficients this is very helpful but what I am actually trying to do is rebuild a model made on 2019 data and I all I have is the code. so I can reproduce the data with 2022 code

here is the code I am trying to reproduce the raw data is the same as mine

Data2019$GameHour <- as.character(Data2019$GameHour)
Data2019$Date <- as.character(Data2019$Date)
Data2019$COMP <- as.integer(Data2019$COMP)
Data2019$DOLLAR <- as.integer(Data2019$DOLLAR)
Data2019$GROUP <- as.integer(Data2019$GROUP)
Data2019$NGHTLY <- as.integer(Data2019$NGHTLY)
Data2019$SEASON <- as.integer(Data2019$SEASON)
Data2019$SINGLE <- as.integer(Data2019$SINGLE)
Data2019$Day <- as.factor(Data2019$Day)
Data2019$OpeningDay <- as.factor(Data2019$OpeningDay)
Data2019$OpeningWeekend <- as.factor(Data2019$OpeningWeekend)
Data2019$PreASB <- as.factor(Data2019$PreASB)
Data2019$BOSNYY <- as.factor(Data2019$BOSNYY)
Data2019$Holiday <- as.factor(Data2019$Holiday)
Data2019$DayGame <- as.factor(Data2019$DayGame)
Data2019$WeekdayDayGame <- as.factor(Data2019$WeekdayDayGame)
Data2019$Bobblehead <- as.factor(Data2019$Bobblehead)
Data2019$Wearable <- as.factor(Data2019$Wearable)
Data2019$OtherGiveaway <- as.factor(Data2019$OtherGiveaway)
Data2019$Kids <- as.factor(Data2019$Kids)
Data2019$Concert <- as.factor(Data2019$Concert)
Data2019$SpecEvent <- as.factor(Data2019$SpecEvent)
Data2019$Friday <- as.factor(Data2019$Friday)
Data2019$Saturday <- as.factor(Data2019$Saturday)
Data2019$Sunday <- as.factor(Data2019$Sunday)

Model1 <- lm(SINGLE ~ OpeningDay + OpeningWeekend + PreASB + BOSNYY + Holiday
+ DayGame + WeekdayDayGame + Bobblehead + Wearable
+ OtherGiveaway + Kids + Concert + SpecEvent + Friday
+ Saturday + Sunday, data = Data2019)

You can't pipe the dataframe into lm(). Piping just gives the first argument to the function, which in this case would be the formula rather than the data. Try

 lm(formula = SINGLE ~ OpeningDay + Friday, data = RStat2019)