Daniël v.

9 years experience -- Friendly and patient tutor with Ph.D in Statistics

Tutor Satisfaction Guarantee

R Programming

TutorMe

Question:

Let's say we want to fill a matrix structure with numbers. The matrix has 100 rows and 10 columns. We put in the numbers 1, 2, 3, ... 1000. So the matrix will look like this: [ 1][101][201][301][401][501][601][701][801][901] [ 2][102][202][302][402][502][602][702][802][902] [ 3][103][203][303][403][503][603][703][803][903] [ 4][104][204][304][404][504][604][704][804][904] ... ... ... ... ... ... ... ... ... ... Now, suppose you want to substract the row average from every number and store the result in a new variable. One way to do that is as follows: myData <- matrix(1:1000, ncol = 10) myDataModified <- myData for(i in 1:nrow(myData)) { myDataModified[i,] <- myData[i,] - mean(myData[i,]) } How can we achieve the same result using the apply function instead of a loop?

Daniël v.

Answer:

When we use the apply function, we must specify 3 arguments apply( [1}, [2], [3] ) [1] The object we are targeting [2] Whether we want to operate on the rows (1) or columns (2) [3] Which function we want to apply Now, if we simply want the row means, the specification is simpler: apply(myDataModified, 1, mean) However, we can also write a custom function which gives us much more flexibility: t(apply(myDataModified, 1, function(x) { x - mean(x) })) Note that 't()' is the transpose function. Without it, we would get a matrix back with 100 columns and 10 rows. The matrix would be on its side, so to say. So we fix that by transposing the matrix.

Basic Math

TutorMe

Question:

If y = x^2 + 4, express x in terms of y. Hence: x = ?

Daniël v.

Answer:

1) Substract 4 from both sides: y - 4 = x^2 + 4 - 4 --> y - 4 = x^2 2) Take the square-root from both sides: sqrt(y-4) = sqrt(x^2) = x --> x = sqrt(y-4)

Statistics

TutorMe

Question:

Typically, in hypothesis testing, researchers formulate a hypothesis and a sample is drawn from the population to either reject or maintain their nul hypothesis. An example of a nul hypothesis is: Male students and female students are equally old on average. An example of a alternative hypothesis is: Male students are older on average than female students. To test this nul hypothesis, a random sample is drawn with N = 102 students, 51 males and 51 females. The researchers find a mean difference of 0.4 years and a p-value of 0.12 What is the interpretation of a p-value?

Daniël v.

Answer:

1) If the nul hypothesis were true (Male students are on average as old as female students) and 2) this experiment of taking a sample of N = 102 students were to be repeated an infinite number of times 3) under exactly the same circumstances Then the probability of finding this exact result (mean difference of 0.4 years) OR more extreme (>.4 years), equals 0.12 The reasoning behind the p-value is that we reject a nul hypothesis if we draw a sample that is very unlikely given that the nul hypothesis is true. Typically, if the probability of a sample result is less than 5% (p < 0.05), then researchers reject the nul hypothesis and the alternative hypothesis is assumed to be true.

Send a message explaining your

needs and Daniël will reply soon.

needs and Daniël will reply soon.

Contact Daniël

Ready now? Request a lesson.

Start Session

FAQs

What is a lesson?

A lesson is virtual lesson space on our platform where you and a tutor can communicate.
You'll have the option to communicate using video/audio as well as text chat.
You can also upload documents, edit papers in real time and use our cutting-edge virtual whiteboard.

How do I begin a lesson?

If the tutor is currently online, you can click the "Start Session" button above.
If they are offline, you can always send them a message to schedule a lesson.

Who are TutorMe tutors?

Many of our tutors are current college students or recent graduates of top-tier universities
like MIT, Harvard and USC.
TutorMe has thousands of top-quality tutors available to work with you.