Kernel or Bezier curve smoothing for Kaplan-Meier Survival Estimate - bezier

I am a civil engineering grad student working on survival modeling of bridges. I am using SAS with Kaplan-Meier method to analyze the data. I would like to overlay the survival probability plot with a smooth curve using either Kernel smoothing or Bezier smoothing. But since these methods are not available in statistic packages, I exported the survival probability to an excel in order to produce it manually (I may be wrong on doing this). After several attempt I could not figure out on how to do it in Excel.
I am attaching an excel file image with data and the Kaplan Meier curve I am working and would be grateful if someone could help me by coding either the kernel smoothing or Bezier smoothing steps and overlay the curve and repost the file here to me. Or, more effeciently provide me with an excel add in to do this or a SAS code to do this.

If a parametric model providing a smoothed description of the survival data isn't appropriate, you could use smoothing splines or loess curves, compared on this page for example. For smoothing, multiple Bézier curves are combined to form one type of spline, and loess is one form of a kernel smoother. These are easily implemented in standard statistical software packages; for example, in SAS TRANSREG provides splines and LOESS implements that locally-weighted regression.*
That said, baseline survival curves in clinical studies are typically presented as the type of step function that you display, without smoothing. Also, it seems that your underlying data might only provide information at 1-year intervals. If so, then presenting a smooth curve might be somewhat misrepresenting the smoothness of your data. If you do have individual event and censoring times for each bridge, then your smoothed curve should be based on the survival probabilities at each event time to provide the closest representation of your data.
*I would be wary of using Excel for any serious statistical work. I have found it too easy to make unforced errors that avoid detection in Excel.

Related

A better way of visualizing extreme oscillation curve in matlibplot?

Here are three curve
All the curve contains so many spikes and noises. I'm interesting to see which curve has less chaos
One way is to use np.convolve to smooth the curve. Unfortunately, it lost so much information and defeat my original purposes.
I'm wondering if there different way of visualization ? (Not necessarily plotting the curve but use some math theorem to visualize the chaos in a different way)
Maybe Flatten out your plot by specifying the width, height for you plot.

Parameterization of Triangulated Surface Meshes

I’d like to perform a surface parametrization of a triangle mesh (for the purpose of texture mapping).
I tried using some of CGAL’s algorithms, e.g. ARAP, Discrete Conformal Map etc.
The problem is that the surface parameterization methods proposed by CGAL only deal with meshes which are homeomorphic (topologically equivalent) to discs.
Meshes with arbitrary topology can be parameterized, provided that the user specifies a cut graph (a set of edges), which defines the border of a topological disc.
So the problem now becomes – how to cut the graph properly (using CGAL’s interface).
I found a similar question from 3 years ago that went unanswered.
P.S.
If someone can point me to a different library that can do the job, that’ll be just as great.
Thanks.

Conversion of fine organic surface mesh to a few patches of NURBS

I have a very fine mesh (STL) of some organic shapes (e.g., a bone) and would like to convert it to a few patches of NURBS, which will be much smoother with reasonable simplification.
I can do this manually with Solidworks ScanTo3D function, but it is not scriptable. It's a pain when I need to do hundreds of them.
Would there be a way to automate it, e.g., with some open source libraries available? I am perfectly fine with quite some loss in accuracy. I use mainly Python, but I don't mind if it is in other languages and I can work my way around it.
Note that one thing I'd like to avoid is to convert an STL of 10,000 triangles to a NURBS with 10,000 patches. I'd like to automatically (programmatically, could be with some parameter tunings) divide the mesh into a few patches and then fit it. Again, I'm perfect fine with quite some loss in accuracy.
Converting an arbitrary mesh to nurbs is not easy in general. What is a good nurbs surface for a given mesh depends on the use case. Do you want to manually edit the nurbs surface afterwards? Should symmetric structures or other features be recognized and represented correctly in the nurbs body? Is it important to keep the volume of the body? Are there boundary lines that should not be simplified as they change the appearance or angles that must be kept?
If you just want to smooth the mesh or reduce the amount of vertices there are easier ways like mesh reduction and mesh smoothing.
If you require your output to be nurbs there are different methods leading to different topologies and approximations like indicated above. A commonly used method for object simplification is to register the mesh to some handmade prototype and then perform some smaller changes to shape the specific instance. If there are for example several classes of shapes like bones, hearts, livers etc. it might be possible to model a prototype nurbs body for each class once which defines the average appearance and topology of that organ. Each instance of a class can then be converted to a nurbs by fitting the prototype to that instance. As the topology is fixed the optimization problem is reduced to the problem where we need to find the control points that approximate the mesh with the smallest error.Disadvantage of this method is that you have to create a prototype for each class. The advantage is that the topology will be nice and easily editable.
Another approach would be to first smooth the mesh and reduce the polygon count (there are libraries available for mesh reduction) and then simply converting each triangle/ quad to a nurbs patch (like the Rhino MeshToNurb Command). This method should be easier to implement but the resulting nurbs body could have an ugly topology.
If one of this methods is applicable really depends on what you want to do with your transformed data.

