I am working on an assignment for a course. The code creates variables for use in a data.dist function from rms. We then create a simple linear regression model using ols(). Printing/creating the first plot before the data.dist() and ols() functions is simple. We use:
plot(x,y,pch='o')
lines(x,yTrue,lty=2,lwd=.5,col='red')
Then we create the data.dist() and the ols(), here named fit0.
mydat=data.frame(x=x,y=y)
dd=datadist(mydat)
options(datadist='dd')
fit0=ols(y~x,data=mydat)
fit0
anova(fit0)
This all works smoothly, printing out the results of the linear regression and the anova table. Then, we want to predict based on the model, and plot these predictions. The plot prints out nicely, however the lines and points won't show up here. The code:
ff=Predict(fit0)
plot(ff)
lines(x,yTrue,lwd=2,lty=1,col='red')
points(x,y,pch='.')
Note - this works fine in R. I much prefer to use RStudio, though can switch to R if there's no clear solution this issue. I've tried dev.off() several times (i.e. repeat until get, I've tried closing RStudio and re-opening, I've uninstalled and reinstalled R and RStudio, rms package (which includes ggplot2), updated the packages, made my RStudio graphics window larger. Any solution I've seen, doesn't work. Help!
Related
In my OpenModelica model (OpenModelica 1.19.2 on Ubuntu 20.04) I'm using Modelica.Blocks.Math.Mean to compute the mean of the final period of some of my results, like:
when terminal() then
result = blockMean.y;
end when;
where result is a Real and blockMean is an instance of Modelica.Blocks.Math.Mean (with the variable of interest as input).
When I run this model in OpenModelica, this works fine, and result shows up in the resulting list of variables in the Plotting tab, with the correct value.
However, after exporting an fmu of this model and running it in Python using pyFMI, result is an array of zeros, of the same length as all resulting time-varying signals.
I'm fairly new to Modelica and pyFMI, so I'm not awfully familiar with all options and details. As a first attempt at solving this I tried playing with opts["CVode_options"]["store_event_points"], but that didn't make any difference.
Is there some option that I should set? Or is this a bug that I just should live with?
So my problem lies within Rstudio. I have a data set with three columns (study name, effect size (derived from odds ratios) and sample size). Once I have run my meta-regression model I cannot find a code that allows me to generate a forest plot similar to the one included in the link. I am quite new to R and would consider myself a beginner so apologies for a potentially silly question.
I am using a MacBook pro and Rstudio version 2022.02.0+443
I'm working on some code to select and export geodata based on a bounding box. The data I want to select comes from 2 seperate layers in a huge File GDB (16GB) covering the entire Netherlands. I use a bounding box as to avoid reading the entire dataset before making a selection.
This method works great when applied on a gpkg database, but with a file geodatabase the time to process is way longer (0,2s vs 300s for a 200x200 meter selection). The File GDB I'm using has a spatial index set for the layers I'm reading. I'm using geopandas to read and select. Below you'll find an example for the layer 'Adres':
import geopandas as gpd
def ImportGeodata(FilePath, BoundingBox):
importBag=gpd.read_file(FilePath, layer='Adres', bbox=BoundingBox)
importBag['mergeid']=importBag['identificatie']
return importBag
Am I overseeing something? Or is this a limitation when importing from a huge File GDB? I can't find an obvious mistake here. For now the workaround is another script that imports and dumps the layers I need in a gpkg. Problem is this runs for 3 to 4 hours (gpkg result is almost 6 GB). I don't want to keep doing that, it would be necessary to do once every month or so in order to process a new version of this dataset.
Curious what you guys come up with.
We see pretty pictures of error surface with a global minima and convergence of a neural network in many books. How can I visualize something similar in keras i.e containing error surface and how my model is converging to achieve global minimal error? Below is an example image of such illustrations. And this link has animated illustration of different optimizers. I explored tensorboard log callback for this purpose but could not find any such thing. A little guidance will be appreciated.
The pictures and animations are made for didatic purposes, but the error surface is completely unknown (or incredibly complex to be understood or visualized). That's the whole idea behind using gradient descent.
We only know, at a single point, the direction towards which the funcion increases, through getting the current gradient.
You could try to plot the way (line) you're following by getting the weights values at each iteration and the error, but then you'd face another problem: it's a massively multidimensional function. It's not actually a surface. The number of variables is the number of weights you have in the model (often thousands or even millions). This is absolutely impossible to visualize or even conceive as a visual thing.
To plot such a surface, you'd have to manually change all thousands of weights to get the error for each arrangement. Besides the "impossible to visualize" problem, this would be excessively time consuming.
I wrote this following (written at the end of my question) piece of code which is error-free, but I think, while running it, it has an overwriting problem. During the program, there are two cases where I wanted to draw graphs; first, the graphs of the curves written with ezplot, and second, the plot regression where I wanted to draw regression lines.
When I skip the code plotregression(C_i, D_i), it has no problem displaying the graphs of all five logistic functions (actually one users here showed me the hold on-hold off codes to help doing that), but then, when I incorporate plotregression(C_i, D_i), two things happen:
it shows me all the regression lines, but contrary to having all
the regression lines all in the same figure, it keeps changing the
regression lines with varying regression coefficients. You can
actually see this happening if you run the code.
The effect of plotregression(C_i, D_i) is gone; it no more
plots the graphs of the five logistic functions.
I've two questions:
If I want to get two figures, one showing all the five logistic
curves, and the other showing all the five regression curves, how
can I modify the program minimally so as to get the job done?
How can I stop over writing the regression curves? I used the 'hold on-hold off' in order to avoid the same for the logistic curves, but is it not working on the regression curves?
Here's the code:
syms t;
hold on;
for i=1:5;
P_i=0.009;
r_i=abs(sin(i.^-1));
y_i(t)= P_i*exp(r_i*t)/(1+P_i*(exp(r_i*t)-1));
t_1= 1+rand; t_2= 16+rand; t_3=31+rand;
time_points=[1, t_1; 1, t_2; 1, t_3];
biomarker_values= double([y_i(t_1);y_i(t_2);y_i(t_3)]);
X=vertcat(X,time_points);
Z=blkdiag(Z,time_points);
Y=vertcat(Y,biomarker_values);
G=vertcat(G,[i,i,i]');
ezplot(y_i,[-50,100]);
C_i=time_points(:,2)
D_i=biomarker_values
plotregression(C_i, D_i)
end;
hold off;