Presentation on demonstrating "New Treatments as Fixed Effect" in R
Ashu Guru
Author
03/07/2019
Added
761
Plays
Description
Presentation on demonstrating "New Treatments as Fixed Effect" in R
Searchable Transcript
Toggle between list and paragraph view.
- [00:00:00.160]So we are ready for the first model.
- [00:00:02.960]We are going to treat the entries as fixed and only blocks will be the random
- [00:00:08.583]effects.
- [00:00:09.680]So let's walk through the code that will help us fit this model to the data.
- [00:00:14.200]The first statement that I would like you to look at is the library call and this
- [00:00:21.064]is where we are telling are that we will be using lmer test package.
- [00:00:26.840]So include all the functions that are defined in this library or this package
- [00:00:32.788]and make it available so when I run them I can use them with this data.
- [00:00:38.920]If I had not called this statement and I had tried to use some function calls
- [00:00:45.660]which are included in lmer test, they will not work.
- [00:00:50.240]Take a look at step function which I'll talk about it later.
- [00:00:54.720]So here is the step function.
- [00:00:59.240]If I do not make the call to the library lmer test, I cannot use step function.
- [00:01:05.720]In addition to the providing us the step function,
- [00:01:09.865]lmer test wraps around and enhances the LME 4 package that we installed.
- [00:01:16.160]So what I would like you to take from here is that anytime you have a
- [00:01:20.671]functionality that is defined in a new package,
- [00:01:23.764]once you have installed it you want to use it in your script.
- [00:01:27.760]You will have to call it with a library call.
- [00:01:31.680]Next is a similar routine, which I always do.
- [00:01:34.960]I define a working directory as a variable and then I set my working
- [00:01:40.639]directory using the set WD command.
- [00:01:43.680]My data is located in an input file called solvedExampleMetaForm.CSV.
- [00:01:49.960]So I define that variable.
- [00:01:51.440]Then I read it into a variable or an R object called input data and I do that
- [00:01:56.907]with the read .CSV command.
- [00:01:58.800]Let's take a quick look at the input data that we read the data file.
- [00:02:02.520]We realized that R considered plot and entry both as integer variables.
- [00:02:08.480]But we know that based on the experiment that these should be factors.
- [00:02:13.880]So what I am doing in statement here is that I'm going to force R to consider
- [00:02:19.688]block and entry as factor variables as well.
- [00:02:23.040]So now if I print the STR command it tells me that both entry and block are
- [00:02:30.133]now treated as factors.
- [00:02:32.320]The plot variable is not in our model so I am leaving it as integer for now.
- [00:02:37.960]What I'm going to do is I'm going to print out entries per block and that can
- [00:02:42.456]be done with the X tabs.
- [00:02:43.840]So if I run this function I am able to see that for each block which entry is
- [00:02:50.672]present in that block.
- [00:02:52.600]So if I look at block number one, the entries that are there are entry
- [00:02:58.239]number 89 and I can see the list of all and what I see in addition is that entry
- [00:03:04.673]number 89, 90 and 91 are present in each of the six
- [00:03:08.803]blocks.
- [00:03:09.880]In the previous topics, we saw that the fixed model will be
- [00:03:14.809]represented in terms of R as TSW dependent on entry as fixed and block as
- [00:03:20.889]random effect.
- [00:03:22.120]The reason R will consider this as random effect is because it is preceded by a
- [00:03:27.832]parenthesis and a one and a vertical bar.
- [00:03:30.920]And then we tell R that the data comes from the variable input data.
- [00:03:37.320]So I'll run that command and now R has actually fit the model which is defined
- [00:03:44.430]here to the data.
- [00:03:46.400]Now let's take an output of the ANOVA output of the model that we fit.
- [00:03:51.520]And the function that we are going to use is ANOVA for the model output.
- [00:03:58.200]Once it is run we can print the ANOVA output.
- [00:04:01.680]In this case it is significant which is represented by three stars and the legend
- [00:04:07.306]for significance code is also given here.
- [00:04:11.960]The next step is we would like to see the summary of the linear model that was fit.
- [00:04:16.800]So I have the statement which is called summarize the input data dot entry where
- [00:04:23.389]the model was fit and I'm saying I would like the correlation to be true and once
- [00:04:30.059]done I can actually print the model summary.
- [00:04:34.680]So the model summary shows us the formula that was used to fit the model,
- [00:04:39.908]the data that was used as input, and the residuals,
- [00:04:43.582]the random effects and the fixed effects.
- [00:04:47.200]And in this case, the first intercept is entry one.
- [00:04:52.840]And the reason R picks entry one as the intercept is because entry one is the
- [00:04:58.370]first one.
- [00:04:59.080]In lexographical treatment.
- [00:05:00.840]If you take all the fixed variables and you arrange them in order of alphabet or
- [00:05:06.686]a dictionary order, entry one will be the first one and
- [00:05:10.728]that's why it is treated as the intercept.
- [00:05:14.040]In R there is a function called step provided by the package lmer test and we
- [00:05:20.417]will use this to see the least square means difference between the fixed effect.
- [00:05:27.040]So in order to do that I first wanted to share with you how do you find out or
- [00:05:32.925]what are the details of this function called steps.
- [00:05:36.800]So I'm using an R function is help dot search.
- [00:05:40.520]I'm searching for the function call step and it is in package LMER test.
- [00:05:45.280]So when I run this command the search results show me the LMER test step
- [00:05:50.016]function.
- [00:05:50.720]This function allows us to perform backward elimination of non significant
- [00:05:55.093]effects.
- [00:05:55.880]But in this case I'm telling it do not reduce the fixed effects or keep it false.
- [00:06:01.040]And once I do that, it will be about a minute or a minute and
- [00:06:06.068]a half, depending on the machine speed that it
- [00:06:09.880]will take before this function call comes back with the result for you.
- [00:06:16.240]So if I now print this output, it is going to run through the console
- [00:06:21.735]very fast.
- [00:06:22.520]Let me just show it to you.
- [00:06:24.200]And I do see the results, but they are beyond the display ability
- [00:06:29.513]of my console.
- [00:06:30.640]So I'm going to print the output of this instead into a file.
- [00:06:34.440]And we'll use a function called sync.
- [00:06:36.560]So now I am directing R that whatever the output is requested to be printed on the
- [00:06:41.516]screen diverted to this file in the folder that I'm working.
- [00:06:45.160]So I'm going to call the sync call and then I'm going to print the output and
- [00:06:51.613]I'm going to revert back with the sync.
- [00:06:54.840]So closing the sync calls all the output comes back to the main console and let us
- [00:07:01.080]open the file.
- [00:07:02.760]Here is the output and you can see details of the step function call and
- [00:07:09.651]what is interesting for you most likely is the differences of LS means and you
- [00:07:17.108]can see differences between individual entries.
The screen size you are trying to search captions on is too small!
You can always jump over to MediaHub and check it out there.
Log in to post comments
Embed
Copy the following code into your page
HTML
<div style="padding-top: 56.25%; overflow: hidden; position:relative; -webkit-box-flex: 1; flex-grow: 1;"> <iframe style="bottom: 0; left: 0; position: absolute; right: 0; top: 0; border: 0; height: 100%; width: 100%;" src="https://mediahub.unl.edu/media/10753?format=iframe&autoplay=0" title="Video Player: Presentation on demonstrating "New Treatments as Fixed Effect" in R" allowfullscreen ></iframe> </div>
Comments
0 Comments