Library for fitting parametric curves

Does anyone know of a library (any language, though preferably python/R/matlab) for parametric curve fitting, i.e. if you have a set of points in the plane {(x_i,y_i)} you can find parameter estimates for two (polynomial) functions y=f_y(t) and x=f_x(t) for some (arc-length?) parametrization t? This is especially useful if you have some multi-valued function (e.g. a circle) for which regression wouldn't work.
There are a number of papers detailing algorithms (e.g. 'Parametric Curve Fitting', Grossman 1971) but I can't find any corresponding software that would save a lot of time coding up.
For future reference, I ended up using the princurve library in R based on principal curves by Trevor Hastie.

Tweaking Heightmap Generation For Hexagon Grids

Currently I'm working on a little project just for a bit of fun. It is a C++, WinAPI application using OpenGL.
I hope it will turn into a RTS Game played on a hexagon grid and when I get the basic game engine done, I have plans to expand it further.
At the moment my application consists of a VBO that holds vertex and heightmap information. The heightmap is generated using a midpoint displacement algorithm (diamond-square).
In order to implement a hexagon grid I went with the idea explained here. It shifts down odd rows of a normal grid to allow relatively easy rendering of hexagons without too many further complications (I hope).
After a few days it is beginning to come together and I've added mouse picking, which is implemented by rendering each hex in the grid in a unique colour, and then sampling a given mouse position within this FBO to identify the ID of the selected cell (visible in the top right of the screenshot below).
In the next stage of my project I would like to look at generating more 'playable' terrains. To me this means that the shape of each hexagon should be more regular than those seen in the image above.
So finally coming to my point, is there:
A way of smoothing or adjusting the vertices in my current method
that would bring all point of a hexagon onto one plane (coplanar).
EDIT:
For anyone looking for information on how to make points coplanar here is a great explination.
A better approach to procedural terrain generation that would allow
for better control of this sort of thing.
A way to represent my vertex information in a different way that allows for this.
To be clear, I am not trying to achieve a flat hex grid with raised edges or platforms (as seen below).
)
I would like all the geometry to join and lead into the next bit.
I'm hope to achieve something similar to what I have now (relatively nice undulating hills & terrain) but with more controllable plateaus. This gives me the flexibility of cording off areas (unplayable tiles) later on, where I can add higher detail meshes if needed.
Any feedback is welcome, I'm using this as a learning exercise so please - all comments welcome!
It depends on what you actually want and what you mean by "more controlled".
Do you want to be able to say "there will be a mountain on coordinates [11, -127] with radius 20"? Complexity of this this depends on how far you want to go. If you want just mountains, then radial gradients are enough (just add the gradient values to the noise values). But if you want some more complex shapes, you are in for a treat.
I explore this idea to great depth in my project (please consider that the published version is just a prototype, which is currently undergoing major redesign, it is completely usable a map generator though).
Another way is to make the generation much more procedural - you just specify a sequence of mathematical functions, which you apply on the terrain. Even a simple value transformation can get you very far.
All of these methods should work just fine for hex grid. If artefacts occur because of the odd-row shift, then you could interpolate the odd rows instead (just calculate the height value for the vertex from the two vertices between which it is located with simple linear interpolation formula).
Consider a function, which maps the purple line into the blue curve - it emphasizes lower located heights as well as very high located heights, but makes the transition between them steeper (this example is just a cosine function, making the curve less smooth would make the transformation more prominent).
You could also only use bottom half of the curve, making peaks sharper and lower located areas flatter (thus more playable).
"sharpness" of the curve can be easily modulated with power (making the effect much more dramatic) or square root (decreasing the effect).
Implementation of this is actually extremely simple (especially if you use the cosine function) - just apply the function on each pixel in the map. If the function isn't so mathematically trivial, lookup tables work just fine (with cubic interpolation between the table values, linear interpolation creates artefacts).
Several more simple methods of "gamification" of random noise terrain can be found in this paper: "Realtime Synthesis of Eroded Fractal Terrain for Use in Computer Games".
Good luck with your project