0

I am working through a predictive analytics course, and I am having trouble getting a similar output with my data versus the output that was given in the sample code. My desired output is a prediction (in column d3hat) for each age group level (in column AORlevels.)

This is what is given in the code/output:

Sample code/output

This is the code/output that I am getting: My code/output

The only difference I can see between my data and the sample data is that I have an extra variable.

Here is the data I am working with:

d3

My ultimate goal of the assignment is to make a graph and interpret results--it's a predictive analytics course, but there is a heavy coding component that I am struggling with. I have taken a course in R, but it is still challenging for me to adapt another's code to fit the data I am using.

Thanks in advance for any help/advice!

Mo

I have tried matching the code exactly (changing variable names, etc.) but I still get the same result as if I were to just use the variable name itself (d3$d1.AORlevels).

Code/output using exact sample code

Using this code, I was not able to successfully create the d3hat column. The number of rows in newly created newdata1 is 4 rows (which is great), but the variable I'm trying to create with the predictions (newdata1$d3hat) has 7,836 rows (one for each observation.) This result leads me to believe that I am missing a very simple and obvious coding component that I am not aware of.

  • Hi there! Welcome to Stack Overflow. Would you be able to 1. share the code you have written, and some of your data, enough that someone else can have a go at replicating what you've done? Thank you! – Mark Jun 17 '23 at 11:27
  • Here's a guide on what to do: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Mark Jun 17 '23 at 11:28

0 Answers0