Question

In: Statistics and Probability

What are the values you get from "data[,1]" and "data[,2]" in r code? Are the values...

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.

Solutions

Expert Solution

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.


Related Solutions

Answer IN R CODE to get the following. Using the data below, Create a scatterplot of...
Answer IN R CODE to get the following. Using the data below, Create a scatterplot of y vs x Fit a simple linear regression model using y as the response and plot the regression line (with the data) Test whether x is a significant predictor and create a 95% CI around the slope coefficient. Report and interpret the coefficient of determination. For x=20, create a CI for E(Y|X=20). For x=150, can you use the model to estimate E(Y|X=150)? Discuss. Does...
APPLIED STATISTICS 2 USE R CODE! SHOW R CODE Use data file RecordMath2526.txt, to produce a...
APPLIED STATISTICS 2 USE R CODE! SHOW R CODE Use data file RecordMath2526.txt, to produce a plot graph with Exam1 as x, Exam2 as y, use Gender as color, and Hw1 as pch. RecordMath2526 information Index Gender Hw1 Hw2 Hw3 Exam1 Hw4 Exam2 Hw5 Hw6 Hw7 Final 1 F 9 6 8 60 7 82 10 10 9 69 2 M 10 10 10 94 9 98 10 10 8 91 3 M 9 10 8 79 9 55 10...
Here is the R code for running a t-test: t.test( numeric vector of data values, another...
Here is the R code for running a t-test: t.test( numeric vector of data values, another optional numeric vector of data values,        alternative = c("two.sided", "less", "greater"),        mu = Ho, paired = c(TRUE, FALSE), var.equal = c(TRUE,FALSE),conf.level =1-) 1.) Suppose 30 students are all taking the same Math 115 and English 101 classes at CSUN. You want to know in which class students tend to do better. The data below represents the class averages of the students in both classes....
Here is the R code for running a t-test: t.test( numeric vector of data values, another...
Here is the R code for running a t-test: t.test( numeric vector of data values, another optional numeric vector of data values,        alternative = c("two.sided", "less", "greater"),        mu = Ho, paired = c(TRUE, FALSE), var.equal = c(TRUE,FALSE),conf.level =1-) 2) You want to determine if the average height of men in California is greater than the average height of men in Nebraska. You take a random sample of 30 men in California and 30 men in Nebraska. The data below represents...
How do you get from Power = work/time to Power = v^2/r ?
How do you get from Power = work/time to Power = v^2/r ?
Given the data set (treatments 1 to 4) with respective outcome, what is the R code...
Given the data set (treatments 1 to 4) with respective outcome, what is the R code I can use to Find a 95 percent confidence interval on the mean strength of the 4 techniques. Also for finding a 95 percent confidence interval on the difference in means. (i.e 1 vs 3 , 2 vs 4 etc) strength group 3129 1 3000 1 2865 1 2890 1 3200 2 3300 2 2975 2 3150 2 2800 3 2900 3 2985 3...
Instructions tell you how to get the data in R R has built in dataset called...
Instructions tell you how to get the data in R R has built in dataset called Iris. This famous (Fisher's or Anderson's) iris data set gives the measurements in centimeters of the variables sepal length and width and petal length and width, respectively, for 50 flowers from each of 3 species of iris. The species are Iris setosa, versicolor, and virginica. We are interested in estimating the length of Petal (Y) using the length of Sepal (X). First, load the...
How do you load a simple data series onto R? For instance, data values that are...
How do you load a simple data series onto R? For instance, data values that are down below: Below are the batting averages of 20 batting champions of the National League: 0.403 0.378 0.320 0.341 0.362 0.334 0.379 0.424 0.326 0.330 0.345 0.354 0.350 0.330 0.376 0.363 0.353 0.351 0.335 0.371 1. Construct a relative frequency histogram for the data. 2. What can you say about the shape of the histogram (modes, symmetry, outliers)?
1.Why there is a need to conduct research? 2. What practical benefits can you get from...
1.Why there is a need to conduct research? 2. What practical benefits can you get from research? 3. If you are an athlete or an artist, do you still need to conduct research? Why or why not? 4. What are the research process? 5. What are the importance of research?
I need the code in SAS and R and outputs please 2. The data below come...
I need the code in SAS and R and outputs please 2. The data below come from a study investigating a method of measuring body composition, and give the body fat percentage (% fat), age and sex for 18 adults aged between 23 and 61 years. Source: Mazess, R.B., Peppler, W.W., and Gibbons, M. (1984) Total body composition by dual-photon (153GD) absorptiometry. American Journal of Clinical Nutrition, 40, 834-839. age % fat sex 23 9.5 male 23 27.9 female 27...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT