In: Statistics and Probability
What are the values you get from "data[,1]" and "data[,2]" in r code?
Are the values from "data[,1]" are the fitted values/ yhat values?
When I try "fitted(data)" I get different values from "data[,1]", I am very confused.
When we use the data[,1] or data[,2] on a data frame, it just
returns all the rows in the data frame along with the first and
second rows respectively. Rows and columns in a data frame in R can
be accessed with their indices . That is the whole data frame is
thus data[,]. Specifying values in rows or columns as indices helps
in accessing rows or columns as required from the data
frame.
Below I ll try to explain the variations or effects of using
fitted(data) function.
The fitted function returns the y hat value associated with the
data used to fit the model. Thus once the fit function is used, the
value that we get for data[,1] may actually be different
.
the fitted function returns the y hat values associated with the data used to fit the model. Because of the same reason the result that we get for data [,1] once the model is fitted may be different. In this connect you may also want to look into the predict function. The predict function helps in predicting the values for a new set of values. If you don’t specify a new set of predictor set of variables, turn it will use the dataset that was already fed into and this may be the reason why the confusion which you said is occurring to you is happening.